ls

package
v1.0.0-beta8 Latest Latest
Warning

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

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

Documentation

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)

	// LayerIDTerm is the schema or overlay id
	LayerIDTerm = NewTerm(LS, "layerId", true, false, NoComposition, 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)

	BundleTerm     = NewTerm(LS, "SchemaVariant/bundle", 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)

	// 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, 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", true, 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 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 ErrNotASchemaVariant = errors.New("Not a schema variant")
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

View Source
var LookupTableElementCaseSensitiveTerm = NewTerm(LS, "lookupTable/element/caseSensitive", false, false, NoComposition, nil)
View Source
var LookupTableElementErrorTerm = NewTerm(LS, "lookupTable/element/error", false, false, NoComposition, nil)
View Source
var LookupTableElementOptionsTerm = NewTerm(LS, "lookupTable/element/options", false, false, NoComposition, nil)
View Source
var LookupTableElementValueTerm = NewTerm(LS, "lookupTable/element/value", false, false, NoComposition, nil)
View Source
var LookupTableElementsTerm = NewTerm(LS, "lookupTable/elements", false, true, NoComposition, nil)
View Source
var LookupTableReferenceTerm = NewTerm(LS, "lookupTable/ref", true, false, NoComposition, nil)

LookupTableReferenceTerm is used as a node type for nodes whose lookup table references are not resolved. These nodes should be resolved to real lookup tables during compilation

View Source
var LookupTableTerm = NewTerm(LS, "lookupTable", false, false, OverrideComposition, struct {
	lookupTableMarshaler
}{
	lookupTableMarshaler{},
})

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

View Source
var RawInputValueTerm = NewTerm(LS, "rawValue", false, false, NoComposition, nil)

RawInputValueTerm keeps the raw input value if the value is processed using a lookup table

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 DefaultNodeIDGenerator

func DefaultNodeIDGenerator(path NodePath, schemaNode graph.Node) string

DefaultNodeIDGenerator returns Ingester.Schema.ID + join(path,".")

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 FindNodeByID

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

func FollowEdgesToNodeWithType

func FollowEdgesToNodeWithType(typ string) func(graph.Edge, []graph.Node) 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 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 GetEntityRootNodes

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

GetEntityRootNodes returns all the nodes that are entity roots

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) (map[string][]graph.Node, error)

GetObjectAttributeNodes returns the schema attribute nodes under a schema object. The returned map is keyed by the AttributeNameTerm

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 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 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 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 skiip the edge, follow it, or stop processing.

func IterateDescendants

func IterateDescendants(from graph.Node, nodeFunc func(graph.Node, []graph.Node) bool, edgeFunc func(graph.Edge, []graph.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 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 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 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 MarshalSchemaVariant

func MarshalSchemaVariant(variant *SchemaVariant) interface{}

MarshalSchemaVariant returns a compact jsonld document for the variant

func NewDocumentGraph

func NewDocumentGraph() graph.Graph

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

func NewTerm

func NewTerm(ns, lname string, isID, isList bool, comp CompositionType, md interface{}) 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

Types

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
	GetLayerNodes(string) []graph.Node
	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 func(ref string) (*Layer, error)
	// CGraph keeps the compiled interlinked schemas. If this is
	// initalized 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

func (*Compiler) RecompileSchema

func (compiler *Compiler) RecompileSchema(context *Context, schema *Layer) (*Layer, error)

RecompileSchema uses the cache to resolve the references of the schema, but does not put the schema back into the cache

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

func (d *DefaultCompiledGraph) GetLayerNodes(ref string) []graph.Node

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 tje 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, _ []graph.Node) 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

type ErrAmbiguousLookup

type ErrAmbiguousLookup struct {
	Msg string
}

func (ErrAmbiguousLookup) Error

func (e ErrAmbiguousLookup) Error() string

type ErrCannotDetermineEdgeLabel

type ErrCannotDetermineEdgeLabel struct {
	Msg  string
	Path NodePath
}

func (ErrCannotDetermineEdgeLabel) Error

type ErrCannotDeterminePropertyName

type ErrCannotDeterminePropertyName struct {
	Path NodePath
}

func (ErrCannotDeterminePropertyName) Error

type ErrCannotFindAncestor

type ErrCannotFindAncestor struct {
	Path NodePath
}

func (ErrCannotFindAncestor) Error

func (e ErrCannotFindAncestor) Error() string
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 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 ErrInputValueNotFoundInLookup

type ErrInputValueNotFoundInLookup struct {
	Msg string
}

func (ErrInputValueNotFoundInLookup) Error

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 ErrInvalidLookupTable

type ErrInvalidLookupTable struct {
	ID  string
	Msg string
}

func (ErrInvalidLookupTable) Error

func (e ErrInvalidLookupTable) 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 ErrLookupTableError

type ErrLookupTableError struct {
	Errors []string
}

func (ErrLookupTableError) Error

func (e ErrLookupTableError) 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
	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 Ingester

type Ingester struct {
	// The schema variant to use during ingestion
	Schema *Layer

	// 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

	// IngestEmptyValues is true if the value to ingest contains data, otherwise default to false
	IngestEmptyValues bool

	ExternalLookup func(lookupTableID string, dataNode graph.Node) (LookupResult, error)

	// SchemaNodeMap is used to keep a mapping of schema nodes copied into the
	// target graph. The key is a schema node. The value is the node in
	// target graph.
	SchemaNodeMap map[graph.Node]graph.Node

	// The target graph
	Graph graph.Graph
}

Ingester keeps the schema and the ingestion options

func (*Ingester) Array

func (ingester *Ingester) Array(ictx IngestionContext, types ...string) (string, graph.Edge, graph.Node, error)

Array ingests an array as a node or edge

func (*Ingester) ArrayAsEdge

func (ingester *Ingester) ArrayAsEdge(ictx IngestionContext, types ...string) (graph.Edge, error)

func (*Ingester) ArrayAsNode

func (ingester *Ingester) ArrayAsNode(ictx IngestionContext, types ...string) (graph.Edge, graph.Node, error)

func (*Ingester) EmbedSchemaNode

func (ingester *Ingester) EmbedSchemaNode(targetNode, schemaNode graph.Node)

EmbedSchemaNode merges the schema node properties with the target node properties. No properties are overwritten in the target node. The schema node types that are not schema node types are also merged with the target node types.

func (*Ingester) Finish

func (ingester *Ingester) Finish(ictx IngestionContext, root graph.Node) error

Finish ingesting by assigning node IDs and linking nodes to their entity root nodes. If generateIDFunc is nil, the default ID generation function is used

func (ingester *Ingester) Link(ictx IngestionContext, spec *LinkSpec, docNode, parentNode graph.Node, entityInfo map[graph.Node]EntityInfo) error

Link the given node, or create a link from the parent node as the docNode may not exist.

func (*Ingester) NewNode

func (ingester *Ingester) NewNode(ictx IngestionContext) graph.Node

NewNode creates a new graph node, either by using the NewNodeFunc or by creating a new node using DefaultNodeIDGenerator. Then it either merges schema properties into the new node, or creates an instanceOf edge to the schema node.

func (*Ingester) Object

func (ingester *Ingester) Object(ictx IngestionContext, types ...string) (string, graph.Edge, graph.Node, error)

Object ingests an object as a node or edge

func (*Ingester) ObjectAsEdge

func (ingester *Ingester) ObjectAsEdge(ictx IngestionContext, types ...string) (graph.Edge, error)

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

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

func (*Ingester) ObjectAsNode

func (ingester *Ingester) ObjectAsNode(ictx IngestionContext, types ...string) (graph.Edge, graph.Node, error)

ObjectAsNode creates a new object node

func (*Ingester) Polymorphic

func (ingester *Ingester) Polymorphic(ictx IngestionContext, ingest func(*Ingester, IngestionContext) (graph.Node, error)) (graph.Node, error)

Polymorphic tests all options in the schema by calling ingest func

func (*Ingester) Start

func (ingester *Ingester) Start(context *Context, baseID string) IngestionContext

Start ingestion. Returns the path initialized with the baseId, and the schema root.

func (*Ingester) Validate

func (ingester *Ingester) Validate(ictx IngestionContext, documentNode graph.Node) error

Validate the document node with the schema node

func (*Ingester) Value

func (ingester *Ingester) Value(ictx IngestionContext, value string, types ...string) (string, graph.Edge, graph.Node, error)

Value ingests a value as a node, edge-node, or as a property depending on the schema. The default is ingestion as node. Returns the node, and optionally, the edge going to that node

func (*Ingester) ValueAsEdge

func (ingester *Ingester) ValueAsEdge(ictx IngestionContext, 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 (*Ingester) ValueAsNode

func (ingester *Ingester) ValueAsNode(ictx IngestionContext, 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 (*Ingester) ValueAsProperty

func (ingester *Ingester) ValueAsProperty(ictx IngestionContext, value string) error

ValueAsProperty ingests a value as a property of an ancestor node

type IngestionContext

type IngestionContext struct {
	*Context
	// SourcePath is the path in the input document that is being
	// ingested. This is mainly useful for diagnostic messages as it
	// shows which field is being processed
	SourcePath NodePath
	// GraphPath is the path in the target graph. At any given point,
	// the last element of GraphPath gives the parent element
	GraphPath []graph.Node
	// SchemaPath is the path to the current schema node. Elements can be nil
	SchemaPath []graph.Node
}

IngestionContext keeps the ingestion state

func (IngestionContext) GetEntityRootNode

func (ctx IngestionContext) GetEntityRootNode() graph.Node

GetEntityRootNode returns the root node of the current entity. Returns nil if it cannot be determined.

func (IngestionContext) GetParentNode

func (ctx IngestionContext) GetParentNode() graph.Node

GetParentNode returns the last element of the graph path

func (IngestionContext) GetSchemaNode

func (ctx IngestionContext) GetSchemaNode() graph.Node

GetSchemaNode returns the current schema node

func (IngestionContext) New

func (ctx IngestionContext) New(key interface{}, schemaNode graph.Node) IngestionContext

New returns a new ingestion context that is a copy of the original with one more level added

func (IngestionContext) NewLevel

func (ctx IngestionContext) NewLevel(docNode graph.Node) IngestionContext

NewLevel return a new context with a new document node in graph path

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 (*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 NewLayer

func NewLayer() *Layer

NewLayer returns a new empty layer

func NewLayerFromGraph

func NewLayerFromGraph(g graph.Graph) *Layer

NewLayerFromGraph uses the graph to create a layer. The root node of the graph becomes the schema root, if there is one

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

func (*Layer) CloneInto

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

CloneInto clones the layer into the targetgraph

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

GetPath 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) GetSchemaRootNode

func (l *Layer) GetSchemaRootNode() graph.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) RenameBlankNodes

func (l *Layer) RenameBlankNodes(namer func(graph.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, 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 LookupProcessor

type LookupProcessor struct {
	Graph graph.Graph

	ExternalLookup func(lookupTableID string, dataNode graph.Node) (LookupResult, error)
}

LookupProcessor keeps the lookup configuration and provides the methods to evaulate lookup annotations

func (*LookupProcessor) ProcessLookup

func (prc *LookupProcessor) ProcessLookup(node graph.Node) error

ProcessLookup will process the lookup annotations on the node. If the node has none, this will not do anything

type LookupResult

type LookupResult struct {
	// Matched is true if the lookup value matched something in the lookup table
	Matched bool
	// If true, the value did not match anything and the returned value
	// is the default value
	DefaultValue bool
	// This is the value returned if Matched==true
	Value string
	// This is nonempty if an error must be returned
	Error string
}

type LookupTable

type LookupTable struct {
	// Lookup table ID
	ID       string               `json:"id"`
	Ref      string               `json:"ref"`
	Elements []LookupTableElement `json:"elements"`
}

LookupTable is the JSON representation of a lookup table containing the ID and elements

type LookupTableElement

type LookupTableElement struct {
	// Possible values the data point can take. If empty, this is the default option
	Options []string `json:"options"`
	// If the options are to be compared case sensitive
	CaseSensitive bool `json:"caseSensitive"`
	// This is the value that has to be returned for the field if options match, or if this is the default
	Value string `json:"value"`
	// If set, data ingestion/set/get must fail with this error
	Error string `json:"error"`
}

LookupTableElement is the JSON schema representation of a lookup table item. It is also the JSON-LD representation under the ls:/lookupTable/element namespace

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 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 SchemaVariant

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

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

func UnmarshalSchemaVariant

func UnmarshalSchemaVariant(in interface{}) (*SchemaVariant, error)

Unmarshals the given jsonld document into a schema variant

func (*SchemaVariant) GetID

func (m *SchemaVariant) GetID() string

GetID returns the schema variant ID

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

	// 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 Validator

type Validator interface {
	Validate(docNode, layerNode graph.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 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

Jump to

Keyboard shortcuts

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