ls

package
v1.0.0-beta5 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: Apache-2.0 Imports: 13 Imported by: 3

Documentation

Index

Constants

View Source
const LS = "https://lschema.org/"

Variables

View Source
var (
	// SchemaTerm is the layer type for schemas
	SchemaTerm = NewTerm(LS+"Schema", false, false, NoComposition, nil)

	// OverlayTerm is the layer type for overlays
	OverlayTerm = NewTerm(LS+"Overlay", false, false, NoComposition, nil)

	// SchemaManifestTerm is the schema manifest type
	SchemaManifestTerm = NewTerm(LS+"SchemaManifest", false, false, NoComposition, nil)

	// TargetType is the term specifying the data type for the attribute defined
	TargetType = NewTerm(LS+"targetType", true, false, SetComposition, nil)

	// DescriptionTerm is used for comments/descriptions
	DescriptionTerm = NewTerm(LS+"description", false, false, SetComposition, nil)

	// AttributeNameTerm represents the name of an attribute
	AttributeNameTerm = NewTerm(LS+"attributeName", false, false, ErrorComposition, nil)

	// AttributeIndexTerm represents the index of an array element
	AttributeIndexTerm = NewTerm(LS+"attributeIndex", false, false, NoComposition, nil)

	// AttributeValueTerm represents the value of an attribute
	AttributeValueTerm = NewTerm(LS+"attributeValue", false, false, ErrorComposition, nil)

	// LayerRootTerm is an edge term that connects layer node to the root node of the schema
	LayerRootTerm = NewTerm(LS+"layer", false, false, ErrorComposition, nil)

	// DefaultValueTerm is the default value for an attribute if attribute is not present
	DefaultValueTerm = NewTerm(LS+"defaultValue", false, false, OverrideComposition, nil)

	// LabelTerm defines one or more presentation layer labels for the attribute
	LabelTerm = NewTerm(LS+"label", false, false, OverrideComposition, nil)
)
View Source
var (
	// CharacterEncodingTerm is used to specify a character encoding for
	// the data processed with the layer
	CharacterEncodingTerm = NewTerm(LS+"characterEncoding", false, false, OverrideComposition, nil)

	// InstanceOfTerm is an edge term that is used to connect values with
	// their schema specifications
	InstanceOfTerm = NewTerm(LS+"data#instanceOf", false, false, ErrorComposition, nil)

	BundleTerm     = NewTerm(LS+"SchemaManifest#bundle", false, false, ErrorComposition, nil)
	SchemaBaseTerm = NewTerm(LS+"SchemaManifest#schema", true, false, ErrorComposition, nil)
	OverlaysTerm   = NewTerm(LS+"SchemaManifest#overlays", true, true, ErrorComposition, nil)
)
View Source
var AnyEdgePredicate = func(Edge) bool { return true }

AnyEdgePredicate accepts all edges

View Source
var AnyNodePredicate = func(Node) bool { return true }

AnyNodePredicate accepts all nodes

View Source
var AttributeTypes = struct {
	Value       string
	Object      string
	Array       string
	Reference   string
	Composite   string
	Polymorphic string
	Attribute   string
}{
	Value:       NewTerm(LS+"Value", false, false, OverrideComposition, nil),
	Object:      NewTerm(LS+"Object", false, false, OverrideComposition, nil),
	Array:       NewTerm(LS+"Array", false, false, OverrideComposition, nil),
	Reference:   NewTerm(LS+"Reference", false, false, OverrideComposition, nil),
	Composite:   NewTerm(LS+"Composite", false, false, OverrideComposition, nil),
	Polymorphic: NewTerm(LS+"Polymorphic", false, false, OverrideComposition, nil),
	Attribute:   NewTerm(LS+"Attribute", false, false, OverrideComposition, nil),
}

AttributeTypes defines the terms describing attribute types. Each attribute must have one of the attribute types plus the Attribute type, marking the object as an attribute.

View Source
var DataEdgeTerms = struct {
	// Type of a document node
	// Edge label linking attribute nodes to an object node
	ObjectAttributes string
	// Edge label linking array element nodes to an array node
	ArrayElements string
}{
	ObjectAttributes: NewTerm(LS+"data/object#attributes", false, false, ErrorComposition, nil),
	ArrayElements:    NewTerm(LS+"data/array#elements", false, false, ErrorComposition, nil),
}
View Source
var DocumentNodeTerm = NewTerm(LS+"DocumentNode", false, false, ErrorComposition, nil)

DocumentNodeTerm is ithe type of document nodes

View Source
var ErrAttributeWithoutID = errors.New("Attribute without id")
View Source
var ErrCompositionSourceNotOverlay = errors.New("Composition source is not an overlay")
View Source
var ErrIncompatibleComposition = errors.New("Incompatible composition of layers")
View Source
var ErrInvalidComposition = errors.New("Invalid composition")
View Source
var ErrInvalidEncodingIndex = errors.New("Invalid encoding index")

ErrInvalidEncodingIndex is used to return error about an invalid or unrecognized character encoding

View Source
var ErrInvalidExpression = errors.New("Invalid expression")
View Source
var ErrInvalidJsonLdGraph = errors.New("Invalid JsonLd graph")
View Source
var ErrInvalidPredicate = errors.New("Invalid predicate")
View Source
var ErrNotALayer = errors.New("Not a layer")
View Source
var ErrNotASchemaManifest = errors.New("Not a schema manifest")
View Source
var IncludeAllNodesInSliceFunc = func(layer *Layer, nd Node) Node {
	return nd.Clone().(*node)
}

IncludeAllNodesInSliceFunc includes all the nodes in the slice

View Source
var LayerTerms = struct {
	// Unordered named attributes (json object)
	Attributes string
	// Ordered named attributes (json object, xml elements)
	AttributeList string
	// Reference to another schema. This will be resolved to another
	// schema during compilation
	Reference string
	// ArrayItems contains the definition for the items of the array
	ArrayItems string
	// All components of a composite attribute
	AllOf string
	// All options of a polymorphic attribute
	OneOf string
}{
	Attributes:    NewTerm(LS+"Object#attributes", false, false, ErrorComposition, nil),
	AttributeList: NewTerm(LS+"Object#attributeList", false, true, ErrorComposition, nil),
	Reference:     NewTerm(LS+"Reference#reference", true, false, ErrorComposition, nil),
	ArrayItems:    NewTerm(LS+"Array#items", false, false, ErrorComposition, nil),
	AllOf:         NewTerm(LS+"Composite#allOf", false, true, ErrorComposition, nil),
	OneOf:         NewTerm(LS+"Polymorphic#oneOf", false, true, ErrorComposition, nil),
}

LayerTerms includes type specific terms recognized by the schema compiler. These are terms used to define elements of an attribute.

Functions

func ComposeProperties

func ComposeProperties(target, source map[string]*PropertyValue) error

ComposeProperties will combine the properties in source to target. The target properties will be modified directly

func Copy

func Copy(in, target *digraph.Graph, nodeSelector func(Node) bool, edgeSelector func(Edge) bool) map[Node]Node

Copy in to target using the node selectors. Return a node map from the in to target nodes

func CopyPropertyMap

func CopyPropertyMap(m map[string]*PropertyValue) map[string]*PropertyValue

CopyPropertyMap returns a copy of the property map

func DeepEqual

func DeepEqual(i1, i2 interface{}) error

DeepEqual test equivalence between two JSON trees

func DescendToListElements

func DescendToListElements(in []interface{}) []interface{}

If in is a @list, returns its elements

func FilterAttributeTypes

func FilterAttributeTypes(types []string) []string

FilterAttributeTypes returns all recognized attribute types from the given types array. This is mainly used for validation, to ensure there is only one attribute type

func FilterNonLayerTypes

func FilterNonLayerTypes(types []string) []string

FilterNonLayerTypes returns the types that are not attribute or layer related

func FilterValue

func FilterValue(value interface{}, docnode Node, properties map[string]*PropertyValue) interface{}

FilterValue computes the processed node value

func FirstReachable

func FirstReachable(from Node, nodePredicate func(Node, []Node) bool, edgePredicate func(Edge, []Node) bool) (Node, []Node)

FirstReachable returns the first reachable node for which nodePrdicate returns true, using only the edges for which edgePredicate returns true.

func ForEachAttributeNode

func ForEachAttributeNode(root Node, f func(node Node, path []Node) bool) bool

ForEachAttributeNode calls f with each attribute node, depth first. Path contains all the nodes from root to the current node. If f returns false, iteration stops. This function visits each node only once

func ForEachAttributeNodeOrdered

func ForEachAttributeNodeOrdered(root Node, f func(node Node, path []Node) bool) bool

ForEachAttributeNodeOrdered calls f with each attribute node, depth first, preserving order. Path contains all the nodes from root to the current node. If f returns false, iteration stops. This function visits each node only once

func GetFilteredValue

func GetFilteredValue(schemaNode, docNode Node) interface{}

GetFilteredValue filters the value through the schema properties and then through the node properties before returning

func GetKeyValue

func GetKeyValue(key string, node interface{}) (interface{}, bool)

GetKeyValue returns the value of the key in the node. The node must be a map

func GetLDListElements

func GetLDListElements(node interface{}) []interface{}

GetLDListElements returns the elements of a @list node. The input can be a [{"@list":elements}] or {@list:elements}. If the input cannot be interpreted as a list, returns nil

func GetNodeFilteredValue

func GetNodeFilteredValue(node Node) interface{}

GetNodeFilteredValue returns the field value processed by the schema value filters, and then the node value filters

func GetNodeID

func GetNodeID(node interface{}) string

GetNodeID returns the node @id. The argument must be a map

func GetNodeTypes

func GetNodeTypes(node interface{}) []string

GetNodeTypes returns the node @type. The argument must be a map

func GetSliceByTermsFunc

func GetSliceByTermsFunc(includeTerms []string, includeAttributeNodes bool) func(*Layer, Node) Node

GetSliceByTermsFunc is used in the Slice function to select nodes by the properties it contains. If includeAttributeNodes is true, attributes nodes are included unconditionally even though the node does not contain any of the terms.

func GetStringValue

func GetStringValue(key string, node interface{}) string

GetStringValue returns a string value from the node with the key. The node must be a map

func GetTermMetadata

func GetTermMetadata(term string) interface{}

GetTermMetadata returns metadata about a term

func IsAttributeNode

func IsAttributeNode(a Node) bool

IsAttributeNode returns true if the node has Attribute type

func IsAttributeTreeEdge

func IsAttributeTreeEdge(edge Edge) bool

IsAttributeTreeEdge returns true if the edge is an edge between two attribute nodes

func IsDocumentEdge

func IsDocumentEdge(edge digraph.Edge) bool

IsDocumentEdge returns true if the edge is a data edge term

func IsDocumentNode

func IsDocumentNode(a Node) bool

func IterateDescendants

func IterateDescendants(from Node, nodeFunc func(Node, []Node) bool, edgeFunc func(Edge, []Node) EdgeFuncResult, ordered bool) bool

IterateDescendants iterates the descendants of the node based on the results of nodeFunc and edgeFunc.

For each visited node, if nodeFunc is not nil, nodeFunc is called with the node and the path to the node. If nodeFunc returns false, processing stops.

For each outgoing edge, if edgeFunc is not nil, edgeFunc is called with the edge and the path to the source node. If edgeFunc returns FollowEdgeResult, the edge is followed. If edgeFunc returnd DontFollowEdgeResult, edge is skipped. If edgeFunc returns StopEdgeResult, iteration stops.

func MakeErrInvalidInput

func MakeErrInvalidInput(id ...string) error

func MarshalLayer

func MarshalLayer(layer *Layer) interface{}

Marshals the layer into an expanded jsonld document

func MarshalSchemaManifest

func MarshalSchemaManifest(manifest *SchemaManifest) interface{}

MarshalSchemaNanifest returns a compact jsonld document for the manifest

func NewTerm

func NewTerm(term string, isID, isList bool, comp CompositionType, md interface{}) string

NewTerm registers a term with given semantics, and returns the term.

func RegisterTerm

func RegisterTerm(t TermSemantics)

func RunTestsFromFile

func RunTestsFromFile(t *testing.T, file string, unmarshal func(json.RawMessage) (TestCase, error))

func SortEdges

func SortEdges(edges []Edge)

SortEdges sorts edges by their target node index

func SortEdgesItr

func SortEdgesItr(edges digraph.Edges) digraph.Edges

SortEdgesItr sorts the edges by index

func SortNodes

func SortNodes(nodes []Node)

SortNodes sorts nodes by their node index

func StringSetIntersection

func StringSetIntersection(s1, s2 []string) []string

StringSetIntersection returns the common elements of s1 and s2

func StringSetSubtract

func StringSetSubtract(s1, s2 []string) []string

Returns all elements that are in s1 but not in s2

func StringSetToSlice

func StringSetToSlice(str map[string]struct{}) []string

func StringSetUnion

func StringSetUnion(s1, s2 []string) []string

StringSetUnion returns s1 setunion s2

func ToMap

func ToMap(in interface{}) interface{}

ToMap converts the input to a map

func UnmarshalGraph

func UnmarshalGraph(input interface{}) (*digraph.Graph, error)

Unmarshal a graph

func ValidateDocumentNode

func ValidateDocumentNode(node Node) error

ValidateDocumentNode runs the validators for the document node

func ValidateDocumentNodeBySchema

func ValidateDocumentNodeBySchema(node, schemaNode Node) error

ValidateDocumentNodeBySchema runs the validators for the document node

Types

type Compiler

type Compiler struct {
	// Loader loads a layer using a strong reference.
	Loader func(string) (*Layer, error)
}

func (Compiler) Compile

func (compiler Compiler) Compile(ref string) (*Layer, error)

Compile compiles the schema by resolving all references and building all compositions.

func (Compiler) CompileSchema

func (compiler Compiler) CompileSchema(schema *Layer) (*Layer, error)

CompileSchema compiles the loaded schema

type Composer

type Composer interface {
	Compose(v1, v2 *PropertyValue) (*PropertyValue, error)
}

Composer interface represents term composition algorithm. During layer composition, any term metadata that implements Composer interface will be composed using the customized implementation. If the term does not implement the Composer interface, Setcomposition will be used

func GetComposerForTerm

func GetComposerForTerm(term string) Composer

GetComposerForTerm returns a term composer

type CompositionType

type CompositionType string

CompositionType determines the composition semantics for the term

const (
	// SetComposition means when two terms are composed, set-union of the values are taken
	SetComposition CompositionType = "set"
	// ListComposition means when two terms are composed, their values are appended
	ListComposition CompositionType = "list"
	// OverrideComposition means when two terms are composed, the new one replaces the old one
	OverrideComposition CompositionType = "override"
	// NoComposition means when two terms are composed, the original remains
	NoComposition CompositionType = "nocompose"
	// ErrorComposition means if two terms are composed and they are different, composition fails
	ErrorComposition CompositionType = "error"
)

func (CompositionType) Compose

func (c CompositionType) Compose(target, src *PropertyValue) (*PropertyValue, error)

Compose target and src based on the composition type

type Edge

type Edge interface {
	digraph.Edge

	GetLabelStr() string

	// Clone returns a new edge that is a copy of this one but
	// unconnected to any nodes
	Clone() Edge

	GetProperties() map[string]*PropertyValue

	GetCompiledDataMap() map[interface{}]interface{}
}

func CloneWithLabel

func CloneWithLabel(e Edge, label string) Edge

CloneWithLabel returns a copy of the schema edge with a new label

func Connect

func Connect(source, target Node, edgeLabel string) Edge

Connect source node with the target node using an edge with the given label

func GetLayerEdgeBetweenNodes

func GetLayerEdgeBetweenNodes(source, target Node) Edge

GetAttributeEdgeBetweenNodes returns the attribute edges between two nodes. If there are no direct edges, return nil

func NewEdge

func NewEdge(label string) Edge

NewEdge returns a new initialized edge

type EdgeCompiler

type EdgeCompiler interface {
	// CompileEdge gets an edge and compiles the associated term on that
	// edge. It should store tje compiled state into edge.Compiled with
	// an opaque key
	CompileEdge(Edge) error
}

EdgeCompiler interface represents term compilation algorithm when the term is an edge

During schema compilation, if the term metadata for the edge label implements EdgeCompiler, this method is called.

func GetEdgeCompiler

func GetEdgeCompiler(term string) EdgeCompiler

GetEdgeCompiler return a compiler that will compile the term when the term is an edge label

type EdgeFuncResult

type EdgeFuncResult int
const (
	FollowEdgeResult EdgeFuncResult = iota
	SkipEdgeResult
	StopEdgeResult
)

type EdgeSet

type EdgeSet map[Edge]struct{}

An EdgeSet is a set of edges

func NewEdgeSet

func NewEdgeSet(edge ...Edge) EdgeSet

NewEdgeSet creates a new edge set containing the given edges

func (EdgeSet) Slice

func (set EdgeSet) Slice() []Edge

Slice returns edges in the set as a slice

type EncodingIndex

type EncodingIndex int

EncodingIndex determines the encoding name index

const (
	UnknownEncodingIndex EncodingIndex = 0
	MIMEEncodingIndex    EncodingIndex = 1
	IANAEncodingIndex    EncodingIndex = 2
	MIBEncodingIndex     EncodingIndex = 3
)

Encoding indexes. If encoding name index is unknown, use UnknownEncodingIndex

func (EncodingIndex) Encoding

func (index EncodingIndex) Encoding(name string) (encoding.Encoding, error)

GetEncoding returns the encoding based on the index value. In index is UnknownEncodingIndex, it tries to resolve the name using IANA, MIME, and MIB indexes, in that order.

type ErrDuplicateAttributeID

type ErrDuplicateAttributeID string

func (ErrDuplicateAttributeID) Error

func (e ErrDuplicateAttributeID) Error() string

type ErrDuplicateNodeID

type ErrDuplicateNodeID string

func (ErrDuplicateNodeID) Error

func (e ErrDuplicateNodeID) Error() string

type ErrInvalidInput

type ErrInvalidInput struct {
	ID  string
	Msg string
}

func (ErrInvalidInput) Error

func (e ErrInvalidInput) Error() string

type ErrInvalidValidator

type ErrInvalidValidator struct {
	Validator string
	Msg       string
	Err       error
}

ErrInvalidValidator is used to return validator compilation errors

func (ErrInvalidValidator) Error

func (e ErrInvalidValidator) Error() string

func (ErrInvalidValidator) Unwrap

func (e ErrInvalidValidator) Unwrap() error

type ErrMultipleTypes

type ErrMultipleTypes string

func (ErrMultipleTypes) Error

func (e ErrMultipleTypes) Error() string

type ErrNotFound

type ErrNotFound string

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type ErrTerm

type ErrTerm struct {
	Term string
	Err  error
}

func (ErrTerm) Error

func (e ErrTerm) Error() string

func (ErrTerm) Unwrap

func (e ErrTerm) Unwrap() error

type ErrUnknownOperator

type ErrUnknownOperator struct {
	Operator string
}

func (ErrUnknownOperator) Error

func (e ErrUnknownOperator) Error() string

type ErrValidation

type ErrValidation struct {
	Validator string
	Msg       string
	Value     string
	Err       error
}

ErrValidation is used to return validator errors

func (ErrValidation) Error

func (e ErrValidation) Error() string

func (ErrValidation) Unwrap

func (e ErrValidation) Unwrap() error

type ErrValidatorCompile

type ErrValidatorCompile struct {
	Validator string
	NodeID    string
	Msg       string
	Err       error
}

ErrValidatorCompile is returned for validator compilation errors

func (ErrValidatorCompile) Error

func (e ErrValidatorCompile) Error() string

func (ErrValidatorCompile) Unwrap

func (e ErrValidatorCompile) Unwrap() error

type LDMarshaler

type LDMarshaler struct {
	// If set, generates node identifiers from the given node. It should
	// be able to generate blank node IDs if the node is to be
	// represented as an RDF blank node, or if the node does not have an
	// ID.
	//
	// If not set, the default generator function uses the string node
	// id, or _b:<n> if the node does not have an id.
	NodeIDGeneratorFunc func(Node) string

	// If set, generates edge labels for the given edge. If it is not set,
	// the default is to use the edge label. If edge does not have a
	// label,
	EdgeLabelGeneratorFunc func(Edge) string
}

LDMarshaler renders a graph in JSON-LD flattened format

func (*LDMarshaler) Marshal

func (rd *LDMarshaler) Marshal(input *digraph.Graph) interface{}

type Layer

type Layer struct {
	*digraph.Graph
	// contains filtered or unexported fields
}

A Layer is either a schema or an overlay. It keeps the definition of a layer as a directed labeled property graph.

The root node of the layer keeps layer identifying information. The root node is connected to the schema node which contains the actual object defined by the layer.

func NewLayer

func NewLayer() *Layer

NewLayer returns a new empty layer

func UnmarshalLayer

func UnmarshalLayer(in interface{}) (*Layer, error)

UnmarshalLayer unmarshals a schema ar overlay

func (*Layer) Clone

func (l *Layer) Clone() *Layer

Clone returns a copy of the layer

func (*Layer) Compose

func (layer *Layer) Compose(source *Layer) error

Compose schema layers. Directly modifies the source and the target. The source must be an overlay.

func (*Layer) FindAttributeByID

func (l *Layer) FindAttributeByID(id string) (Node, []Node)

FindAttributeByID returns the attribute and the path to it

func (*Layer) FindFirstAttribute

func (l *Layer) FindFirstAttribute(predicate func(Node) bool) (Node, []Node)

FindFirstAttribute returns the first attribute for which the predicate holds

func (*Layer) ForEachAttribute

func (l *Layer) ForEachAttribute(f func(Node, []Node) bool) bool

ForEachAttribute calls f with each attribute node, depth first. If f returns false, iteration stops

func (*Layer) ForEachAttributeOrdered

func (l *Layer) ForEachAttributeOrdered(f func(Node, []Node) bool) bool

ForEachAttributeOrdered calls f with each attribute node, depth first and in order. If f returns false, iteration stops

func (*Layer) GetAttributePath

func (l *Layer) GetAttributePath(node Node) []Node

GetPath returns the path to the given attribute node

func (*Layer) GetEncoding

func (l *Layer) GetEncoding() (encoding.Encoding, error)

GetEncoding returns the encoding that should be used to ingest/export data using this layer. The encoding information is taken from the schema root node characterEncoding annotation. If missing, the default encoding is used, which does not perform any character translation

func (*Layer) GetID

func (l *Layer) GetID() string

GetID returns the ID of the layer

func (*Layer) GetLayerInfoNode

func (l *Layer) GetLayerInfoNode() Node

GetLayerInfoNode returns the root node of the schema

func (*Layer) GetLayerType

func (l *Layer) GetLayerType() string

GetLayerType returns the layer type, SchemaTerm or OverlayTerm.

func (*Layer) GetSchemaRootNode

func (l *Layer) GetSchemaRootNode() Node

GetSchemaRootNode returns the root node of the object defined by the schema

func (*Layer) GetTargetType

func (l *Layer) GetTargetType() string

GetTargetType returns the value of the targetType field from the layer information node

func (*Layer) NewNode

func (l *Layer) NewNode(ID string, types ...string) Node

NewNode creates a new node for the layer with the given ID and types, and adds the node to the layer

func (*Layer) RenameBlankNodes

func (l *Layer) RenameBlankNodes(namer func(Node))

RenameBlankNodes will call namerFunc for each blank node, so they can be renamed and won't cause name clashes

func (*Layer) SetID

func (l *Layer) SetID(ID string)

SetID sets the ID of the layer

func (*Layer) SetLayerType

func (l *Layer) SetLayerType(t string)

SetLayerType sets if the layer is a schema or an overlay

func (*Layer) SetTargetType

func (l *Layer) SetTargetType(t string)

SetTargetType sets the targe types of the layer

func (*Layer) Slice

func (layer *Layer) Slice(layerType string, nodeFilter func(*Layer, Node) Node) *Layer

type Node

type Node interface {
	digraph.Node

	// Return the types of the node
	GetTypes() *Types

	// Return node ID
	GetID() string

	// Set node ID
	SetID(string)

	// Clone returns a new node that is a copy of this one, but the
	// returned node is not connected
	Clone() Node

	// Value of the document node, nil if the node is not a document node
	GetValue() interface{}

	SetValue(interface{})

	GetIndex() int
	SetIndex(int)

	// GetProperties returns the name/value pairs of the node. The
	// values are either string or []string. When cloned, the new node
	// receives a deep copy of the map
	GetProperties() map[string]*PropertyValue

	// Returns the compiled data map. This map is used to store
	// compilation information related to the node, and its contents are
	// unspecified. If the node is cloned with compiled data map, the
	// new node will get a shallow copy of the compiled data
	GetCompiledDataMap() map[interface{}]interface{}
}

Node is the node type used for schema layer graphs

func InstanceOf

func InstanceOf(node Node) []Node

InstanceOf returns the transitive closure of all the nodes that are connect to this node via instanceOf term,

func NewNode

func NewNode(ID string, types ...string) Node

NewNode returns a new node with the given types

type NodeCompiler

type NodeCompiler interface {
	// CompileNode gets a node and compiles the associated term on that
	// node. It should store the compiled state into node.Compiled with
	// the an opaque key
	CompileNode(Node) error
}

NodeCompiler interface represents term compilation algorithm when the term is a node.

During schema compilation, if a node is found to be a semantic annotation node (i.e. not an attribute node), and if the term metadata for the node label implements NodeCompiler, this function is called to compile the node.

func GetNodeCompiler

func GetNodeCompiler(term string) NodeCompiler

GetNodeCompiler return a compiler that will compile the term when the term is a node label

type NodeSet

type NodeSet struct {
	// contains filtered or unexported fields
}

NodeSet is a set of nodes

func NewNodeSet

func NewNodeSet(node ...Node) NodeSet

NewNodeSet constructs a new nodeset from the given nodes

func (*NodeSet) Add

func (n *NodeSet) Add(nodes ...Node)

Add adds nodes to the set

func (*NodeSet) Delete

func (n *NodeSet) Delete(nodes ...Node)

Delete some nodes from the set

func (NodeSet) EqualSet

func (n NodeSet) EqualSet(n2 NodeSet) bool

EqualSet returns if the two nodesets are equal without taking into account the node ordering

func (NodeSet) Has

func (n NodeSet) Has(node Node) bool

Has returns true if node is in the set

func (NodeSet) Len

func (n NodeSet) Len() int

func (NodeSet) Map

func (n NodeSet) Map() map[Node]struct{}

Set returns the nodes as a map

func (NodeSet) Slice

func (n NodeSet) Slice() []Node

Slice returns the nodes in a nodeset as a slice

type NopFilter

type NopFilter struct{}

NopFilter does not modify the underlying value

func (NopFilter) FilterValue

func (NopFilter) FilterValue(in interface{}, _ Node) interface{}

type PropertyValue

type PropertyValue struct {
	// contains filtered or unexported fields
}

PropertyValue can be a string or []string. It is an immutable value object

func IntPropertyValue

func IntPropertyValue(i int) *PropertyValue

IntPropertyValue converts the int value to string, and returns a string value

func ListAppend

func ListAppend(v1, v2 *PropertyValue) *PropertyValue

ListAppend appends v2 and v1

func SetUnion

func SetUnion(v1, v2 *PropertyValue) *PropertyValue

SetUnion computes the set union of properties v1 and v2

func StringPropertyValue

func StringPropertyValue(s string) *PropertyValue

StringPropertyValue creates a string value

func StringSlicePropertyValue

func StringSlicePropertyValue(s []string) *PropertyValue

StringSlicePropertyValue creates a []string value. If s is nil, it creates an empty slice

func (*PropertyValue) AsInt

func (p *PropertyValue) AsInt() int

AsInt attempts to return the underlying string value as integer

func (*PropertyValue) AsInterfaceSlice

func (p *PropertyValue) AsInterfaceSlice() []interface{}

AsInterfaceSlice returns an interface slice of the underlying value if it is a []string

func (*PropertyValue) AsString

func (p *PropertyValue) AsString() string

AsString returns the value as string

func (*PropertyValue) AsStringSlice

func (p *PropertyValue) AsStringSlice() []string

AsStringSlice returns the value as string slice

func (PropertyValue) Clone

func (p PropertyValue) Clone() *PropertyValue

func (*PropertyValue) Equal

func (p *PropertyValue) Equal(v *PropertyValue) bool

Equal compares two property values, and returns true if they are equal

func (*PropertyValue) Has

func (p *PropertyValue) Has(s string) bool

Has checks if p has the given string or is equal to it

func (*PropertyValue) IsInt

func (p *PropertyValue) IsInt() bool

Returns true if the underlying value is a string, and that string can be converted to int

func (*PropertyValue) IsString

func (p *PropertyValue) IsString() bool

IsString returns true if the underlying value is a string

func (*PropertyValue) IsStringSlice

func (p *PropertyValue) IsStringSlice() bool

IsStringSlice returns true if the underlying value is a string slice

func (PropertyValue) String

func (p PropertyValue) String() string

type SchemaManifest

type SchemaManifest struct {
	ID         string
	Type       string
	TargetType string
	Bundle     string
	Schema     string
	Overlays   []string
}

SchemaManifest contains the minimal information to define a schema variant with an optional bundle

func UnmarshalSchemaManifest

func UnmarshalSchemaManifest(in interface{}) (*SchemaManifest, error)

Unmarshals the given jsonld document into a schema manifest

func (*SchemaManifest) GetID

func (m *SchemaManifest) GetID() string

GetID returns the schema manifest ID

type TermCompiler

type TermCompiler interface {
	// CompileTerm gets a term and its value, and returns an object that
	// will be placed in the Compiled map of the node or the edge.
	CompileTerm(string, *PropertyValue) (interface{}, error)
}

TermCompiler interface represents term compilation algorithm. This is used to compile terms stored as node/edge properties. If the term metadata implements TermCompiler, this method is called, and the result is stored in the Compiled map of the node/edge with the term as the key.

func GetTermCompiler

func GetTermCompiler(term string) TermCompiler

GetTermCompiler return a compiler that will compile the term when the term is a node/edge property

type TermSemantics

type TermSemantics struct {
	// The term
	Term string `json:"term" yaml:"term"`

	// If true, the term value is an @id (IRI). In JSON-LD, the values for
	// this term will be marshalled as @id
	IsID bool `json:"isId" yaml:"isId"`

	// If true, the term is a list. In JSON-LD, its elements will be
	// marshaled under @list
	IsList bool `json:"isList" yaml:"isList"`

	Composition CompositionType `json:"composition,omitempty" yaml:"composition,omitempty"`

	Metadata interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}

TermSemantics is used to describe how a term operates within the layered schemas framework.

func GetTermInfo

func GetTermInfo(term string) TermSemantics

func (TermSemantics) Compose

func (t TermSemantics) Compose(target, src *PropertyValue) (*PropertyValue, error)

type TestCase

type TestCase interface {
	GetName() string
	Run(*testing.T)
}

type Types

type Types struct {
	// contains filtered or unexported fields
}

Types is a set of strings for representing node types

func CombineNodeTypes

func CombineNodeTypes(nodes []Node) *Types

CombineNodeTypes returns a combination of the types of all the given nodes

func (*Types) Add

func (types *Types) Add(t ...string)

Add adds new types. The result is the set-union of the existing types and the given types

func (*Types) AddTypes

func (types *Types) AddTypes(t ...*Types)

AddTypes adds all the types into this one

func (Types) Has

func (types Types) Has(t string) bool

Has returns true if the set has the given type

func (Types) Len

func (types Types) Len() int

func (*Types) Remove

func (types *Types) Remove(t ...string)

Remove removes the given set of types from the node.

func (*Types) Set

func (types *Types) Set(t ...string)

Set sets the types

func (Types) Slice

func (types Types) Slice() []string

func (Types) String

func (types Types) String() string

type Validator

type Validator interface {
	Validate(docNode, layerNode Node) error
}

A Validator is used to validate document nodes based on their schema. The Validate function is called with the document node that needs to be validated, and the associated schema node.

func GetAttributeValidator

func GetAttributeValidator(term string) Validator

GetAttributeValidator returns a validator implementation for the given validation term

type ValueFilter

type ValueFilter interface {
	FilterValue(interface{}, Node) interface{}
}

A ValueFilter applies a filter to the node value

func GetValueFilter

func GetValueFilter(term string) ValueFilter

GetValueFilter returns the value filter for the term. If the term has none, returns NopFilter

type Walk

type Walk struct {
	// contains filtered or unexported fields
}

A Walk specifies an edge-node-edge-node... predicate sequence. The predicates alter, it starts with an edge predicate, and then follows a node predicate, edge predicate, etc. In the end, the walk specifies all the nodes selected by the paths defined by the edge-node predicates.

func NewWalk

func NewWalk() *Walk

NewWalk creates a new walk

func (*Walk) Step

func (w *Walk) Step(edge func(Edge) bool, node func(Node) bool) *Walk

Step adds a new edge and node to the walk

func (*Walk) Walk

func (w *Walk) Walk(start []Node) []Node

Walk the walk starting at the given nodes, and return all the nodes arrived

Jump to

Keyboard shortcuts

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