ls

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: Apache-2.0 Imports: 26 Imported by: 3

Documentation

Index

Constants

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

IngestAs constants

View Source
const (
	// SchemaElementTag means that the term is used for schema definitions only
	SchemaElementTag = "schemaElement"

	// ProvenanceTag means that the term is provenance related
	ProvenanceTag = "provenance"

	// ValidationTag means that the tag is about validation
	ValidationTag = "validation"
)

Known tags for term semantics

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 (
	// ReferenceFK specifies the foreign key value
	ReferenceFK = NewTerm(LS+"Reference/", "fkValue").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
	// ReferenceFKFor is used for value nodes that are foreign keys
	ReferenceFKFor = NewTerm(LS+"Reference/", "fkFor").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
	// ReferenceFKTerm specifies the foreign key attribute ID
	ReferenceFKTerm = NewTerm(LS+"Reference/", "fk").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// ReferenceLabelTerm specifies the edge label between the referenced nodes
	ReferenceLabelTerm = NewTerm(LS+"Reference/", "label").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// ReferenceDirectionTerm specifies the direction of the edge. If
	// "to" or "toTarget", the edge points to the target entity.
	// If "from" or "fromTarget", the edge points
	// to this entity.
	ReferenceDirectionTerm = NewTerm(LS+"Reference/", "dir").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// ReferenceLinkNodeTerm specifies the node in the current entity
	// that will be linked to the other entity. If the references are
	// defined in a Reference type node, then the node itself if the
	// link. Otherwise, this gives the node that must be linked to the
	// other entity.
	ReferenceLinkNodeTerm = NewTerm(LS+"Reference/", "linkNode").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// ReferenceMultiTerm specifies if there can be more than one link targets
	ReferenceMultiTerm = NewTerm(LS+"Reference/", "multi").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
)
View Source
var (
	// SchemaTerm is the layer type for schemas
	SchemaTerm = NewTerm(LS, "Schema").SetComposition(NoComposition).SetTags(SchemaElementTag).Register()

	// OverlayTerm is the layer type for overlays
	OverlayTerm = NewTerm(LS, "Overlay").SetComposition(NoComposition).SetTags(SchemaElementTag).Register()

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

	// 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").SetList(true).SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// NSMapTerm specifies a namespace map for an overlay. A Namespace
	// map includes one or more expressions of the form:
	//
	//    from -> to
	//
	// where from and to are attribute id prefixes. All the prefixes of
	// attributes that match from are converted to to.
	//
	// This is necessary when a different variants of a schema is used in
	// a complex schema. Each variant gets its own namespace.
	NSMapTerm = NewTerm(LS, "nsMap").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// CharacterEncodingTerm is used to specify a character encoding for
	// the data processed with the layer
	CharacterEncodingTerm = NewTerm(LS, "characterEncoding").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// InstanceOfTerm is an edge term that is used to connect values with
	// their schema specifications
	InstanceOfTerm = NewTerm(LS, "instanceOf").SetComposition(ErrorComposition).Register()

	// SchemaNodeIDTerm denotes the schema node ID for ingested nodes
	SchemaNodeIDTerm = NewTerm(LS, "schemaNodeId").SetComposition(ErrorComposition).SetTags(SchemaElementTag).Register()

	// SchemaVariantTerm is the schema variant type
	SchemaVariantTerm = NewTerm(LS, "SchemaVariant").SetComposition(NoComposition).SetTags(SchemaElementTag).Register()

	// DescriptionTerm is used for comments/descriptions
	DescriptionTerm = NewTerm(LS, "description").SetComposition(SetComposition).SetTags(SchemaElementTag).Register()

	// AttributeNameTerm represents the name of an attribute
	AttributeNameTerm = NewTerm(LS, "attributeName").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// AttributeIndexTerm represents the index of an array element
	AttributeIndexTerm = NewTerm(LS, "attributeIndex").SetComposition(NoComposition).SetTags(SchemaElementTag).Register()

	// ConditionalTerm specifies conditions for ingestion
	ConditionalTerm = NewTerm(LS, "conditional").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// LayerRootTerm is an edge term that connects layer node to the root node of the schema
	LayerRootTerm = NewTerm(LS, "layer").SetComposition(ErrorComposition).SetTags(SchemaElementTag).Register()

	// DefaultValueTerm is the default value for an attribute if attribute is not present
	DefaultValueTerm = NewTerm(LS, "defaultValue").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

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

	// NodeIDTerm keeps the node ID or the attribute ID
	NodeIDTerm = NewTerm(LS, "nodeId").SetComposition(ErrorComposition).SetTags(SchemaElementTag).Register()

	// IngestAsTerm ingests value as an edge, node, or property
	IngestAsTerm = NewTerm(LS, "ingestAs").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// 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").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// EdgeLabelTerm represents the value used as an edge label, when ingesting an edge
	EdgeLabelTerm = NewTerm(LS, "edgeLabel").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// OutputEdgeLabelTerm determines the labels of the output edges
	OutputEdgeLabelTerm = NewTerm(LS, "outputEdgeLabel").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// PropertyNameTerm represents the value used as a property name when ingesting a property
	PropertyNameTerm = NewTerm(LS, "propertyName").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// DocumentNodeTerm is the type of document nodes
	DocumentNodeTerm = NewTerm(LS, "DocumentNode").SetComposition(ErrorComposition).Register()

	// NodeValueTerm is the property key used to keep node value
	NodeValueTerm = NewTerm(LS, "value").SetComposition(ErrorComposition).Register()

	// ValueTypeTerm defines the type of a value
	ValueTypeTerm = NewTerm(LS, "valueType").SetComposition(OverrideComposition).Register()

	// HasTerm is an edge term for linking document elements
	HasTerm = NewTerm(LS, "has").SetComposition(ErrorComposition).Register()

	// 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").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// 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").SetComposition(OverrideComposition).Register()

	// LabeledAsTerm adds labels to JSON schemas
	LabeledAsTerm = NewTerm(LS, "labeledAs").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// TypeDiscriminatorTerm represents a set of schema field hints for defining polymorphic objects
	TypeDiscriminatorTerm = NewTerm(LS, "typeDiscriminator").SetComposition(NoComposition).SetTags(SchemaElementTag).Register()

	// IncludeSchemaTerm represents another schema to replace and copy its contents
	IncludeSchemaTerm = NewTerm(LS, "include").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// Namespace defines the namespace prefix
	NamespaceTerm = NewTerm(LS, "namespace").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// SourceTerm gives the source information for the data element
	SourceTerm = NewTerm(LS, "provenance/source").SetComposition(OverrideComposition).SetTags(ProvenanceTag).Register()
)
View Source
var (
	AttributeTypeValue       = NewTerm(LS, "Value").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
	AttributeTypeObject      = NewTerm(LS, "Object").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
	AttributeTypeArray       = NewTerm(LS, "Array").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
	AttributeTypeReference   = NewTerm(LS, "Reference").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
	AttributeTypeComposite   = NewTerm(LS, "Composite").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
	AttributeTypePolymorphic = NewTerm(LS, "Polymorphic").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
	AttributeNodeTerm        = NewTerm(LS, "Attribute").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
)

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

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
	//
	// If context is empty, entity root is assumed
	ValuesetContextTerm = NewTerm(LS, "vs/context").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
	// ValuesetContextExprTerm is an opencyper expression that gives the context node using "this" as the current node
	ValuesetContextExprTerm = NewTerm(LS, "vs/contextExpr").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// 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").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// 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").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

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

	// ValuesetRequestTerm specifies one or more openCypher expressions
	// that builds up a valuest lookup request. The named results of
	// those expressions are added to the request key/value pairs
	ValuesetRequestTerm = NewTerm(LS, "vs/request").SetComposition(OverrideComposition).SetTags(SchemaElementTag).SetMetadata(CompileOCSemantics{}).Register()

	// 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").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// ValuesetResultValuesTerm specifies the schema node IDs for the
	// nodes that will receive the matching key values. If there is only
	// one, resultKeys is optional The result value nodes must be a
	// direct descendant of one of the nodes from the document node up
	// to the context node.
	ValuesetResultValuesTerm = NewTerm(LS, "vs/resultValues").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()

	// ValuesetResultContext determines the node under which the results
	// will be added. This is needed if the results will be added under
	// a different entity attached to the valueset context.
	ValuesetResultContextTerm = NewTerm(LS, "vs/resultContext").SetComposition(OverrideComposition).SetTags(SchemaElementTag).Register()
)
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 HashSHA1Term = NewTerm(LS, "hash.sha1").SetComposition(OverrideComposition).SetMetadata(hashSemantics{}).SetTags(SchemaElementTag).Register()
View Source
var HashSHA256Term = NewTerm(LS, "hash.sha256").SetComposition(OverrideComposition).SetMetadata(hashSemantics{}).SetTags(SchemaElementTag).Register()
View Source
var HashSHA512Term = NewTerm(LS, "hash.sha512").SetComposition(OverrideComposition).SetMetadata(hashSemantics{}).SetTags(SchemaElementTag).Register()
View Source
var HashTerm = NewTerm(LS, "hash").SetComposition(OverrideComposition).SetMetadata(hashSemantics{}).SetTags(SchemaElementTag).Register()
View Source
var IncludeAllNodesInSliceFunc = func(layer *Layer, nd *lpg.Node) *lpg.Node {
	return CloneNode(nd, layer.Graph)
}

IncludeAllNodesInSliceFunc includes all the nodes in the slice

OnlyAttributeNodes can be used in IterateDescendants edge func to follow edges that reach to Attribute nodes

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

View Source
var SetValueTerm = NewTerm(LS, "setValue").SetComposition(OverrideComposition).SetMetadata(setValueSemantics{}).SetTags(SchemaElementTag).Register()

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

View Source
var UUIDTerm = NewTerm(LS, "uuid").SetComposition(OverrideComposition).SetTags(SchemaElementTag).SetMetadata(uuidSemantics{}).Register()

Functions

func CloneEdge

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

func CloneNode

func CloneNode(sourceNode *lpg.Node, targetGraph *lpg.Graph) *lpg.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 []*lpg.Node) lpg.StringSet

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

func CompileGraphNodeTerms

func CompileGraphNodeTerms(g *lpg.Graph) error

CompileGraphNodeTerms compiles all node terms of the graph

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 *lpg.Node) error

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

func ConsolidateDuplicateEntities

func ConsolidateDuplicateEntities(g *lpg.Graph, label string)

ConsolidateDuplicateEntities finds all nodes that have identical nonempty entityId with the given label, and merges those that share labels

func CopyGraph

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

CopyGraph source to target using the optional node/edge selectors. Return a node map from the in to target nodes

func CopyGraphWithCloneFunc

func CopyGraphWithCloneFunc(target, source *lpg.Graph, nodeCloner func(*lpg.Node, *lpg.Graph) *lpg.Node, edgeCloner func(*lpg.Edge, map[*lpg.Node]*lpg.Node, *lpg.Graph) *lpg.Edge) map[*lpg.Node]*lpg.Node

CopyGraphWithCloneFunc source to target using the optional node/edge cloners. 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 *lpg.Graph, schemaNode *lpg.Node) *lpg.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 ...*lpg.Node) []*lpg.Node

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

func EnsurePath

func EnsurePath(rootDocNode, ancestorDocNode *lpg.Node, rootSchemaNode, schemaNode *lpg.Node, instantiate func(parentDocNode, schemaNode *lpg.Node) (*lpg.Node, error)) (*lpg.Node, error)

EnsurePath finds or instantiates a path in the graph. The path will start at rootDocNode, which is an instance of rootSchemaNode, will pass through ancestorDocNode if ancestorDocNode is not nil, and will be an instance of schemaNode. Each node will be created using the instantiate func that takes the parent document node, and the schema node to instantiate.

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 *lpg.Node, childAttrID string) []*lpg.Node

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

func FindFirstChildIf

func FindFirstChildIf(parent *lpg.Node, pred func(*lpg.Node) bool) *lpg.Node

FindFirstChildIf returns the first child node for which the predicate returns true

func FindNodeByID

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

func FollowEdgesToNodeWithType

func FollowEdgesToNodeWithType(typ string) func(*lpg.Edge) EdgeFuncResult

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

func ForEachAttributeNode

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

func FormatNodeValue(node *lpg.Node) (string, error)

FormatNodeValue formats the node value as string

func GetArrayElementNode

func GetArrayElementNode(arraySchemaNode *lpg.Node) *lpg.Node

GetArrayElementNode returns the array element node from an array node

func GetAttributeID

func GetAttributeID(node *lpg.Node) string

GetAttributeID returns the attributeID

func GetAttributePath

func GetAttributePath(root, node *lpg.Node) []*lpg.Node

GetAttributePath returns the path from root to node. There must exist exactly one path. If not, returns nil

func GetAttributeValidator

func GetAttributeValidator(term string) (NodeValidator, ValueValidator)

GetAttributeValidator returns a validator implementation for the given validation term

func GetEntityInfo

func GetEntityInfo(g *lpg.Graph) map[*lpg.Node]EntityInfo

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

Deprecated

func GetEntityRoot

func GetEntityRoot(node *lpg.Node) *lpg.Node

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

func GetEntityRootNode

func GetEntityRootNode(aNode *lpg.Node) *lpg.Node

GetEntityRootNode returns the entity root node containing this node

func GetEntityRootsByID

func GetEntityRootsByID(g *lpg.Graph) map[*lpg.Node]EntityInfo

GetEntityRootsByID returns all nodes that have entity id

func GetIngestAs

func GetIngestAs(schemaNode *lpg.Node) string

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

func GetIngestAsProperty

func GetIngestAsProperty(schemaNode *lpg.Node) (asPropertyOf, propertyName string)

func GetLayerEntityRoot

func GetLayerEntityRoot(node *lpg.Node) *lpg.Node

GetLayerEntityRoot returns the layer entity root node containing the given schema node

func GetNSMap

func GetNSMap(in []string) ([][]string, error)

GetNSMap parses the namespace map and returns the mapping

func GetNodeID

func GetNodeID(node *lpg.Node) string

GetNodeID returns the nodeid

func GetNodeIndex

func GetNodeIndex(node *lpg.Node) int

GetNodeIndex returns the value of attribute index term as int

func GetNodeSchemaNodeID

func GetNodeSchemaNodeID(documentNode *lpg.Node) string

GetNodeSchemaNodeID returns the schema node ID of a document node. Returns empty string if not found.

func GetNodeValue

func GetNodeValue(node *lpg.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 *lpg.Graph, attrId string) []*lpg.Node

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

func GetNodesWithValidators

func GetNodesWithValidators(root *lpg.Node) map[*lpg.Node]struct{}

GetNodesWithValidators returns all nodes under root that has validators

func GetObjectAttributeNodes

func GetObjectAttributeNodes(objectSchemaNode *lpg.Node) []*lpg.Node

GetObjectAttributeNodes returns the schema attribute nodes under a schema object.

func GetObjectAttributeNodesBy

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

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

func GetOutputEdgeLabel

func GetOutputEdgeLabel(parentNode *lpg.Node) string

GetOutputEdgeLabel returns the label that should be used to connect child nodes. This is determined by the outputEdgeLabel term. ParentNode is either a schema node or a doc node

func GetParentAttribute

func GetParentAttribute(node *lpg.Node) *lpg.Node

GetParentAttribute returns the parent attribute of the given node

func GetParentDocumentNodes

func GetParentDocumentNodes(node *lpg.Node) []*lpg.Node

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

func GetPathFromRoot

func GetPathFromRoot(schemaNode *lpg.Node) []*lpg.Node

GetPathFromEntityRoot returns the path from the entity root node of the schema

func GetPolymorphicOptions

func GetPolymorphicOptions(polymorphicSchemaNode *lpg.Node) []*lpg.Node

GetPolymorphicOptions returns the polymorphic options of a schema node

func GetRawNodeValue

func GetRawNodeValue(node *lpg.Node) (string, bool)

GetRawNodeValue returns the unprocessed node value

func GetSchemaNodeIDMap

func GetSchemaNodeIDMap(docRoot *lpg.Node) map[string][]*lpg.Node

GetSchemaNodeIDMap returns a map of schema node IDs to slices of nodes that are instances of those schema nodes

func GetSliceByTermsFunc

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

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

func InstantiateSchemaNode

func InstantiateSchemaNode(targetGraph *lpg.Graph, schemaNode *lpg.Node, embedSchemaNodes bool, schemaNodeMap map[*lpg.Node]*lpg.Node) *lpg.Node

InstantiateSchemaNode creates a new node in targetGraph that is an instance of the given schemaNode. If embedSchemaNodes is true, the properties of the schema node will be embedded into the new schema node. If embedSchemaNodes is false, schema nodes will be kept separate. The schemaNodeMap will be filled with the map of schema nodes copied into the target graph. The key will be the original schema node, and the value will be the copied schema node in targetGraph. Returns the new node.

func InternSlice

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

InternSlice interns all elements of a slice

func IsAttributeNode

func IsAttributeNode(node *lpg.Node) bool

IsAttributeNode returns true if the node has Attribute type

func IsAttributeTreeEdge

func IsAttributeTreeEdge(edge *lpg.Edge) bool

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

func IsAttributeType

func IsAttributeType(typeName string) bool

IsAttributeType returns true if the term is one of the attribute types

func IsCompilationArtifact

func IsCompilationArtifact(edge *lpg.Edge) bool

IsCompilationArtifact returns true if the edge is a compilation artifact

func IsDocumentEdge

func IsDocumentEdge(edge *lpg.Edge) bool

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

func IsDocumentNode

func IsDocumentNode(node *lpg.Node) bool

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

func IsEntityRoot

func IsEntityRoot(node *lpg.Node) bool

IsEntityRoot returns true if the node is an entity root

func IsInstanceOf

func IsInstanceOf(n *lpg.Node, schemaNodeID string) bool

IsInstanceOf returns true if g is an instance of the schema node

func IsNodeEntityRoot

func IsNodeEntityRoot(node *lpg.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 IsTermRegistered

func IsTermRegistered(term string) bool

func IterateAncestors

func IterateAncestors(root *lpg.Node, nodeFunc func(*lpg.Node) bool, edgeFunc func(*lpg.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 *lpg.Node, nodeFunc func(*lpg.Node) bool, edgeFunc func(*lpg.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 IterateDescendantsp

func IterateDescendantsp(from *lpg.Node, nodeFunc func(*lpg.Node, []*lpg.Node) bool, edgeFunc func(*lpg.Edge) EdgeFuncResult, ordered bool, visitSeenNodes bool) bool

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() *lpg.Graph

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

func NewEvalContext

func NewEvalContext(g *lpg.Graph) *opencypher.EvalContext

func NewLayerGraph

func NewLayerGraph() *lpg.Graph

NewLayerGraph creates a new graph indexes to store layers

func ParseNSMap

func ParseNSMap(in string) (string, string, error)

ParseNSMap parses a string pair of the form

string1 -> string2

This is used in nsMap expression to specify namespace (prefix) mapping for node ids.

func ProcessLabeledAs

func ProcessLabeledAs(graph *lpg.Graph)

func PropertiesAsMap

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

func PropertyValueFromNative

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

func RegisterNewDocGraphHook

func RegisterNewDocGraphHook(f func(*lpg.Graph))

func RegisterNewLayerGraphHook

func RegisterNewLayerGraphHook(f func(*lpg.Graph))

func RegisterTerm

func RegisterTerm(t TermSemantics)

func RemoveRawNodeValue

func RemoveRawNodeValue(node *lpg.Node)

func RunTestsFromFile

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

func SameTerm

func SameTerm(term1, term2 string) bool

SameTerm returns true if term1 is an alias of term2 or vice versa

func SetAttributeID

func SetAttributeID(node *lpg.Node, ID string)

SetAttrributeID sets the attribute ID

func SetEntityIDVectorElement

func SetEntityIDVectorElement(entityRootNode *lpg.Node, schemaNodeID, value string) error

SetEntityIDVectorElement sets the entity Id component of the entity root node if the schema node is part of an entity id

func SetEntityIDVectorElementFromNode

func SetEntityIDVectorElementFromNode(docNode *lpg.Node, value string) error

SetEntityIDVectorElementFromNode sets the entity Id component of the entity root node if the schema node is part of an entity id. The schema node ID and entity root node are found based on the given node

func SetNodeID

func SetNodeID(node *lpg.Node, ID string)

SetNodeID sets the node ID

func SetNodeIndex

func SetNodeIndex(node *lpg.Node, index int)

func SetNodeValue

func SetNodeValue(node *lpg.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 *lpg.Node, value string)

SetRawNodeValue sets the unprocessed node value

func SkipEdgesToNodeWithType

func SkipEdgesToNodeWithType(typ string) func(*lpg.Edge) EdgeFuncResult

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

func SortEdges

func SortEdges(edges []*lpg.Edge) []*lpg.Edge

SortEdges sorts edges by their target node index

func SortEdgesItr

func SortEdgesItr(edges lpg.EdgeIterator) lpg.EdgeIterator

SortEdgesItr sorts the edges by index

func SortNodes

func SortNodes(nodes []*lpg.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 *lpg.Graph, interner Interner) error

UnmarshalJSONLDGraph Unmarshals a graph in JSON-LD format

func ValidateDocumentNode

func ValidateDocumentNode(node *lpg.Node) error

ValidateDocumentNode runs the validators for the document node

func ValidateDocumentNodeBySchema

func ValidateDocumentNodeBySchema(node, schemaNode *lpg.Node) error

ValidateDocumentNodeBySchema runs the validators for the document node

func ValidateValueBySchema

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

ValidateValueBySchema runs the validators for the value

func WalkNodesInEntity

func WalkNodesInEntity(aNode *lpg.Node, f func(*lpg.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 AttributeReference

type AttributeReference struct {
	Node     *lpg.Node
	Property string
}

AttributeReference points to an attribute in a document. The attribute can be a node, or a property of a node

func GetAttributeReferenceBySchemaNode

func GetAttributeReferenceBySchemaNode(schemaRootNode, schemaNode *lpg.Node, docContextNode *lpg.Node) (AttributeReference, bool)

GetAttributeReferenceBySchemaNode returns the attribute reference whose instance is under docContextNode

func GetAttributeReferenceBySchemaPath

func GetAttributeReferenceBySchemaPath(schemaPath []*lpg.Node, docContextNode *lpg.Node) (AttributeReference, bool)

func (AttributeReference) AsPropertyValue

func (a AttributeReference) AsPropertyValue() *PropertyValue

func (AttributeReference) IsProperty

func (a AttributeReference) IsProperty() bool

type BasicParsedDocNode

type BasicParsedDocNode struct {
	SchemaNode     *lpg.Node
	TypeTerm       string
	ID             string
	Value          string
	ValueTypes     []string
	AttributeIndex int
	AttributeName  string
	Children       []ParsedDocNode
	Properties     map[string]interface{}
}

BasicParsedDocNode is the default implementation of a parsed doc node

func (*BasicParsedDocNode) GetAttributeIndex

func (b *BasicParsedDocNode) GetAttributeIndex() int

func (*BasicParsedDocNode) GetAttributeName

func (b *BasicParsedDocNode) GetAttributeName() string

func (*BasicParsedDocNode) GetChildren

func (b *BasicParsedDocNode) GetChildren() []ParsedDocNode

func (*BasicParsedDocNode) GetID

func (b *BasicParsedDocNode) GetID() string

func (*BasicParsedDocNode) GetProperties

func (b *BasicParsedDocNode) GetProperties() map[string]interface{}

func (*BasicParsedDocNode) GetSchemaNode

func (b *BasicParsedDocNode) GetSchemaNode() *lpg.Node

func (*BasicParsedDocNode) GetTypeTerm

func (b *BasicParsedDocNode) GetTypeTerm() string

func (*BasicParsedDocNode) GetValue

func (b *BasicParsedDocNode) GetValue() string

func (*BasicParsedDocNode) GetValueTypes

func (b *BasicParsedDocNode) GetValueTypes() []string

type CompilablePropertyContainer

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

CompilablePropertyContainer contains properties and a compiled data map

type CompileContext

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

An instance of CompileContext is passed to all compile functions. It contains a statement cache to prevent recompiling same statemement multiple times

func (*CompileContext) CompileOpencypher

func (c *CompileContext) CompileOpencypher(statement string) (opencypher.Evaluatable, error)

func (*CompileContext) GetCompiledStatement

func (c *CompileContext) GetCompiledStatement(statement any) (any, bool)

GetCompiledStatement returns the compiled statement if any

func (*CompileContext) SetCompiledStatement

func (c *CompileContext) SetCompiledStatement(statement, compiled any)

SetCompiledStatement sets a compiled statement

type CompileOCSemantics

type CompileOCSemantics struct{}

CompileOCSemantics is a compilation implementation for terms containing a slice of opencypher expressions. It compiles one or more expressions of the term, and places them im $compiled_term property.

func (CompileOCSemantics) CompileTerm

func (CompileOCSemantics) Compiled

func (CompileOCSemantics) Evaluate

Evaluate all compiled expressions and return nonempty resultsets.

type CompiledGraph

type CompiledGraph interface {
	GetCompiledSchema(string) *Layer
	PutCompiledSchema(*Context, string, *Layer) (*Layer, error)
	GetGraph() *lpg.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 GetComposerForProperty

func GetComposerForProperty(p *PropertyValue) Composer

GetComposerForProperty returns the composer for the given property. Never returns nil

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 {
	context.Context
	// contains filtered or unexported fields
}

func DefaultContext

func DefaultContext() *Context

func NewContext

func NewContext(ctx context.Context) *Context

func (*Context) Get

func (ctx *Context) Get(key interface{}) interface{}

func (*Context) GetInterner

func (ctx *Context) GetInterner() Interner

func (*Context) GetLogger

func (ctx *Context) GetLogger() Logger

func (*Context) Set

func (ctx *Context) Set(key, value interface{})

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() *lpg.Graph

func (*DefaultCompiledGraph) PutCompiledSchema

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

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 DialectValue

type DialectValue struct {
	Dialect string
	Value   any
}

type DialectValueSemantics

type DialectValueSemantics struct{}

DialectValueSemantics is a compilation implementation for terms containing an expression, or value. The property is expected to be:

dialect: value

For example:

opencypher:  expr

is an expression

literal: value

is a literal

Anything else is error

func (DialectValueSemantics) CompileTerm

func (DialectValueSemantics) Compiled

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(*CompileContext, *Layer, *lpg.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 *lpg.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() *lpg.Node

func (EntityInfo) GetValueType

func (e EntityInfo) GetValueType() []string

func (EntityInfo) String

func (e EntityInfo) String() string

type EntityInfoIndex

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

func GetEntityInfoIndex

func GetEntityInfoIndex(g *lpg.Graph) EntityInfoIndex

GetEntityInfoIndex returns a fast-access entity info

func IndexEntityInfo

func IndexEntityInfo(entityInfo map[*lpg.Node]EntityInfo) EntityInfoIndex

IndexEntityInfo returns a fast-access version of entity info

func (EntityInfoIndex) Find

func (e EntityInfoIndex) Find(entityName string, fk []string) []*lpg.Node

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 ErrInvalidNSMapExpression

type ErrInvalidNSMapExpression string

func (ErrInvalidNSMapExpression) Error

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 ErrPathInstantiation

type ErrPathInstantiation struct {
	TargetNode string
	Msg        string
}

func (ErrPathInstantiation) Error

func (e ErrPathInstantiation) 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 ForeignKeyInfo

type ForeignKeyInfo struct {
	DocumentNodes []*lpg.Node
	ForeignKey    []string
}

type GraphBuilder

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

GraphBuilder contains the methods to ingest a graph

func NewGraphBuilder

func NewGraphBuilder(g *lpg.Graph, options GraphBuilderOptions) GraphBuilder

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

func (GraphBuilder) AddDefaults

func (gb GraphBuilder) AddDefaults(schemaRootNode, docRootNode *lpg.Node)

PostIngestSchemaNode calls the post ingest functions for properties of the document nodes for the given schema node.

func (GraphBuilder) ArrayAsEdge

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

func (GraphBuilder) ArrayAsNode

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

func (GraphBuilder) CollectionAsEdge

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

func (GraphBuilder) CollectionAsNode

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

func (GraphBuilder) GetGraph

func (gb GraphBuilder) GetGraph() *lpg.Graph

func (GraphBuilder) GetOptions

func (gb GraphBuilder) GetOptions() GraphBuilderOptions

func (GraphBuilder) LinkNodes

func (gb GraphBuilder) LinkNodes(ctx *Context, schema *Layer) error

func (GraphBuilder) LinkNodesWithSpecs

func (gb GraphBuilder) LinkNodesWithSpecs(ctx *Context, specs []*LinkSpec, eix EntityInfoIndex) error

func (GraphBuilder) NativeValueAsEdge

func (gb GraphBuilder) NativeValueAsEdge(schemaNode, parentDocumentNode *lpg.Node, value interface{}, types ...string) (*lpg.Edge, error)

func (GraphBuilder) NativeValueAsNode

func (gb GraphBuilder) NativeValueAsNode(schemaNode, parentDocumentNode *lpg.Node, value interface{}, types ...string) (*lpg.Edge, *lpg.Node, error)

func (GraphBuilder) NativeValueAsProperty

func (gb GraphBuilder) NativeValueAsProperty(schemaNode *lpg.Node, graphPath []*lpg.Node, value interface{}) error

func (GraphBuilder) NewNode

func (gb GraphBuilder) NewNode(schemaNode *lpg.Node) *lpg.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) NewUniqueEdge

func (gb GraphBuilder) NewUniqueEdge(fromNode, toNode *lpg.Node, label string, properties map[string]interface{}) *lpg.Edge

NewUniqueEdge create a new edge if one does not exist.

func (GraphBuilder) ObjectAsEdge

func (gb GraphBuilder) ObjectAsEdge(schemaNode, parentNode *lpg.Node, types ...string) (*lpg.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 *lpg.Node, types ...string) (*lpg.Edge, *lpg.Node, error)

ObjectAsNode creates a new object node

func (GraphBuilder) PostIngest

func (gb GraphBuilder) PostIngest(schemaRootNode, docRootNode *lpg.Node) error

PostIngest calls the post ingestion functions for properties that has one

func (GraphBuilder) PostIngestSchemaNode

func (gb GraphBuilder) PostIngestSchemaNode(schemaRootNode, schemaNode, docRootNode *lpg.Node, nodeIDMap map[string][]*lpg.Node) error

PostIngestSchemaNode calls the post ingest functions for properties of the document nodes for the given schema node.

func (GraphBuilder) PostNodeIngest

func (gp GraphBuilder) PostNodeIngest(schemaNode, docNode *lpg.Node) error

PostNodeIngest calls the post node ingestion functions for properties that has one

func (GraphBuilder) RawValueAsEdge

func (gb GraphBuilder) RawValueAsEdge(schemaNode, parentDocumentNode *lpg.Node, value string, types ...string) (*lpg.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) RawValueAsNode

func (gb GraphBuilder) RawValueAsNode(schemaNode, parentDocumentNode *lpg.Node, value string, types ...string) (*lpg.Edge, *lpg.Node, error)

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

func (GraphBuilder) RawValueAsProperty

func (gb GraphBuilder) RawValueAsProperty(schemaNode *lpg.Node, graphPath []*lpg.Node, value string) error

func (GraphBuilder) ValueAsEdge

func (gb GraphBuilder) ValueAsEdge(schemaNode, parentDocumentNode *lpg.Node, setValue func(*lpg.Node) error, types ...string) (*lpg.Edge, error)

func (GraphBuilder) ValueAsNode

func (gb GraphBuilder) ValueAsNode(schemaNode, parentDocumentNode *lpg.Node, setValue func(*lpg.Node) error, types ...string) (*lpg.Edge, *lpg.Node, error)

func (GraphBuilder) ValueAsProperty

func (gb GraphBuilder) ValueAsProperty(schemaNode *lpg.Node, graphPath []*lpg.Node, setValue func(*lpg.Node, string)) error

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

func (GraphBuilder) ValueSetAsEdge

func (gb GraphBuilder) ValueSetAsEdge(node, schemaNode, parentDocumentNode *lpg.Node)

ValueSetAsEdge can be called to notify the graph builder that a value is set that was ingested as edge

func (GraphBuilder) ValueSetAsNode

func (gb GraphBuilder) ValueSetAsNode(node, schemaNode, parentDocumentNode *lpg.Node)

ValueSetAsNode can be called to notif the graph builder that a node value is set

func (GraphBuilder) ValueSetAsProperty

func (gb GraphBuilder) ValueSetAsProperty(schemaNode *lpg.Node, graphPath []*lpg.Node, value string)

ValueSetAsProperty can be called to notify the graph builder that a node value is set

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 HasLabels

type HasLabels interface {
	GetLabels() []string
}

type HasNativeValue

type HasNativeValue interface {
	GetNativeValue() (interface{}, bool)
}

HasNativeValue is implemented by parsed doc nodes if the node knows its native value

type Ingester

type Ingester struct {
	Schema *Layer
	// contains filtered or unexported fields
}

func (*Ingester) GetPostIngestSchemaNodes

func (ing *Ingester) GetPostIngestSchemaNodes(schemaRootNode *lpg.Node) []*lpg.Node

func (*Ingester) Ingest

func (ing *Ingester) Ingest(builder GraphBuilder, root ParsedDocNode) (*lpg.Node, error)

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 JSONMarshaler

type JSONMarshaler struct {
	lpg.JSON
}

JSONMarshaler marshals/unmarshals a graph

func NewJSONMarshaler

func NewJSONMarshaler(interner Interner) *JSONMarshaler

func (*JSONMarshaler) Decode

func (m *JSONMarshaler) Decode(targetGraph *lpg.Graph, decoder *json.Decoder) error

Decode decodes a graph from JSON input

func (*JSONMarshaler) Encode

func (m *JSONMarshaler) Encode(g *lpg.Graph, writer io.Writer) error

Encode encodes the graph as a JSON document

func (*JSONMarshaler) Marshal

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

Marshal marshals the graph as a JSON document

func (*JSONMarshaler) Unmarshal

func (m *JSONMarshaler) Unmarshal(in []byte, targetGraph *lpg.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(*lpg.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(*lpg.Edge) string
}

LDMarshaler renders a graph in JSON-LD flattened format

func (*LDMarshaler) Marshal

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

type LDNode

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

type Layer

type Layer struct {
	Graph *lpg.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 *lpg.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 NewLayerFromRootNode

func NewLayerFromRootNode(layerInfoNode *lpg.Node) *Layer

func NewLayerInGraph

func NewLayerInGraph(g *lpg.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 *lpg.Graph) (*Layer, map[*lpg.Node]*lpg.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) (*lpg.Node, []*lpg.Node)

FindAttributeByID returns the attribute and the path to it

func (*Layer) FindFirstAttribute

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

FindFirstAttribute returns the first attribute for which the predicate holds

func (*Layer) ForEachAttribute

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

GetAttributeByID returns the attribute node by its ID.

func (*Layer) GetAttributePath

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

GetAttributePath returns the path to the given attribute node

func (*Layer) GetAttributesByID

func (l *Layer) GetAttributesByID(ids []string) []*lpg.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() *lpg.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) GetLinkSpecs

func (l *Layer) GetLinkSpecs() ([]*LinkSpec, error)

GetLinkSpecs retrieves link specs for the layer

func (*Layer) GetOverlayAttributes

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

Returns the overlay attribute nodes if there are any

func (*Layer) GetSchemaRootNode

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

func (l *Layer) NodeSlice() []*lpg.Node

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, *lpg.Node) *lpg.Node) *Layer

type LinkSpec

type LinkSpec struct {
	SchemaNode *lpg.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 the schema node is not a reference node, then this is the node
	// that should receive the link
	LinkNode string
	// If true, the reference can have more than one links
	Multi bool
	// IngestAs node or edge
	IngestAs string

	// Initialized when linkSpec is initialized
	ParentSchemaNode *lpg.Node
}

LinkSpec contains the link field information

func GetLinkSpec

func GetLinkSpec(schemaNode *lpg.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 EntityInfoIndex, fk []string) ([]*lpg.Node, error)

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

func (*LinkSpec) GetForeignKeys

func (spec *LinkSpec) GetForeignKeys(entityRoot *lpg.Node) ([]ForeignKeyInfo, error)

GetForeignKeys returns the foreign keys for the link spec given the entity root node

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(*CompileContext, *Layer, *lpg.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 *lpg.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 NodeValueAccessor

type NodeValueAccessor interface {
	GetNodeValue(*lpg.Node) (interface{}, error)
	SetNodeValue(interface{}, *lpg.Node) error
}

NodeValueAccessor can optionally be implemented by ValueAccessors to get/set node values directly

type ParsedDocNode

type ParsedDocNode interface {
	GetSchemaNode() *lpg.Node

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

	GetID() string

	GetValue() string
	GetValueTypes() []string

	GetAttributeIndex() int
	GetAttributeName() string

	GetChildren() []ParsedDocNode

	GetProperties() map[string]interface{}
}

type PostIngest

type PostIngest interface {
	ProcessNodePostDocIngest(schemaRootNode, schemaNode *lpg.Node, term *PropertyValue, docNode *lpg.Node) error
}

PostIngest is called after the ingestion of a document.

type PostNodeIngest

type PostNodeIngest interface {
	ProcessNodePostIngest(term *PropertyValue, docNode, layerNode *lpg.Node) error
}

PostNodeIngest is called after the ingestion of a node. If the node is a container (object or array), this is called after all children of the node are ingested.

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 *lpg.Node) *PropertyValue

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

func GetNodeOrSchemaProperty

func GetNodeOrSchemaProperty(node *lpg.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(term string, 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(term, s string) *PropertyValue

StringPropertyValue creates a string value

func StringSlicePropertyValue

func StringSlicePropertyValue(term string, 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) GetSem

func (pv *PropertyValue) GetSem() *TermSemantics

func (*PropertyValue) GetTerm

func (pv *PropertyValue) GetTerm() string

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

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(*CompileContext, 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 *lpg.Node, key string) (interface{}, error)
	UnmarshalJSON(target *Layer, key string, value interface{}, node *lpg.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

	// Tags define additional metadata about a term
	Tags map[string]struct{}

	Metadata interface{}
}

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

func GetTermInfo

func GetTermInfo(term string) *TermSemantics

func NewTerm

func NewTerm(ns, lname string, aliases ...string) TermSemantics

NewTerm create a new term.

func (TermSemantics) Compose

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

func (TermSemantics) Register

func (t TermSemantics) Register() string

Register a term and return its name

func (TermSemantics) SetAliases

func (t TermSemantics) SetAliases(aliases ...string) TermSemantics

func (TermSemantics) SetComposition

func (t TermSemantics) SetComposition(comp CompositionType) TermSemantics

func (TermSemantics) SetID

func (t TermSemantics) SetID(v bool) TermSemantics

func (TermSemantics) SetList

func (t TermSemantics) SetList(v bool) TermSemantics

func (TermSemantics) SetMetadata

func (t TermSemantics) SetMetadata(md any) TermSemantics

func (TermSemantics) SetTags

func (t TermSemantics) SetTags(tags ...string) TermSemantics

type TestCase

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

type ValueAccessor

type ValueAccessor interface {
	// GetNativeValue returns the native value based on input
	GetNativeValue(string, *lpg.Node) (interface{}, error)
	FormatNativeValue(newValue, oldValue interface{}, schNode *lpg.Node) (string, error)
}

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

func GetNodeValueAccessor

func GetNodeValueAccessor(node *lpg.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 *lpg.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. If this is empty, then the entity root
	// node is the context node
	ContextID string

	ContextExpr opencypher.Evaluatable

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

	// Request expressions
	RequestExprs []opencypher.Evaluatable

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

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

	// If empty, will be set to the ContextID. The results will be added under this node.
	ResultContext string

	// The schemanode containing the valueset info
	SchemaNode *lpg.Node
	// contains filtered or unexported fields
}

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(layer *Layer, node *lpg.Node) (*ValuesetInfo, error)

ValueSetInfoFromNode parses the valueset 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, resultContextSchemaNode *lpg.Node, result ValuesetLookupResponse) error

func (*ValuesetInfo) GetContextNode

func (vsi *ValuesetInfo) GetContextNode(docNode *lpg.Node) (*lpg.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) GetDocNodes

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

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

func (*ValuesetInfo) GetRequest

func (vsi *ValuesetInfo) GetRequest(ctx *Context, contextDocumentNode, vsiDocumentNode *lpg.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), tables []string) (ValuesetProcessor, error)

func (*ValuesetProcessor) Process

func (prc *ValuesetProcessor) Process(ctx *Context, builder GraphBuilder, vsiDocNode, contextSchemaNode, resultContextSchemaNode *lpg.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, resultContextSchemaNode, vsiDocNode *lpg.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