libkeg

package module
v0.0.0-...-7f8a71a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

libkeg

Test library

A Go library for interacting with Knowledge Exchange Graphs, as defined by the KEG 2023-01 Specification.

Documentation

Index

Constants

View Source
const (
	KegTimestampLayout = "2006-01-02 15:04:05Z"
)

Variables

View Source
var (
	ErrNodeNotEnoughFields = errors.New("dex tsv entry does not have 3 parts")
	ErrNodeIdNotInt        = errors.New("dex node id is not an int")
	ErrInvalidTimestamp    = errors.New("timestamp must be formatted as 2006-01-02 15:04:05Z")
)

Functions

This section is empty.

Types

type Dex

type Dex struct {
	// Nodes is a slice containing all of the [Node] entries in the KEG.
	Nodes []Node
}

Dex is an index of nodes

func DexFromNodesTsv

func DexFromNodesTsv(tsv string) (Dex, error)

DexFromNodesTsv converts a TSV represented in a string into a Dex struct, using the format "(id)\t(created)\t(title)".

dex, err := libkeg.DexFromNodesTsv("1\t2022-12-11 22:32:00Z\tHello, world!")

type KegIndex

type KegIndex struct {
	File    string  `yaml:"file" json:"file"`
	Summary *string `yaml:"summary" json:"summary"`
}

type KegInfo

type KegInfo struct {
	Title   string       `yaml:"title" json:"title"`
	Kegv    *string      `yaml:"kegv" json:"kegv"`
	Creator *string      `yaml:"creator" json:"creator"`
	State   *string      `yaml:"state" json:"state"`
	Updated KegTimestamp `yaml:"updated" json:"updated"`

	Summary *string    `yaml:"summary" json:"summary"`
	Urls    []string   `yaml:"urls" json:"urls"`
	Indexes []KegIndex `yaml:"indexes" json:"indexes"`
}

func KegInfoFromYaml

func KegInfoFromYaml(in string) (KegInfo, error)

type KegTimestamp

type KegTimestamp struct {
	Time time.Time
}

func (*KegTimestamp) MarshalYAML

func (kt *KegTimestamp) MarshalYAML() (interface{}, error)

func (*KegTimestamp) UnmarshalYAML

func (kt *KegTimestamp) UnmarshalYAML(value *yaml.Node) error

type Node

type Node struct {
	// Id is the incrementing ID of the KEG node.
	Id int `yaml:"id" json:"id"`

	// Created is the time the KEG node was created.
	Created KegTimestamp `yaml:"created" json:"created"`

	// Title is the string title of the KEG node.
	Title string `yaml:"title" json:"title"`
}

Node represents a KEG node of any type.

func NodeFromTsvSlice

func NodeFromTsvSlice(data []string) (Node, error)

NodeFromTsvSlice converts a slice formatted as [id, created, title] info a Node, returning an error if the record is invalid.

node, err := libkeg.NodeFromTsvSlice([]string{"1", "2022-12-11 22:33:00Z", "Hello, world!"})

type NodeMap

type NodeMap map[int]Node

NodeMap is a map of nodes, keyed by the ID of the node in the KEG.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL