ls

package
v1.0.0-beta14 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: Apache-2.0 Imports: 19 Imported by: 3

Documentation

Overview

Copyright 2021 Cloud Privacy Labs, LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	IngestAsNode     = "node"
	IngestAsEdge     = "edge"
	IngestAsProperty = "property"
)

IngestAs constants

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

Variables

View Source
var (
	ErrInvalidJsonLdGraph          = errors.New("Invalid JsonLd graph")
	ErrInvalidJsonGraph            = errors.New("Invalid JSON graph")
	ErrUnexpectedEOF               = errors.New("Unexpected EOF")
	ErrAttributeWithoutID          = errors.New("Attribute without id")
	ErrNotALayer                   = errors.New("Not a layer")
	ErrCompositionSourceNotOverlay = errors.New("Composition source is not an overlay")
	ErrIncompatibleComposition     = errors.New("Incompatible composition of layers")

	ErrInvalidComposition = errors.New("Invalid composition")
)

Error declarations for marshaling and composition

View Source
var (
	// ReferenceFKTerm specifies the foreign key attribute ID
	ReferenceFKTerm = NewTerm(LS+"Reference/", "fk", false, false, OverrideComposition, nil)

	// ReferenceLabelTerm specifies the edge label between the referenced nodes
	ReferenceLabelTerm = NewTerm(LS+"Reference/", "label", false, false, OverrideComposition, nil)

	// ReferenceLinkTerm specifies the direction of the edge. If
	// ->, the edge points to the target entity. If <-, the edge points
	// to this entity.
	ReferenceLinkTerm = NewTerm(LS+"Reference/", "link", false, false, OverrideComposition, nil)

	// ReferenceMultiTerm specifies if there can be more than one link targets
	ReferenceMultiTerm = NewTerm(LS+"Reference/", "multi", false, false, OverrideComposition, nil)
)
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)

	// ComposeTerm is used for overlays to redefine term compositions. One of CompositionType constants
	ComposeTerm = NewTerm(LS, "compose", false, false, OverrideComposition, nil)

	// AttributeOverlaysTerm lists the overlays for schema attributes
	// that are matched by ID, as opposed to matching by ID and their
	// place in the layer
	AttributeOverlaysTerm = NewTerm(LS, "attributeOverlays", false, true, OverrideComposition, nil)

	// 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, "instanceOf", false, false, ErrorComposition, nil)

	// SchemaNodeIDTerm denotes the schema node ID for ingested nodes
	SchemaNodeIDTerm = NewTerm(LS, "schemaNodeId", false, false, ErrorComposition, nil)

	SchemaBaseTerm = NewTerm(LS, "SchemaVariant/schema", true, false, ErrorComposition, nil)
	OverlaysTerm   = NewTerm(LS, "SchemaVariant/overlays", true, true, ErrorComposition, nil)

	// SchemaVariantTerm is the schema variant type
	SchemaVariantTerm = NewTerm(LS, "SchemaVariant", false, false, NoComposition, 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, OverrideComposition, 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)

	// Format specifies a type-specific formatting directive, such as a date format
	FormatTerm = NewTerm(LS, "format", false, false, OverrideComposition, nil)
	// EntitySchemaTerm is inserted by the schema compilation to mark
	// entity roots. It records the schema ID containing the entity
	// definition.
	EntitySchemaTerm = NewTerm(LS, "entitySchema", false, false, ErrorComposition, nil)

	// NodeIDTerm keeps the node ID or the attribute ID
	NodeIDTerm = NewTerm(LS, "nodeID", false, false, ErrorComposition, nil)

	// IngestAsTerm ingests value as an edge, node, or property
	IngestAsTerm = NewTerm(LS, "ingestAs", false, false, OverrideComposition, nil)

	// AsPropertyOfTerm is optional. If specified, it gives the nearest
	// ancestor node that is an instance of the given type. If not, it
	// is the parent document node
	AsPropertyOfTerm = NewTerm(LS, "asPropertyOf", false, false, OverrideComposition, nil)

	// EdgeLabelTerm represents the value used as an edge label, when ingesting an edge
	EdgeLabelTerm = NewTerm(LS, "edgeLabel", false, false, OverrideComposition, nil)

	// PropertyNameTerm represents the value used as a property name when ingesting a property
	PropertyNameTerm = NewTerm(LS, "propertyName", false, false, OverrideComposition, nil)

	// DocumentNodeTerm is the type of document nodes
	DocumentNodeTerm = NewTerm(LS, "DocumentNode", false, false, ErrorComposition, nil)

	// NodeValueTerm is the property key used to keep node value
	NodeValueTerm = NewTerm(LS, "value", false, false, ErrorComposition, nil)

	// ValueTypeTerm defines the type of a value
	ValueTypeTerm = NewTerm(LS, "valueType", false, false, OverrideComposition, nil)

	// HasTerm is an edge term for linking document elements
	HasTerm = NewTerm(LS, "has", false, false, ErrorComposition, nil)

	// EntityIDFieldsTerm is a string or []string that lists the attribute IDs
	// for entity ID. It is defined at the root node of a layer. All
	// attribute IDs must refer to value nodes.
	EntityIDFieldsTerm = NewTerm(LS, "entityIdFields", false, false, OverrideComposition, nil)

	// EntityIDTerm is a string or []string that gives the unique ID of
	// an entity. This is a node property at the root node of an entity
	EntityIDTerm = NewTerm(LS, "entityId", false, false, OverrideComposition, nil)
)
View Source
var (
	AttributeTypeValue       = NewTerm(LS, "Value", false, false, OverrideComposition, nil)
	AttributeTypeObject      = NewTerm(LS, "Object", false, false, OverrideComposition, nil)
	AttributeTypeArray       = NewTerm(LS, "Array", false, false, OverrideComposition, nil)
	AttributeTypeReference   = NewTerm(LS, "Reference", false, false, OverrideComposition, nil)
	AttributeTypeComposite   = NewTerm(LS, "Composite", false, false, OverrideComposition, nil)
	AttributeTypePolymorphic = NewTerm(LS, "Polymorphic", false, false, OverrideComposition, nil)
	AttributeNodeTerm        = NewTerm(LS, "Attribute", false, false, OverrideComposition, nil)
)

Attribute types 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 (
	// Unordered named attributes (json object)
	ObjectAttributesTerm = NewTerm(LS, "Object/attributes", false, false, ErrorComposition, nil)
	// Ordered named attributes (json object, xml elements)
	ObjectAttributeListTerm = NewTerm(LS, "Object/attributeList", false, true, ErrorComposition, nil)
	// Reference to another schema. This will be resolved to another
	// schema during compilation
	ReferenceTerm = NewTerm(LS, "Reference/ref", false, false, ErrorComposition, nil)
	// ArrayItems contains the definition for the items of the array
	ArrayItemsTerm = NewTerm(LS, "Array/elements", false, false, ErrorComposition, nil)
	// All components of a composite attribute
	AllOfTerm = NewTerm(LS, "Composite/allOf", false, true, ErrorComposition, nil)
	// All options of a polymorphic attribute
	OneOfTerm = NewTerm(LS, "Polymorphic/oneOf", false, true, ErrorComposition, nil)
)

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

View Source
var (
	// ValuesetContextTerm specifies the context under which valueset related values are to be looked up.
	//
	// For instance, consider a row of data:
	//
	//   root ----> item1
	//        ----> item2
	//
	// If item1 and item2 are values that can be used as an input to
	// valueset lookup, then the context should be set to root
	//
	// A node must contain either the ValuesetContextTerm or the ValuesetTablesTerm to be used in lookup
	ValuesetContextTerm = NewTerm(LS, "vs/context", false, false, OverrideComposition, nil)

	// ValuesetTablesTerm specifies the list of table IDs to
	// lookup. This is optional.  A node must contain either the
	// ValuesetContextTerm or the ValuesetTablesTerm to be used in
	// lookup
	ValuesetTablesTerm = NewTerm(LS, "vs/valuesets", false, false, OverrideComposition, nil)

	// ValuesetRequestKeysTerm specifies the keys that will be used in
	// the valueset request. These keys are interpreted by the valueset
	// lookup.
	ValuesetRequestKeysTerm = NewTerm(LS, "vs/requestKeys", false, false, OverrideComposition, nil)

	// ValuesetRequestValuesTerm contains entries matching
	// ValuesetRequestKeysTerm. It specifies the schema node IDs of the
	// nodes containing values to lookup
	ValuesetRequestValuesTerm = NewTerm(LS, "vs/requestValues", false, false, OverrideComposition, nil)

	// ValuesetResultKeys term contains the keys that will be returned
	// from the valueset lookup. Values of these keys will be inserted under the context
	ValuesetResultKeysTerm = NewTerm(LS, "vs/resultKeys", false, false, OverrideComposition, nil)

	// ValuesetResultValuesTerm specifies the schema node IDs for the
	// nodes that will receive the matching key values. If there is only one, resultKeys is optional
	ValuesetResultValuesTerm = NewTerm(LS, "vs/resultValues", false, false, OverrideComposition, nil)
)
View Source
var DefaultLogLevel = LogLevelError
View Source
var DefaultTermMarshaler defaultTermMarshaler
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 IncludeAllNodesInSliceFunc = func(layer *Layer, nd graph.Node) graph.Node {
	return CloneNode(nd, layer.Graph)
}

IncludeAllNodesInSliceFunc includes all the nodes in the slice

OnlyDocumentNodes can be used in IterateDescendants edge func to follow edges that reach to document nodes

SkipDocumentNodes can be used in IterateDescendants edge func to skip all edges that go to a document node

SkipSchemaNodes can be used in IterateDescendants edge func to skip all edges that go to a schema node

Functions

func CloneEdge

func CloneEdge(fromInTarget, toInTarget graph.Node, sourceEdge graph.Edge, targetGraph graph.Graph) graph.Edge

func CloneNode

func CloneNode(sourceNode graph.Node, targetGraph graph.Graph) graph.Node

CloneNode clones the sourcenode in targetgraph

func CloneProperties

func CloneProperties(iterator interface {
	ForEachProperty(func(string, interface{}) bool) bool
}) map[string]interface{}

CloneProperties can be used to clone edge and node properties

func ClonePropertyValueFunc

func ClonePropertyValueFunc(key string, value interface{}) interface{}

ClonePropertyFunc can be used in graph copy functions

func CombineNodeTypes

func CombineNodeTypes(nodes []graph.Node) graph.StringSet

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

func CompileTerms

func CompileTerms(layer *Layer) error

CompileTerms compiles all node and edge terms of the layer

func ComposeProperties

func ComposeProperties(context *Context, target, source graph.Node) error

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

func CopyGraph

func CopyGraph(target, source graph.Graph, nodeSelector func(graph.Node) bool, edgeSelector func(graph.Edge) bool) map[graph.Node]graph.Node

CopyGraph source to target using the optional node/edge 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 CopySchemaNodeIntoGraph

func CopySchemaNodeIntoGraph(target graph.Graph, schemaNode graph.Node) graph.Node

CopySchemaNodeIntoGraph copies a schema node and the subtree under it that does not belong the schema into the target graph

func DeepEqual

func DeepEqual(i1, i2 interface{}) error

DeepEqual test equivalence between two JSON trees

func DocumentNodesUnder

func DocumentNodesUnder(node ...graph.Node) []graph.Node

DocumentNodesUnder returns all document nodes under the given node(s)

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 FindChildInstanceOf

func FindChildInstanceOf(parent graph.Node, childAttrID string) []graph.Node

FindChildInstanceOf returns the childnodes of the parent that are instance of the given attribute id

func FindNodeByID

func FindNodeByID(g graph.Graph, ID string) []graph.Node

func FollowEdgesToNodeWithType

func FollowEdgesToNodeWithType(typ string) func(graph.Edge) EdgeFuncResult

FollowEdgesToNodeWithType returns a function that only follows edges that go to a node with the given type

func ForEachAttributeNode

func ForEachAttributeNode(root graph.Node, f func(node graph.Node, path []graph.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 graph.Node, f func(node graph.Node, path []graph.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 GetArrayElementNode

func GetArrayElementNode(arraySchemaNode graph.Node) graph.Node

GetArrayElementNode returns the array element node from an array node

func GetAttributeID

func GetAttributeID(node graph.Node) string

GetAttributeID returns the attributeID

func GetAttributePath

func GetAttributePath(root, node graph.Node) []graph.Node

func GetAttributeValidator

func GetAttributeValidator(term string) (NodeValidator, ValueValidator)

GetAttributeValidator returns a validator implementation for the given validation term

func GetEntityRoot

func GetEntityRoot(node graph.Node) graph.Node

GetEntityRoot tries to find the entity containing this node by going backwards until a node with EntitySchemaTerm

func GetEntityRootNode

func GetEntityRootNode(aNode graph.Node) graph.Node

GetEntityRootNode returns the entity root node containing this node

func GetEntityRootNodes

func GetEntityRootNodes(g graph.Graph) map[graph.Node]EntityInfo

GetEntityRootNodes returns all the nodes that are entity roots, i.e. nodes containing EntitySchemaTerm

func GetIngestAs

func GetIngestAs(schemaNode graph.Node) string

GetIngestAs returns "node", "edge", or "property" based on IngestAsTerm

func GetNodeID

func GetNodeID(node graph.Node) string

GetNodeID returns the nodeid

func GetNodeIndex

func GetNodeIndex(node graph.Node) int

GetNodeIndex returns the value of attribute index term as int

func GetNodeValue

func GetNodeValue(node graph.Node) (interface{}, error)

GetNodeValue returns the field value processed by the schema type information. The returned object is a Go native object based on the node type

func GetNodesInstanceOf

func GetNodesInstanceOf(g graph.Graph, attrId string) []graph.Node

GetNodesInstanceOf returns document nodes that are instance of the given attribute id

func GetObjectAttributeNodes

func GetObjectAttributeNodes(objectSchemaNode graph.Node) []graph.Node

GetObjectAttributeNodes returns the schema attribute nodes under a schema object.

func GetObjectAttributeNodesBy

func GetObjectAttributeNodesBy(objectSchemaNode graph.Node, keyTerm string) (map[string][]graph.Node, error)

GetObjectAttributeNodesBy returns the schema attribute nodes under a schema object. The returned map is keyed by the keyTerm

func GetParentAttribute

func GetParentAttribute(node graph.Node) graph.Node

GetParentAttribute returns the parent attribute of the given node

func GetParentDocumentNodes

func GetParentDocumentNodes(node graph.Node) []graph.Node

GetParentDocumentNodes returns the document nodes that have incoming edges to this node

func GetPolymorphicOptions

func GetPolymorphicOptions(polymorphicSchemaNode graph.Node) []graph.Node

GetPolymorphicOptions returns the polymorphic options of a schema node

func GetRawNodeValue

func GetRawNodeValue(node graph.Node) (string, bool)

GetRawNodeValue returns the unprocessed node value

func GetSliceByTermsFunc

func GetSliceByTermsFunc(includeTerms []string, includeAttributeNodes bool) func(*Layer, graph.Node) graph.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 GetTermMetadata

func GetTermMetadata(term string) interface{}

GetTermMetadata returns metadata about a term

func Ingest

func Ingest(builder GraphBuilder, root ParsedDocNode) (graph.Node, error)

func InstanceOf

func InstanceOf(node graph.Node) []graph.Node

InstanceOf returns the nodes that are connect to this node via instanceOf term,

func InternSlice

func InternSlice(interner Interner, slice []string) []string

InternSlice interns all elements of a slice

func IsAttributeNode

func IsAttributeNode(node graph.Node) bool

IsAttributeNode returns true if the node has Attribute type

func IsAttributeTreeEdge

func IsAttributeTreeEdge(edge graph.Edge) bool

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

func IsDocumentEdge

func IsDocumentEdge(edge graph.Edge) bool

IsDocumentEdge returns true if the edge is not an attribute link term

func IsDocumentNode

func IsDocumentNode(node graph.Node) bool

IsDocumentNode returns if the node has the DocumentNodeTerm as one of its labels

func IsNodeEntityRoot

func IsNodeEntityRoot(node graph.Node) bool

IsNodeEntityRoot checks if node is an entity root

func IsPropertiesEqual

func IsPropertiesEqual(p, q map[string]*PropertyValue) bool

IsPropertiesEqual compares two property maps and returns true if they are equal

func IterateAncestors

func IterateAncestors(root graph.Node, nodeFunc func(graph.Node) bool, edgeFunc func(graph.Edge) EdgeFuncResult) bool

IterateAncestors iterates the ancestors of the node, calling nodeFunc for each node, and edgeFunc for each edge. If nodeFunc returns false, stops iteration and returns. The behavior after calling edgefunc depends on the return value. The edgeFunc may skip the edge, follow it, or stop processing.

func IterateDescendants

func IterateDescendants(from graph.Node, nodeFunc func(graph.Node) bool, edgeFunc func(graph.Edge) 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 returned DontFollowEdgeResult, edge is skipped. If edgeFunc returns StopEdgeResult, iteration stops.

func LDDescendToListElements

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

If in is a @list, returns its elements

func LDGetKeyValue

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

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

func LDGetListElements

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

LDGetListElements 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 LDGetNodeID

func LDGetNodeID(node interface{}) string

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

func LDGetNodeTypes

func LDGetNodeTypes(node interface{}) []string

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

func LDGetNodeValue

func LDGetNodeValue(node interface{}) string

LDGetNodeValue returns the node @value. The argument must be a map

func LDGetStringValue

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

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

func LDGetValueArr

func LDGetValueArr(in map[string]interface{}) []interface{}

LDGetValueArr returns the result of a "@value" as an array regardless of the number of items it contains

func MakeErrInvalidInput

func MakeErrInvalidInput(id ...string) error

MakeErrInvalidInput creates an ErrInvalidInput error. If there is only one argument, it is used as the ID field of the error. If there are two, then the first is used as the ID, and the second as msg. Other arguments are ignored.

func MarshalLayer

func MarshalLayer(layer *Layer) (interface{}, error)

Marshals the layer into an expanded jsonld document

func NewDocumentGraph

func NewDocumentGraph() graph.Graph

NewDocumentGraph creates a new graph with the correct indexes for document ingestion

func NewLayerGraph

func NewLayerGraph() graph.Graph

NewLayerGraph creates a new graph indexes to store layers

func NewTerm

func NewTerm(ns, lname string, isID, isList bool, comp CompositionType, md interface{}, aliases ...string) string

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

func PropertiesAsMap

func PropertiesAsMap(iterator interface {
	ForEachProperty(func(string, interface{}) bool) bool
}) map[string]*PropertyValue

func RegisterTerm

func RegisterTerm(t TermSemantics)

func RemoveRawNodeValue

func RemoveRawNodeValue(node graph.Node)

func RunTestsFromFile

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

func SetAttributeID

func SetAttributeID(node graph.Node, ID string)

SetAttrributeID sets the attribute ID

func SetNodeID

func SetNodeID(node graph.Node, ID string)

SetNodeID sets the node ID

func SetNodeIndex

func SetNodeIndex(node graph.Node, index int)

func SetNodeValue

func SetNodeValue(node graph.Node, value interface{}) error

SetNodeValue sets the node value using the given native Go value. The value is expected to be interpreted by the node types and converted to string. If there are no value accessors specified for the node, the value will be fmt.Sprint(value)

func SetRawNodeValue

func SetRawNodeValue(node graph.Node, value string)

SetRawNodeValue sets the unprocessed node value

func SkipEdgesToNodeWithType

func SkipEdgesToNodeWithType(typ string) func(graph.Edge, []graph.Node) EdgeFuncResult

SkipEdgesToNodeWithType returns a function that skips edges that go to a node with the given type

func SortEdges

func SortEdges(edges []graph.Edge) []graph.Edge

SortEdges sorts edges by their target node index

func SortEdgesItr

func SortEdgesItr(edges graph.EdgeIterator) graph.EdgeIterator

SortEdgesItr sorts the edges by index

func SortNodes

func SortNodes(nodes []graph.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

StringSetSubtract returns all elements that are in s1 but not in s2

func StringSetToSlice

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

StringSetToSlice converts a string set to slice

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 UnmarshalJSONLDGraph

func UnmarshalJSONLDGraph(input interface{}, target graph.Graph, interner Interner) error

UnmarshalJSONLDGraph Unmarshals a graph in JSON-LD format

func ValidateDocumentNode

func ValidateDocumentNode(node graph.Node) error

ValidateDocumentNode runs the validators for the document node

func ValidateDocumentNodeBySchema

func ValidateDocumentNodeBySchema(node, schemaNode graph.Node) error

ValidateDocumentNodeBySchema runs the validators for the document node

func ValidateValueBySchema

func ValidateValueBySchema(v *string, schemaNode graph.Node) error

ValidateValueBySchema runs the validators for the value

func WalkNodesInEntity

func WalkNodesInEntity(aNode graph.Node, f func(graph.Node) bool) bool

WalkNodesInEntity walks through all the nodes without crossing entity boundaries. It calls the function f for each node. The entity root containing the given node is also traversed.

Types

type BundleByID

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

BundleByID stores layers by their ID

func (*BundleByID) Add

func (b *BundleByID) Add(ctx *Context, variantID string, schema *Layer, overlays ...*Layer) (*Layer, error)

Add a new variant to the bundle. The variant ID must be unique. If variant ID is empty, schema ID will be used. If there are overlays, the variant will be built using the schema as the base, so caller must create a clone if necessary.

func (*BundleByID) LoadSchema

func (b *BundleByID) LoadSchema(ref string) (*Layer, error)

LoadSchema is a schema loader function using schema IDs as reference

type BundleByType

type BundleByType struct {
	Variants map[string]*Layer
}

BundleByType stores layers by their value type

func (*BundleByType) Add

func (b *BundleByType) Add(ctx *Context, typeName string, schema *Layer, overlays ...*Layer) (*Layer, error)

Add a new variant to the bundle. The typeName must be unique. If empty, schema type will be used. If there are overlays, the variant will be built using the schema as the base, so caller must create a clone if necessary.

func (*BundleByType) LoadSchema

func (b *BundleByType) LoadSchema(ref string) (*Layer, error)

SchemaLoader is a schema loader function using types as reference.

type CompilablePropertyContainer

type CompilablePropertyContainer interface {
	GetProperty(string) (interface{}, bool)
	SetProperty(string, interface{})
}

CompilablePropertyContainer contains properties and a compiled data map

type CompiledGraph

type CompiledGraph interface {
	GetCompiledSchema(string) *Layer
	PutCompiledSchema(*Context, string, *Layer) *Layer
	GetGraph() graph.Graph
}

A CompiledGraph is a graph of compiled schemas

type CompiledProperties

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

CompiledProperties is a lazy-initialized map

func (*CompiledProperties) CopyCompiledToMap

func (p *CompiledProperties) CopyCompiledToMap(target map[interface{}]interface{})

func (*CompiledProperties) CopyTo

func (p *CompiledProperties) CopyTo(target *CompiledProperties)

func (*CompiledProperties) GetCompiledProperty

func (p *CompiledProperties) GetCompiledProperty(key interface{}) (interface{}, bool)

func (*CompiledProperties) SetCompiledProperty

func (p *CompiledProperties) SetCompiledProperty(key, value interface{})

type Compiler

type Compiler struct {
	// Loader loads a layer using a strong reference.
	Loader SchemaLoader
	// CGraph keeps the compiled interlinked schemas. If this is
	// initialized before compilation, then it is used during compilation
	// and new schemas are added to it. If it is left uninitialized,
	// compilation initializes it to default compiled graph
	CGraph CompiledGraph
}

func (*Compiler) Compile

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

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

func (*Compiler) CompileSchema

func (compiler *Compiler) CompileSchema(context *Context, 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 Context

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

func DefaultContext

func DefaultContext() *Context

func NewContext

func NewContext(ctx context.Context) *Context

func (*Context) GetInterner

func (ctx *Context) GetInterner() Interner

func (*Context) GetLogger

func (ctx *Context) GetLogger() Logger

func (*Context) SetLogger

func (ctx *Context) SetLogger(log Logger) *Context

type DefaultCompiledGraph

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

DefaultCompiledGraph keeps compiled graphs in a map. Zero value of DefaultCompiledGraph is ready to use

func (DefaultCompiledGraph) GetCompiledSchema

func (d DefaultCompiledGraph) GetCompiledSchema(ref string) *Layer

GetCompiledSchema returns a compiled schema for the reference if known

func (DefaultCompiledGraph) GetGraph

func (d DefaultCompiledGraph) GetGraph() graph.Graph

func (*DefaultCompiledGraph) PutCompiledSchema

func (d *DefaultCompiledGraph) PutCompiledSchema(context *Context, ref string, layer *Layer) *Layer

PutCompiledSchema adds the copy of the schema to the common graph

type DefaultLogger

type DefaultLogger struct {
	Level LogLevel
	Trace bool
}

func NewDefaultLogger

func NewDefaultLogger() *DefaultLogger

func (DefaultLogger) Debug

func (l DefaultLogger) Debug(properties map[string]interface{})

func (DefaultLogger) Error

func (l DefaultLogger) Error(properties map[string]interface{})

func (DefaultLogger) Info

func (l DefaultLogger) Info(properties map[string]interface{})

type EdgeCompiler

type EdgeCompiler interface {
	// CompileEdge gets an edge and compiles the associated term on that
	// edge. It should store the compiled state into edge.Compiled with
	// an opaque key
	CompileEdge(*Layer, graph.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
)

func FollowEdgesInEntity

func FollowEdgesInEntity(edge graph.Edge) EdgeFuncResult

FollowEdgesInEntity follows only the document edges that do not cross entity boundaries

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 EntityInfo

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

EntityInfo contains the entity information in the doc graph

func (EntityInfo) GetEntitySchema

func (e EntityInfo) GetEntitySchema() string

func (EntityInfo) GetID

func (e EntityInfo) GetID() []string

func (EntityInfo) GetRoot

func (e EntityInfo) GetRoot() graph.Node

func (EntityInfo) GetValueType

func (e EntityInfo) GetValueType() []string

type ErrCannotDetermineEdgeLabel

type ErrCannotDetermineEdgeLabel struct {
	Msg          string
	Path         NodePath
	SchemaNodeID string
}

func (ErrCannotDetermineEdgeLabel) Error

type ErrCannotDeterminePropertyName

type ErrCannotDeterminePropertyName struct {
	Path         NodePath
	SchemaNodeID string
}

func (ErrCannotDeterminePropertyName) Error

type ErrCannotFindAncestor

type ErrCannotFindAncestor struct {
	Path         NodePath
	SchemaNodeID string
}

func (ErrCannotFindAncestor) Error

func (e ErrCannotFindAncestor) Error() string

type ErrCannotInstantiateSchemaNode

type ErrCannotInstantiateSchemaNode struct {
	SchemaNodeID string
	Reason       string
}

func (ErrCannotInstantiateSchemaNode) Error

type ErrCannotResolveLink LinkSpec

func (ErrCannotResolveLink) Error

func (err ErrCannotResolveLink) Error() string

type ErrDataIngestion

type ErrDataIngestion struct {
	Key string
	Err error
}

func (ErrDataIngestion) Error

func (e ErrDataIngestion) Error() string

func (ErrDataIngestion) Unwrap

func (e ErrDataIngestion) Unwrap() error

type ErrDuplicate

type ErrDuplicate string

ErrDuplicate is used for duplicate errors

func (ErrDuplicate) Error

func (e ErrDuplicate) Error() string

type ErrDuplicateAttributeID

type ErrDuplicateAttributeID string

ErrDuplicateAttributeID is used to denote a duplicate attribute in a schema

func (ErrDuplicateAttributeID) Error

func (e ErrDuplicateAttributeID) Error() string

type ErrInconsistentTypes

type ErrInconsistentTypes struct {
	ID        string
	TypeNames []string
}

ErrInconsistentTypes is returned if a node has multiple types that can interpret the value

func (ErrInconsistentTypes) Error

func (e ErrInconsistentTypes) Error() string

type ErrInvalidEntityID

type ErrInvalidEntityID struct {
	Path NodePath
}

func (ErrInvalidEntityID) Error

func (e ErrInvalidEntityID) Error() string

type ErrInvalidForeignKeys

type ErrInvalidForeignKeys struct {
	Spec LinkSpec
	Msg  string
}

func (ErrInvalidForeignKeys) Error

func (err ErrInvalidForeignKeys) Error() string

type ErrInvalidInput

type ErrInvalidInput struct {
	ID  string
	Msg string
}

ErrInvalidInput is used for errors due to incorrect values, unexpected syntax, etc.

func (ErrInvalidInput) Error

func (e ErrInvalidInput) Error() string

type ErrInvalidLinkSpec

type ErrInvalidLinkSpec struct {
	ID  string
	Msg string
}

func (ErrInvalidLinkSpec) Error

func (err ErrInvalidLinkSpec) Error() string

type ErrInvalidSchema

type ErrInvalidSchema string

func (ErrInvalidSchema) Error

func (e ErrInvalidSchema) 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 ErrInvalidValue

type ErrInvalidValue struct {
	ID    string
	Type  string
	Value interface{}
	Msg   string
}

func (ErrInvalidValue) Error

func (e ErrInvalidValue) Error() string

type ErrInvalidValuesetSpec

type ErrInvalidValuesetSpec struct {
	Msg string
}

func (ErrInvalidValuesetSpec) Error

func (e ErrInvalidValuesetSpec) Error() string

type ErrMultipleParentNodes

type ErrMultipleParentNodes struct {
	Of string
}

ErrMultipleParentNodes is used to denote multiple parentnodes detected during data ingestion

func (ErrMultipleParentNodes) Error

func (e ErrMultipleParentNodes) Error() string

type ErrMultipleTargetsFound

type ErrMultipleTargetsFound struct {
	ID string
}

func (ErrMultipleTargetsFound) Error

func (err ErrMultipleTargetsFound) Error() string

type ErrMultipleTypes

type ErrMultipleTypes string

ErrMultipleTypes denotes multiple incompatible types declared for an attribute

func (ErrMultipleTypes) Error

func (e ErrMultipleTypes) Error() string

type ErrNoParentNode

type ErrNoParentNode struct {
	Of string
}

ErrNoParentNode is used to denote no parent nodes for an ingested node

func (ErrNoParentNode) Error

func (e ErrNoParentNode) Error() string

type ErrNotFound

type ErrNotFound string

ErrNotFound is used for all not-found errors.

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type ErrSchemaValidation

type ErrSchemaValidation struct {
	Msg  string
	Path NodePath
}

func (ErrSchemaValidation) Error

func (e ErrSchemaValidation) Error() string

type ErrTerm

type ErrTerm struct {
	Term string
	Err  error
}

ErrTerm is used to denote a term operation error

func (ErrTerm) Error

func (e ErrTerm) Error() string

func (ErrTerm) Unwrap

func (e ErrTerm) Unwrap() error

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
	Object    interface{}
	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 ErrValueset

type ErrValueset struct {
	Msg          string
	SchemaNodeID string
}

func (ErrValueset) Error

func (e ErrValueset) Error() string

type GraphBuilder

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

GraphBuilder contains the methods to ingest a graph

func NewGraphBuilder

func NewGraphBuilder(g graph.Graph, options GraphBuilderOptions) GraphBuilder

NewGraphBuilder returns a new builder with an optional graph. If g is nil, a new graph is initialized

func (GraphBuilder) ArrayAsEdge

func (gb GraphBuilder) ArrayAsEdge(schemaNode, parentNode graph.Node, types ...string) (graph.Edge, error)

func (GraphBuilder) ArrayAsNode

func (gb GraphBuilder) ArrayAsNode(schemaNode, parentNode graph.Node, types ...string) (graph.Edge, graph.Node, error)

func (GraphBuilder) CollectionAsEdge

func (gb GraphBuilder) CollectionAsEdge(schemaNode, parentNode graph.Node, typeTerm string, types ...string) (graph.Edge, error)

func (GraphBuilder) CollectionAsNode

func (gb GraphBuilder) CollectionAsNode(schemaNode, parentNode graph.Node, typeTerm string, types ...string) (graph.Edge, graph.Node, error)

func (GraphBuilder) GetGraph

func (gb GraphBuilder) GetGraph() graph.Graph

func (GraphBuilder) GetOptions

func (gb GraphBuilder) GetOptions() GraphBuilderOptions

func (GraphBuilder) LinkNode

func (gb GraphBuilder) LinkNode(spec *LinkSpec, docNode, parentNode graph.Node, entityInfo map[graph.Node]EntityInfo) error

Link the given node, or create a link from the parent node.

`spec` is the link spec. `docNode` contains the ingested document node that will be linked. It can be nil. `parentNode` is the document node containing the docNode.

func (GraphBuilder) LinkNodes

func (gb GraphBuilder) LinkNodes(schema *Layer, entityInfo map[graph.Node]EntityInfo) error

func (GraphBuilder) NewNode

func (gb GraphBuilder) NewNode(schemaNode graph.Node) graph.Node

NewNode creates a new graph node as an instance of SchemaNode. Then it either merges schema properties into the new node, or creates an instanceOf edge to the schema node.

func (GraphBuilder) ObjectAsEdge

func (gb GraphBuilder) ObjectAsEdge(schemaNode, parentNode graph.Node, types ...string) (graph.Edge, error)

ObjectAsEdge creates an object node as an edge using the following scheme:

parent --object--> _blankNode --...

func (GraphBuilder) ObjectAsNode

func (gb GraphBuilder) ObjectAsNode(schemaNode, parentNode graph.Node, types ...string) (graph.Edge, graph.Node, error)

ObjectAsNode creates a new object node

func (GraphBuilder) ValueAsEdge

func (gb GraphBuilder) ValueAsEdge(schemaNode, parentDocumentNode graph.Node, value string, types ...string) (graph.Edge, error)
ValueAsEdge ingests a value using the following scheme:

input: (name: value)
output: --(label)-->(value:value, attributeName:name)

where label=attributeName (in this case "name") if edgeLabel is not specified in schema.

func (GraphBuilder) ValueAsNode

func (gb GraphBuilder) ValueAsNode(schemaNode, parentDocumentNode graph.Node, value string, types ...string) (graph.Edge, graph.Node, error)

ValueAsNode creates a new value node. The new node has the given value and the types

func (GraphBuilder) ValueAsProperty

func (gb GraphBuilder) ValueAsProperty(schemaNode graph.Node, graphPath []graph.Node, value string) error

ValueAsProperty ingests a value as a property of an ancestor node. The ancestor

type GraphBuilderOptions

type GraphBuilderOptions struct {
	// If true, schema node properties are embedded into document
	// nodes. If false, schema nodes are preserved as separate nodes,
	// with an instanceOf edge between the document node to the schema
	// node.
	EmbedSchemaNodes bool
	// If OnlySchemaAttributes is true, only ingest data points if there is a schema for it.
	// If OnlySchemaAttributes is false, ingest whether or not there is a schema for it.
	OnlySchemaAttributes bool
}

type Interner

type Interner interface {
	Intern(string) string
}

Interner interface is used to keep a string table to reduce memory footprint by eliminated repeated keys

type JSONGraph

type JSONGraph struct {
	Nodes []JSONGraphNode `json:"nodes"`
	Edges []JSONGraphEdge `json:"edges"`
}

type JSONGraphEdge

type JSONGraphEdge struct {
	From       int                       `json:"from"`
	To         int                       `json:"to"`
	Label      string                    `json:"label,omitempty"`
	Properties map[string]*PropertyValue `json:"properties,omitempty"`
}

JSONGraphEdge includes the from-to node indexes, the label and properties

type JSONGraphNode

type JSONGraphNode struct {
	N          int                       `json:"n"`
	ID         string                    `json:"id,omitempty"`
	Labels     []string                  `json:"labels,omitempty"`
	Properties map[string]*PropertyValue `json:"properties,omitempty"`
}

JSONGraphNode includes a node index, labels, and properties of the node

type JSONMarshaler

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

JSONMarshaler marshals/unmarshals a graph

func NewJSONMarshaler

func NewJSONMarshaler(interner Interner) *JSONMarshaler

func (*JSONMarshaler) Encode

func (m *JSONMarshaler) Encode(g graph.Graph, w io.Writer) error

Encode writes the graph as a JSON document to the given writer

func (*JSONMarshaler) Marshal

func (m *JSONMarshaler) Marshal(g graph.Graph) ([]byte, error)

Marshal marshals the graph as a JSON document

func (*JSONMarshaler) Unmarshal

func (m *JSONMarshaler) Unmarshal(in []byte, targetGraph graph.Graph) error

Unmarshal unmarshals a graph from JSON input

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(graph.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(graph.Edge) string
}

LDMarshaler renders a graph in JSON-LD flattened format

func (*LDMarshaler) Marshal

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

type LDNode

type LDNode struct {
	Node      map[string]interface{}
	ID        string
	Types     []string
	GraphNode graph.Node
	// contains filtered or unexported fields
}

type Layer

type Layer struct {
	Graph graph.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 LayersFromGraph

func LayersFromGraph(g graph.Graph) []*Layer

LayersFromGraph returns the layers from an existing graph. All Schema and Overlay nodes are returned as layers.

func NewLayer

func NewLayer() *Layer

NewLayer returns a new empty layer

func NewLayerInGraph

func NewLayerInGraph(g graph.Graph) *Layer

NewLayerInGraph creates a new layer in the given graph by creating a layerinfo root node for the layer. The graph may contain many other layers

func ReadLayerFromFile

func ReadLayerFromFile(f string) (*Layer, error)

func UnmarshalLayer

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

UnmarshalLayer unmarshals a schema ar overlay

func UnmarshalLayerFromSlice

func UnmarshalLayerFromSlice(in []byte) (*Layer, error)

func (*Layer) Clone

func (l *Layer) Clone() *Layer

Clone returns a copy of the layer in a new graph. If the graph contains other layers, they are not copied.

func (*Layer) CloneInto

func (l *Layer) CloneInto(targetGraph graph.Graph) (*Layer, map[graph.Node]graph.Node)

CloneInto clones the layer into the targetgraph. If the source graph contains other layers, they are not copied.

func (*Layer) Compose

func (layer *Layer) Compose(context *Context, 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) (graph.Node, []graph.Node)

FindAttributeByID returns the attribute and the path to it

func (*Layer) FindFirstAttribute

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

FindFirstAttribute returns the first attribute for which the predicate holds

func (*Layer) ForEachAttribute

func (l *Layer) ForEachAttribute(f func(graph.Node, []graph.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(graph.Node, []graph.Node) bool) bool

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

func (*Layer) GetAttributeByID

func (l *Layer) GetAttributeByID(id string) graph.Node

GetAttributeByID returns the attribute node by its ID.

func (*Layer) GetAttributePath

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

GetAttributePath returns the path to the given attribute node

func (*Layer) GetAttributesByID

func (l *Layer) GetAttributesByID(ids []string) []graph.Node

GetAttributesByID returns attribute nodes by ID

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) GetEntityIDNodes

func (l *Layer) GetEntityIDNodes() []string

GetEntityIDNodes returns the entity id attribute IDs from the layer root node

func (*Layer) GetID

func (l *Layer) GetID() string

GetID returns the ID of the layer

func (*Layer) GetLayerRootNode

func (l *Layer) GetLayerRootNode() graph.Node

GetLayerRootNode 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) GetOverlayAttributes

func (l *Layer) GetOverlayAttributes() []graph.Node

Returns the overlay attribute nodes if there are any

func (*Layer) GetSchemaRootNode

func (l *Layer) GetSchemaRootNode() graph.Node

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

func (*Layer) GetValueType

func (l *Layer) GetValueType() string

GetValueType returns the value of the valueType field from the layer information node. This is the type of the entity defined by the schema

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) SetValueType

func (l *Layer) SetValueType(t string)

SetValueType sets the value types of the layer

func (*Layer) Slice

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

type LinkSpec

type LinkSpec struct {
	SchemaNode graph.Node
	// The target schema/entity reference, populated from the
	// `reference` property of the node
	TargetEntity string
	// The foreign key field(s)
	FK []string
	// The label of the link
	Label string
	// If true, the link is from this entity to the target. If false,
	// the link is from the target to this.
	Forward bool
	// If true, the reference can have more than one links
	Multi bool
	// IngestAs node or edge
	IngestAs string
}

LinkSpec contains the link field information

func GetLinkSpec

func GetLinkSpec(schemaNode graph.Node) (*LinkSpec, error)

GetLinkSpec returns a link spec from the node if there is one. The node is a schema node

func (*LinkSpec) FindReference

func (spec *LinkSpec) FindReference(entityInfo map[graph.Node]EntityInfo, fk []string) ([]graph.Node, error)

FindReference finds the root nodes with entitySchema=spec.Schema, with entityId=fk

type LogLevel

type LogLevel int8
const (
	LogLevelError LogLevel = iota
	LogLevelInfo
	LogLevelDebug
)

func (LogLevel) String

func (l LogLevel) String() string

type Logger

type Logger interface {
	Debug(map[string]interface{})
	Info(map[string]interface{})
	Error(map[string]interface{})
}

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(*Layer, graph.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 NodePath

type NodePath []string

NodePath contains the name components identifying a node. For JSON, this is the components of a JSON pointer

func (NodePath) Append

func (n NodePath) Append(i interface{}) NodePath

func (NodePath) AppendInt

func (n NodePath) AppendInt(i int) NodePath

func (NodePath) AppendString

func (n NodePath) AppendString(s string) NodePath

func (NodePath) Copy

func (n NodePath) Copy() NodePath

Create a deep-copy of the nodepath

func (NodePath) String

func (n NodePath) String() string

String returns '.' combined path components

type NodeValidator

type NodeValidator interface {
	ValidateNode(docNode, layerNode graph.Node) error
}

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

type ParsedDocNode

type ParsedDocNode interface {
	GetSchemaNode() graph.Node

	// Returns value, object, array
	GetTypeTerm() string

	GetID() string

	GetValue() string
	GetValueTypes() []string

	GetAttributeIndex() int
	GetAttributeName() string

	GetChildren() []ParsedDocNode

	GetProperties() map[string]interface{}
}

type PropertyContainer

type PropertyContainer interface {
	GetProperties() map[string]*PropertyValue
}

PropertyContainer is an object that contains properties. Node and Edge are property containers

type PropertyValue

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

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

func AsPropertyValue

func AsPropertyValue(in interface{}, exists bool) *PropertyValue

func ComposeProperty

func ComposeProperty(context *Context, key string, targetValue, sourceValue *PropertyValue) (*PropertyValue, error)

ComposeProperty composes targetValue and sourceValue for key

func GetEntityIDFields

func GetEntityIDFields(node graph.Node) *PropertyValue

GetEntityIDFields returns the value of the entity ID fields from a document node.

func GetNodeOrSchemaProperty

func GetNodeOrSchemaProperty(node graph.Node, key string) (*PropertyValue, bool)

GetNodeOrSchemaProperty gets the node property with the key from the node, or from the schema nodes it is attached to

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. If the underlying value is not a string slice, returns nil

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) GetNativeValue

func (p PropertyValue) GetNativeValue() interface{}

GetNativeValue is used bythe expression evaluators to access the native value of the property

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) IsEqual

func (p *PropertyValue) IsEqual(q *PropertyValue) bool

IsEqual tests if two values are equal

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) MarshalJSON

func (p PropertyValue) MarshalJSON() ([]byte, error)

func (PropertyValue) MarshalYAML

func (p PropertyValue) MarshalYAML() (interface{}, error)

func (*PropertyValue) MustStringSlice

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

MustStringSlice returns the value as a string slice. If the underlying value is not a string slice, returns a string slice containing one element. If p is nil, returns nil

func (*PropertyValue) Slice

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

Slice returns the property value as a slice. If the property value is a string, returns a slice containing that value. If the property value is nil, returns an empty slice

func (PropertyValue) String

func (p PropertyValue) String() string

func (*PropertyValue) UnmarshalJSON

func (p *PropertyValue) UnmarshalJSON(in []byte) error

func (*PropertyValue) UnmarshalYAML

func (p *PropertyValue) UnmarshalYAML(u func(interface{}) error) error

type SchemaLoader

type SchemaLoader interface {
	LoadSchema(ref string) (*Layer, error)
}

SchemaLoader interface defines the LoadSchema method that loads schemas by reference

type SchemaLoaderFunc

type SchemaLoaderFunc func(string) (*Layer, error)

SchemaLoaderFunc is the function type that load schemas. It also implements SchemaLoader interface

func (SchemaLoaderFunc) LoadSchema

func (s SchemaLoaderFunc) LoadSchema(ref string) (*Layer, error)

type StringInterner

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

StringInterner is used to intern strings so multiple identical copies of strings are minimized

func NewInterner

func NewInterner() StringInterner

NewInterner returns a new interner

func (StringInterner) Intern

func (s StringInterner) Intern(key string) string

Intern a string and return the corresponding interned string

type TermCompiler

type TermCompiler interface {
	// CompileTerm gets a node or edge, the term and its value, and
	// compiles it. It can store compilation data in the compiled data
	// map.
	CompileTerm(CompilablePropertyContainer, string, *PropertyValue) 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 TermMarshaler

type TermMarshaler interface {
	// Unmarshal a flattened json-ld object.
	UnmarshalLd(target *Layer, key string, value interface{}, node *LDNode, allNodes map[string]*LDNode, interner Interner) error
	// Marshal a property of a node as expanded json-ld
	MarshalLd(source *Layer, sourceNode graph.Node, key string) (interface{}, error)
	UnmarshalJSON(target *Layer, key string, value interface{}, node graph.Node, interner Interner) error
}

TermMarshaler interface defines JSON and JSONLD unmarshalers for a custom schema extension

func GetTermMarshaler

func GetTermMarshaler(term string) TermMarshaler

GetTermMarshaler returns the custom marshaler for the term. If there is none, returns the default marshaler

type TermSemantics

type TermSemantics struct {
	// The term
	Term string

	Namespace string
	LName     string
	Aliases   []string

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

	// If true, the term is a list. In JSON-LD, its elements will be
	// marshaled under @list
	IsList bool

	Composition CompositionType

	Metadata interface{}
}

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 ValueAccessor

type ValueAccessor interface {
	GetNodeValue(graph.Node) (interface{}, error)
	SetNodeValue(graph.Node, interface{}) error
}

A ValueAccessor gets node values in native type, and sets node values

func GetNodeValueAccessor

func GetNodeValueAccessor(node graph.Node) (ValueAccessor, error)

GetNodeValueAccessor returns the value accessor for the node based on the node value type. If there is none, returns nil

func GetValueAccessor

func GetValueAccessor(term string) ValueAccessor

GetValueAccessor returns the value accessor for the term. If the term has none, returns nil

type ValueValidator

type ValueValidator interface {
	ValidateValue(value *string, layerNode graph.Node) error
}

A ValueValidator is used to validate a value based on a schema. The ValidateValue function is called with the value that needs to be validated, and the associated schema node. If the node does not exist, the value is nil

type ValuesetInfo

type ValuesetInfo struct {
	// If the valueset lookup requires a single value, the attribute id
	// of the source node. Otherwise, the root node containing all the
	// required values. Results of the valueset lookup will also be
	// inserted under this node. If this is empty, then the current node
	// is the context node
	ContextID string

	// Optional lookup table IDs. If omitted, all compatible tables are
	// looked up
	TableIDs []string

	// Ordered list of valueset keys. The request to the valueset
	// function will use these as the request keys
	RequestKeys []string

	// Ordered list of attribute ids containing valueset request
	// values. The elements of this match the keys array
	RequestValues []string

	// The keys of the valueset result
	ResultKeys []string

	// The attribute ids of the nodes under this node to receive values
	ResultValues []string

	// The schemanode containing the valueset info
	SchemaNode graph.Node
}

ValuesetInfo describes value set information for a schema node.

A schema node containing valueset information requests the use of a dictionary or valueset to manipulate the graph. The results of valueset lookup can be placed under new nodes of the schema node.

The valueset or dictionary lookup is envisioned as an external service. This service is called with the list of valueset ids, and a set of key:value pairs as the request. The response is another set of key:value pairs. Valueset processing adds the response to the graph.

The valueset context node specifies a node that is either the current node or one of its ancestors. All the nodes for the valueset lookup are found under this context, and valueset lookup results are added under this context node.

The valueset info may specify one or mode valuesets to lookup (TableIDs). If none specified, all compatible valuesets should be looked up.

func ValuesetInfoFromNode

func ValuesetInfoFromNode(node graph.Node) *ValuesetInfo

ValueSetInfoFromNode parses the valuese information from a node. Returns nil if the node does not have valueset info

func (*ValuesetInfo) ApplyValuesetResponse

func (vsi *ValuesetInfo) ApplyValuesetResponse(ctx *Context, builder GraphBuilder, layer *Layer, contextDocumentNode, contextSchemaNode graph.Node, result ValuesetLookupResponse) error

func (*ValuesetInfo) GetContextNode

func (vsi *ValuesetInfo) GetContextNode(docNode graph.Node) (graph.Node, error)

GetContextNode returns the context node for the given document node. The context node must be the node itself, or an ancestor of the node

func (*ValuesetInfo) GetContextNodes

func (vsi *ValuesetInfo) GetContextNodes(g graph.Graph) ([]graph.Node, error)

GetContextNodes returns the contexts node for the given document

func (*ValuesetInfo) GetDocNodes

func (vsi *ValuesetInfo) GetDocNodes(g graph.Graph) []graph.Node

GetDocNodes returns the document nodes that are instance of the vsi schema node

func (*ValuesetInfo) GetRequest

func (vsi *ValuesetInfo) GetRequest(contextDocumentNode, vsiDocumentNode graph.Node) (map[string]string, error)

GetRequest builds a valueset service request in the form of key:value pairs. All the request values are expected to be under the contextDocumentNode.

If ValuesetInfo contains no RequestValues, then the vsiDocumentNode is used as the request value. If there are RequestKeys specified, there must be only one, and that is used as the key. Otherwise, the request is prepared with empty key.

vsiDocumentNode can be nil

If ValuesetInfo contains RequestValues, the request values

type ValuesetLookupRequest

type ValuesetLookupRequest struct {
	TableIDs  []string
	KeyValues map[string]string
}

ValuesetLookupRequest specifies an optional list of lookup tables and key-value pairs to lookup. If the lookup tables list is empty, the valueset lookup should check all compatible tables. The key-values may contain a single value with empty key for simple dictionay lookups

type ValuesetLookupResponse

type ValuesetLookupResponse struct {
	KeyValues map[string]string
}

ValuesetLookupResponse returns the key-value pairs that should be inserted into the graph

type ValuesetProcessor

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

func NewValuesetProcessor

func NewValuesetProcessor(layer *Layer, lookupFunc func(*Context, ValuesetLookupRequest) (ValuesetLookupResponse, error)) ValuesetProcessor

func (*ValuesetProcessor) Process

func (prc *ValuesetProcessor) Process(ctx *Context, builder GraphBuilder, vsiDocNode, contextSchemaNode graph.Node, vsi *ValuesetInfo) error

Process processes the value set of the given context document node and the schema node containing the vsi

func (*ValuesetProcessor) ProcessByContextNode

func (prc *ValuesetProcessor) ProcessByContextNode(ctx *Context, builder GraphBuilder, contextDocNode, contextSchemaNode, vsiDocNode graph.Node, vsi *ValuesetInfo) error

ProcessByContextNode processes the value set of the given context node and the schema node containing the vsi

func (*ValuesetProcessor) ProcessGraph

func (prc *ValuesetProcessor) ProcessGraph(ctx *Context, builder GraphBuilder) error

func (*ValuesetProcessor) ProcessGraphValueset

func (prc *ValuesetProcessor) ProcessGraphValueset(ctx *Context, builder GraphBuilder, vsi *ValuesetInfo) error

Jump to

Keyboard shortcuts

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