Documentation
¶
Overview ¶
Copyright 2021 Cloud Privacy Labs, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func CloneEdge(fromInTarget, toInTarget graph.Node, sourceEdge graph.Edge, ...) graph.Edge
- func CloneNode(sourceNode graph.Node, targetGraph graph.Graph) graph.Node
- func CloneProperties(iterator interface{ ... }) map[string]interface{}
- func ClonePropertyValueFunc(key string, value interface{}) interface{}
- func CombineNodeTypes(nodes []graph.Node) graph.StringSet
- func CompileTerms(layer *Layer) error
- func ComposeProperties(context *Context, target, source graph.Node) error
- func CopyGraph(target, source graph.Graph, nodeSelector func(graph.Node) bool, ...) map[graph.Node]graph.Node
- func CopyPropertyMap(m map[string]*PropertyValue) map[string]*PropertyValue
- func CopySchemaNodeIntoGraph(target graph.Graph, schemaNode graph.Node) graph.Node
- func DeepEqual(i1, i2 interface{}) error
- func DefaultNodeIDGenerator(path NodePath, schemaNode graph.Node) string
- func DocumentNodesUnder(node ...graph.Node) []graph.Node
- func FilterAttributeTypes(types []string) []string
- func FilterNonLayerTypes(types []string) []string
- func FindChildInstanceOf(parent graph.Node, childAttrID string) []graph.Node
- func FindNodeByID(g graph.Graph, ID string) []graph.Node
- func FollowEdgesToNodeWithType(typ string) func(graph.Edge, []graph.Node) EdgeFuncResult
- func ForEachAttributeNode(root graph.Node, f func(node graph.Node, path []graph.Node) bool) bool
- func ForEachAttributeNodeOrdered(root graph.Node, f func(node graph.Node, path []graph.Node) bool) bool
- func GetArrayElementNode(arraySchemaNode graph.Node) graph.Node
- func GetAttributeID(node graph.Node) string
- func GetAttributePath(root, node graph.Node) []graph.Node
- func GetEntityRoot(node graph.Node) graph.Node
- func GetEntityRootNodes(g graph.Graph) map[graph.Node]EntityInfo
- func GetIngestAs(schemaNode graph.Node) string
- func GetNodeID(node graph.Node) string
- func GetNodeIndex(node graph.Node) int
- func GetNodeValue(node graph.Node) (interface{}, error)
- func GetNodesInstanceOf(g graph.Graph, attrId string) []graph.Node
- func GetObjectAttributeNodes(objectSchemaNode graph.Node) []graph.Node
- func GetObjectAttributeNodesBy(objectSchemaNode graph.Node, keyTerm string) (map[string][]graph.Node, error)
- func GetParentAttribute(node graph.Node) graph.Node
- func GetParentDocumentNodes(node graph.Node) []graph.Node
- func GetRawNodeValue(node graph.Node) (string, bool)
- func GetSliceByTermsFunc(includeTerms []string, includeAttributeNodes bool) func(*Layer, graph.Node) graph.Node
- func GetTermMetadata(term string) interface{}
- func InstanceOf(node graph.Node) []graph.Node
- func InternSlice(interner Interner, slice []string) []string
- func IsAttributeNode(node graph.Node) bool
- func IsAttributeTreeEdge(edge graph.Edge) bool
- func IsDocumentEdge(edge graph.Edge) bool
- func IsDocumentNode(node graph.Node) bool
- func IsPropertiesEqual(p, q map[string]*PropertyValue) bool
- func IterateAncestors(root graph.Node, nodeFunc func(graph.Node) bool, ...) bool
- func IterateDescendants(from graph.Node, nodeFunc func(graph.Node, []graph.Node) bool, ...) bool
- func LDDescendToListElements(in []interface{}) []interface{}
- func LDGetKeyValue(key string, node interface{}) (interface{}, bool)
- func LDGetListElements(node interface{}) []interface{}
- func LDGetNodeID(node interface{}) string
- func LDGetNodeTypes(node interface{}) []string
- func LDGetNodeValue(node interface{}) string
- func LDGetStringValue(key string, node interface{}) string
- func MakeErrInvalidInput(id ...string) error
- func MarshalLayer(layer *Layer) (interface{}, error)
- func MarshalSchemaVariant(variant *SchemaVariant) interface{}
- func NewDocumentGraph() graph.Graph
- func NewLayerGraph() graph.Graph
- func NewTerm(ns, lname string, isID, isList bool, comp CompositionType, md interface{}) string
- func PropertiesAsMap(iterator interface{ ... }) map[string]*PropertyValue
- func RegisterTerm(t TermSemantics)
- func RemoveRawNodeValue(node graph.Node)
- func RunTestsFromFile(t *testing.T, file string, unmarshal func(json.RawMessage) (TestCase, error))
- func SetAttributeID(node graph.Node, ID string)
- func SetNodeID(node graph.Node, ID string)
- func SetNodeIndex(node graph.Node, index int)
- func SetNodeValue(node graph.Node, value interface{}) error
- func SetRawNodeValue(node graph.Node, value string)
- func SkipEdgesToNodeWithType(typ string) func(graph.Edge, []graph.Node) EdgeFuncResult
- func SortEdges(edges []graph.Edge) []graph.Edge
- func SortEdgesItr(edges graph.EdgeIterator) graph.EdgeIterator
- func SortNodes(nodes []graph.Node)
- func StringSetIntersection(s1, s2 []string) []string
- func StringSetSubtract(s1, s2 []string) []string
- func StringSetToSlice(str map[string]struct{}) []string
- func StringSetUnion(s1, s2 []string) []string
- func ToMap(in interface{}) interface{}
- func UnmarshalJSONLDGraph(input interface{}, target graph.Graph, interner Interner) error
- func ValidateDocumentNode(node graph.Node) error
- func ValidateDocumentNodeBySchema(node, schemaNode graph.Node) error
- type BundleByID
- type BundleByType
- type CompilablePropertyContainer
- type CompiledGraph
- type CompiledProperties
- func (p *CompiledProperties) CopyCompiledToMap(target map[interface{}]interface{})
- func (p *CompiledProperties) CopyTo(target *CompiledProperties)
- func (p *CompiledProperties) GetCompiledProperty(key interface{}) (interface{}, bool)
- func (p *CompiledProperties) SetCompiledProperty(key, value interface{})
- type Compiler
- type Composer
- type CompositionType
- type Context
- type DefaultCompiledGraph
- type DefaultLogger
- type EdgeCompiler
- type EdgeFuncResult
- type EncodingIndex
- type EntityInfo
- type ErrCannotDetermineEdgeLabel
- type ErrCannotDeterminePropertyName
- type ErrCannotFindAncestor
- type ErrCannotResolveLink
- type ErrDataIngestion
- type ErrDuplicate
- type ErrDuplicateAttributeID
- type ErrInconsistentTypes
- type ErrInvalidEntityID
- type ErrInvalidForeignKeys
- type ErrInvalidInput
- type ErrInvalidLinkSpec
- type ErrInvalidSchema
- type ErrInvalidValidator
- type ErrInvalidValue
- type ErrInvalidValuesetSpec
- type ErrMultipleParentNodes
- type ErrMultipleTargetsFound
- type ErrMultipleTypes
- type ErrNoParentNode
- type ErrNotFound
- type ErrSchemaValidation
- type ErrTerm
- type ErrValidation
- type ErrValidatorCompile
- type ErrValueset
- type Ingester
- func (ingester *Ingester) Array(ictx IngestionContext, types ...string) (string, graph.Edge, graph.Node, error)
- func (ingester *Ingester) ArrayAsEdge(ictx IngestionContext, types ...string) (graph.Edge, error)
- func (ingester *Ingester) ArrayAsNode(ictx IngestionContext, types ...string) (graph.Edge, graph.Node, error)
- func (ingester *Ingester) EmbedSchemaNode(targetNode, schemaNode graph.Node)
- func (ingester *Ingester) Finish(ictx IngestionContext, root graph.Node) error
- func (ingester *Ingester) Instantiate(ictx IngestionContext) (string, graph.Edge, graph.Node, IngestionContext, error)
- func (ingester *Ingester) Link(ictx IngestionContext, spec *LinkSpec, docNode, parentNode graph.Node, ...) error
- func (ingester *Ingester) NewNode(ictx IngestionContext) graph.Node
- func (ingester *Ingester) Object(ictx IngestionContext, types ...string) (string, graph.Edge, graph.Node, error)
- func (ingester *Ingester) ObjectAsEdge(ictx IngestionContext, types ...string) (graph.Edge, error)
- func (ingester *Ingester) ObjectAsNode(ictx IngestionContext, types ...string) (graph.Edge, graph.Node, error)
- func (ingester *Ingester) Polymorphic(ictx IngestionContext, ...) (graph.Node, error)
- func (ingester *Ingester) ProcessValueset(ctx IngestionContext, rootDocumentNode, schemaNode graph.Node) error
- func (ingester *Ingester) Start(context *Context, baseID string) IngestionContext
- func (ingester *Ingester) TestPolymorphicOptions(ictx IngestionContext, ...) ([]PolymorphicOption, error)
- func (ingester *Ingester) Validate(ictx IngestionContext, documentNode graph.Node) error
- func (ingester *Ingester) Value(ictx IngestionContext, value string, types ...string) (string, graph.Edge, graph.Node, error)
- func (ingester *Ingester) ValueAsEdge(ictx IngestionContext, value string, types ...string) (graph.Edge, error)
- func (ingester *Ingester) ValueAsNode(ictx IngestionContext, value string, types ...string) (graph.Edge, graph.Node, error)
- func (ingester *Ingester) ValueAsProperty(ictx IngestionContext, value string) error
- type IngestionContext
- func (ctx IngestionContext) GetEntityRootNode() graph.Node
- func (ctx IngestionContext) GetParentNode() graph.Node
- func (ctx IngestionContext) GetSchemaNode() graph.Node
- func (ctx IngestionContext) New(key interface{}, schemaNode graph.Node) IngestionContext
- func (ctx IngestionContext) NewLevel(docNode graph.Node) IngestionContext
- type Interner
- type JSONGraph
- type JSONGraphEdge
- type JSONGraphNode
- type JSONMarshaler
- type LDMarshaler
- type LDNode
- type Layer
- func (l *Layer) Clone() *Layer
- func (l *Layer) CloneInto(targetGraph graph.Graph) (*Layer, map[graph.Node]graph.Node)
- func (layer *Layer) Compose(context *Context, source *Layer) error
- func (l *Layer) FindAttributeByID(id string) (graph.Node, []graph.Node)
- func (l *Layer) FindFirstAttribute(predicate func(graph.Node) bool) (graph.Node, []graph.Node)
- func (l *Layer) ForEachAttribute(f func(graph.Node, []graph.Node) bool) bool
- func (l *Layer) ForEachAttributeOrdered(f func(graph.Node, []graph.Node) bool) bool
- func (l *Layer) GetAttributeByID(id string) graph.Node
- func (l *Layer) GetAttributePath(node graph.Node) []graph.Node
- func (l *Layer) GetAttributesByID(ids []string) []graph.Node
- func (l *Layer) GetEncoding() (encoding.Encoding, error)
- func (l *Layer) GetEntityIDNodes() []string
- func (l *Layer) GetID() string
- func (l *Layer) GetLayerRootNode() graph.Node
- func (l *Layer) GetLayerType() string
- func (l *Layer) GetSchemaRootNode() graph.Node
- func (l *Layer) GetValueType() string
- func (l *Layer) SetID(ID string)
- func (l *Layer) SetLayerType(t string)
- func (l *Layer) SetValueType(t string)
- func (layer *Layer) Slice(layerType string, nodeFilter func(*Layer, graph.Node) graph.Node) *Layer
- type LinkSpec
- type LogLevel
- type Logger
- type NodeCompiler
- type NodePath
- type PolymorphicOption
- type PropertyContainer
- type PropertyValue
- func AsPropertyValue(in interface{}, exists bool) *PropertyValue
- func ComposeProperty(context *Context, key string, targetValue, sourceValue *PropertyValue) (*PropertyValue, error)
- func GetEntityIDFields(node graph.Node) *PropertyValue
- func GetNodeOrSchemaProperty(node graph.Node, key string) (*PropertyValue, bool)
- func IntPropertyValue(i int) *PropertyValue
- func ListAppend(v1, v2 *PropertyValue) *PropertyValue
- func SetUnion(v1, v2 *PropertyValue) *PropertyValue
- func StringPropertyValue(s string) *PropertyValue
- func StringSlicePropertyValue(s []string) *PropertyValue
- func (p *PropertyValue) AsInt() int
- func (p *PropertyValue) AsInterfaceSlice() []interface{}
- func (p *PropertyValue) AsString() string
- func (p *PropertyValue) AsStringSlice() []string
- func (p PropertyValue) Clone() *PropertyValue
- func (p *PropertyValue) Equal(v *PropertyValue) bool
- func (p PropertyValue) GetNativeValue() interface{}
- func (p *PropertyValue) Has(s string) bool
- func (p *PropertyValue) IsEqual(q *PropertyValue) bool
- func (p *PropertyValue) IsInt() bool
- func (p *PropertyValue) IsString() bool
- func (p *PropertyValue) IsStringSlice() bool
- func (p PropertyValue) MarshalJSON() ([]byte, error)
- func (p PropertyValue) MarshalYAML() (interface{}, error)
- func (p *PropertyValue) MustStringSlice() []string
- func (p *PropertyValue) Slice() []string
- func (p PropertyValue) String() string
- func (p *PropertyValue) UnmarshalJSON(in []byte) error
- func (p *PropertyValue) UnmarshalYAML(u func(interface{}) error) error
- type SchemaLoader
- type SchemaLoaderFunc
- type SchemaVariant
- type StringInterner
- type TermCompiler
- type TermMarshaler
- type TermSemantics
- type TestCase
- type Validator
- type ValueAccessor
- type ValuesetInfo
- type ValuesetLookupRequest
- type ValuesetLookupResponse
Constants ¶
const ( IngestAsNode = "node" IngestAsEdge = "edge" IngestAsProperty = "property" )
IngestAs constants
const LS = "https://lschema.org/"
Variables ¶
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
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) )
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) SchemaBaseTerm = NewTerm(LS, "SchemaVariant/schema", true, false, ErrorComposition, nil) OverlaysTerm = NewTerm(LS, "SchemaVariant/overlays", true, true, ErrorComposition, nil) // SchemaVariantTerm is the schema variant type SchemaVariantTerm = NewTerm(LS, "SchemaVariant", false, false, NoComposition, nil) // DescriptionTerm is used for comments/descriptions DescriptionTerm = NewTerm(LS, "description", false, false, SetComposition, nil) // AttributeNameTerm represents the name of an attribute AttributeNameTerm = NewTerm(LS, "attributeName", false, false, OverrideComposition, nil) // AttributeIndexTerm represents the index of an array element AttributeIndexTerm = NewTerm(LS, "attributeIndex", false, false, NoComposition, nil) // AttributeValueTerm represents the value of an attribute AttributeValueTerm = NewTerm(LS, "attributeValue", false, false, ErrorComposition, nil) // LayerRootTerm is an edge term that connects layer node to the root node of the schema LayerRootTerm = NewTerm(LS, "layer", false, false, ErrorComposition, nil) // DefaultValueTerm is the default value for an attribute if attribute is not present DefaultValueTerm = NewTerm(LS, "defaultValue", false, false, OverrideComposition, nil) // Format specifies a type-specific formatting directive, such as a date format FormatTerm = NewTerm(LS, "format", false, false, OverrideComposition, nil) // EntitySchemaTerm is inserted by the schema compilation to mark // entity roots. It records the schema ID containing the entity // definition. EntitySchemaTerm = NewTerm(LS, "entitySchema", false, false, ErrorComposition, nil) // NodeIDTerm keeps the node ID or the attribute ID NodeIDTerm = NewTerm(LS, "nodeID", false, false, ErrorComposition, nil) // IngestAsTerm ingests value as an edge, node, or property IngestAsTerm = NewTerm(LS, "ingestAs", false, false, OverrideComposition, nil) // AsPropertyOfTerm is optional. If specified, it gives the nearest // ancestor node that is an instance of the given type. If not, it // is the parent document node AsPropertyOfTerm = NewTerm(LS, "asPropertyOf", false, false, OverrideComposition, nil) // EdgeLabelTerm represents the value used as an edge label, when ingesting an edge EdgeLabelTerm = NewTerm(LS, "edgeLabel", false, false, OverrideComposition, nil) // PropertyNameTerm represents the value used as a property name when ingesting a property PropertyNameTerm = NewTerm(LS, "propertyName", false, false, OverrideComposition, nil) // DocumentNodeTerm is the type of document nodes DocumentNodeTerm = NewTerm(LS, "DocumentNode", false, false, ErrorComposition, nil) // NodeValueTerm is the property key used to keep node value NodeValueTerm = NewTerm(LS, "value", false, false, ErrorComposition, nil) // ValueTypeTerm defines the type of a value ValueTypeTerm = NewTerm(LS, "valueType", false, false, OverrideComposition, nil) // HasTerm is an edge term for linking document elements HasTerm = NewTerm(LS, "has", false, false, ErrorComposition, nil) // EntityIDFieldsTerm is a string or []string that lists the attribute IDs // for entity ID. It is defined at the root node of a layer. All // attribute IDs must refer to value nodes. EntityIDFieldsTerm = NewTerm(LS, "entityIdFields", false, false, OverrideComposition, nil) // EntityIDTerm is a string or []string that gives the unique ID of // an entity. This is a node property at the root node of an entity EntityIDTerm = NewTerm(LS, "entityId", false, false, OverrideComposition, nil) )
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.
var ( // Unordered named attributes (json object) ObjectAttributesTerm = NewTerm(LS, "Object/attributes", false, false, ErrorComposition, nil) // Ordered named attributes (json object, xml elements) ObjectAttributeListTerm = NewTerm(LS, "Object/attributeList", false, true, ErrorComposition, nil) // Reference to another schema. This will be resolved to another // schema during compilation ReferenceTerm = NewTerm(LS, "Reference/ref", false, false, ErrorComposition, nil) // ArrayItems contains the definition for the items of the array ArrayItemsTerm = NewTerm(LS, "Array/elements", false, false, ErrorComposition, nil) // All components of a composite attribute AllOfTerm = NewTerm(LS, "Composite/allOf", false, true, ErrorComposition, nil) // All options of a polymorphic attribute OneOfTerm = NewTerm(LS, "Polymorphic/oneOf", false, true, ErrorComposition, nil) )
Layer terms includes type specific terms recognized by the schema compiler. These are terms used to define elements of an attribute.
var ( ValuesetSourceIDTerm = NewTerm(LS, "vs/source", false, false, OverrideComposition, nil) ValuesetTablesTerm = NewTerm(LS, "vs/valuesets", false, false, OverrideComposition, nil) ValuesetRequestKeysTerm = NewTerm(LS, "vs/requestKeys", false, false, OverrideComposition, nil) ValuesetRequestValuesTerm = NewTerm(LS, "vs/requestValues", false, false, OverrideComposition, nil) ValuesetResultKeysTerm = NewTerm(LS, "vs/resultKeys", false, false, OverrideComposition, nil) ValuesetResultValuesTerm = NewTerm(LS, "vs/resultValues", false, false, OverrideComposition, nil) )
var DefaultTermMarshaler defaultTermMarshaler
var ErrInvalidEncodingIndex = errors.New("Invalid encoding index")
ErrInvalidEncodingIndex is used to return error about an invalid or unrecognized character encoding
var ErrNotASchemaVariant = errors.New("Not a schema variant")
var IncludeAllNodesInSliceFunc = func(layer *Layer, nd graph.Node) graph.Node { return CloneNode(nd, layer.Graph) }
IncludeAllNodesInSliceFunc includes all the nodes in the slice
var OnlyDocumentNodes = FollowEdgesToNodeWithType(DocumentNodeTerm)
OnlyDocumentNodes can be used in IterateDescendants edge func to follow edges that reach to document nodes
var SkipDocumentNodes = SkipEdgesToNodeWithType(DocumentNodeTerm)
SkipDocumentNodes can be used in IterateDescendants edge func to skip all edges that go to a document node
var SkipSchemaNodes = SkipEdgesToNodeWithType(AttributeNodeTerm)
SkipSchemaNodes can be used in IterateDescendants edge func to skip all edges that go to a schema node
Functions ¶
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 ¶
CombineNodeTypes returns a combination of the types of all the given nodes
func CompileTerms ¶
CompileTerms compiles all node and edge terms of the layer
func ComposeProperties ¶
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 ¶
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 ¶
DefaultNodeIDGenerator returns Ingester.Schema.ID + join(path,".")
func DocumentNodesUnder ¶
DocumentNodesUnder returns all document nodes under the given node(s)
func FilterAttributeTypes ¶
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 ¶
FilterNonLayerTypes returns the types that are not attribute or layer related
func FindChildInstanceOf ¶
FindChildInstanceOf returns the childnodes of the parent that are instance of the given attribute id
func FollowEdgesToNodeWithType ¶
FollowEdgesToNodeWithType returns a function that only follows edges that go to a node with the given type
func ForEachAttributeNode ¶
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 ¶
GetArrayElementNode returns the array element node from an array node
func GetAttributeID ¶
GetAttributeID returns the attributeID
func GetEntityRoot ¶
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 ¶
GetIngestAs returns "node", "edge", or "property" based on IngestAsTerm
func GetNodeIndex ¶
GetNodeIndex returns the value of attribute index term as int
func GetNodeValue ¶
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 ¶
GetNodesInstanceOf returns document nodes that are instance of the given attribute id
func GetObjectAttributeNodes ¶
GetObjectAttributeNodes returns the schema attribute nodes under a schema object.
func GetObjectAttributeNodesBy ¶
func GetObjectAttributeNodesBy(objectSchemaNode graph.Node, keyTerm string) (map[string][]graph.Node, error)
GetObjectAttributeNodesBy returns the schema attribute nodes under a schema object. The returned map is keyed by the keyTerm
func GetParentAttribute ¶
GetParentAttribute returns the parent attribute of the given node
func GetParentDocumentNodes ¶
GetParentDocumentNodes returns the document nodes that have incoming edges to this node
func GetRawNodeValue ¶
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 ¶
InstanceOf returns the nodes that are connect to this node via instanceOf term,
func InternSlice ¶
InternSlice interns all elements of a slice
func IsAttributeNode ¶
IsAttributeNode returns true if the node has Attribute type
func IsAttributeTreeEdge ¶
IsAttributeTreeEdge returns true if the edge is an edge between two attribute nodes
func IsDocumentEdge ¶
IsDocumentEdge returns true if the edge is not an attribute link term
func IsDocumentNode ¶
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 skip 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 ¶
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 ¶
LDGetStringValue returns a string value from the node with the key. The node must be a map
func MakeErrInvalidInput ¶
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 ¶
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 ¶
NewDocumentGraph creates a new graph with the correct indexes for document ingestion
func NewLayerGraph ¶
NewLayerGraph creates a new graph indexes to store layers
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 RunTestsFromFile ¶
func SetAttributeID ¶
SetAttrributeID sets the attribute ID
func SetNodeIndex ¶
func SetNodeValue ¶
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 ¶
SetRawNodeValue sets the unprocessed node value
func SkipEdgesToNodeWithType ¶
SkipEdgesToNodeWithType returns a function that skips edges that go to a node with the given type
func SortEdgesItr ¶
func SortEdgesItr(edges graph.EdgeIterator) graph.EdgeIterator
SortEdgesItr sorts the edges by index
func StringSetIntersection ¶
StringSetIntersection returns the common elements of s1 and s2
func StringSetSubtract ¶
StringSetSubtract returns all elements that are in s1 but not in s2
func StringSetToSlice ¶
StringSetToSlice converts a string set to slice
func StringSetUnion ¶
StringSetUnion returns s1 setunion s2
func UnmarshalJSONLDGraph ¶
UnmarshalJSONLDGraph Unmarshals a graph in JSON-LD format
func ValidateDocumentNode ¶
ValidateDocumentNode runs the validators for the document node
func ValidateDocumentNodeBySchema ¶
ValidateDocumentNodeBySchema runs the validators for the document node
Types ¶
type BundleByID ¶
type BundleByID struct {
// contains filtered or unexported fields
}
BundleByID stores layers by their ID
func (*BundleByID) Add ¶
func (b *BundleByID) Add(ctx *Context, variantID string, schema *Layer, overlays ...*Layer) (*Layer, error)
Add a new variant to the bundle. The variant ID must be unique. If variant ID is empty, schema ID will be used. If there are overlays, the variant will be built using the schema as the base, so caller must create a clone if necessary.
func (*BundleByID) LoadSchema ¶
func (b *BundleByID) LoadSchema(ref string) (*Layer, error)
LoadSchema is a schema loader function using schema IDs as reference
type BundleByType ¶
BundleByType stores layers by their value type
func (*BundleByType) Add ¶
func (b *BundleByType) Add(ctx *Context, typeName string, schema *Layer, overlays ...*Layer) (*Layer, error)
Add a new variant to the bundle. The typeName must be unique. If empty, schema type will be used. If there are overlays, the variant will be built using the schema as the base, so caller must create a clone if necessary.
func (*BundleByType) LoadSchema ¶
func (b *BundleByType) LoadSchema(ref string) (*Layer, error)
SchemaLoader is a schema loader function using types as reference.
type CompilablePropertyContainer ¶
type CompilablePropertyContainer interface {
GetProperty(string) (interface{}, bool)
SetProperty(string, interface{})
}
CompilablePropertyContainer contains properties and a compiled data map
type CompiledGraph ¶
type CompiledGraph interface {
GetCompiledSchema(string) *Layer
PutCompiledSchema(*Context, string, *Layer) *Layer
GetGraph() graph.Graph
}
A CompiledGraph is a graph of compiled schemas
type CompiledProperties ¶
type CompiledProperties struct {
// contains filtered or unexported fields
}
CompiledProperties is a lazy-initialized map
func (*CompiledProperties) CopyCompiledToMap ¶
func (p *CompiledProperties) CopyCompiledToMap(target map[interface{}]interface{})
func (*CompiledProperties) CopyTo ¶
func (p *CompiledProperties) CopyTo(target *CompiledProperties)
func (*CompiledProperties) GetCompiledProperty ¶
func (p *CompiledProperties) GetCompiledProperty(key interface{}) (interface{}, bool)
func (*CompiledProperties) SetCompiledProperty ¶
func (p *CompiledProperties) SetCompiledProperty(key, value interface{})
type Compiler ¶
type Compiler struct {
// Loader loads a layer using a strong reference.
Loader SchemaLoader
// CGraph keeps the compiled interlinked schemas. If this is
// 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
}
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 ¶
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 (*Context) GetInterner ¶
type DefaultCompiledGraph ¶
type DefaultCompiledGraph struct {
// contains filtered or unexported fields
}
DefaultCompiledGraph keeps compiled graphs in a map. Zero value of DefaultCompiledGraph is ready to use
func (DefaultCompiledGraph) GetCompiledSchema ¶
func (d DefaultCompiledGraph) GetCompiledSchema(ref string) *Layer
GetCompiledSchema returns a compiled schema for the reference if known
func (DefaultCompiledGraph) GetGraph ¶
func (d DefaultCompiledGraph) GetGraph() graph.Graph
func (*DefaultCompiledGraph) PutCompiledSchema ¶
func (d *DefaultCompiledGraph) PutCompiledSchema(context *Context, ref string, layer *Layer) *Layer
PutCompiledSchema adds the copy of the schema to the common graph
type DefaultLogger ¶
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
type EntityInfo ¶
type EntityInfo struct {
// contains filtered or unexported fields
}
EntityInfo contains the entity information in the doc graph
func (EntityInfo) GetEntitySchema ¶
func (e EntityInfo) GetEntitySchema() string
func (EntityInfo) GetID ¶
func (e EntityInfo) GetID() []string
func (EntityInfo) GetRoot ¶
func (e EntityInfo) GetRoot() graph.Node
func (EntityInfo) GetValueType ¶
func (e EntityInfo) GetValueType() []string
type ErrCannotDetermineEdgeLabel ¶
func (ErrCannotDetermineEdgeLabel) Error ¶
func (e ErrCannotDetermineEdgeLabel) Error() string
type ErrCannotDeterminePropertyName ¶
type ErrCannotDeterminePropertyName struct {
Path NodePath
}
func (ErrCannotDeterminePropertyName) Error ¶
func (e ErrCannotDeterminePropertyName) Error() string
type ErrCannotFindAncestor ¶
type ErrCannotFindAncestor struct {
Path NodePath
}
func (ErrCannotFindAncestor) Error ¶
func (e ErrCannotFindAncestor) Error() string
type ErrCannotResolveLink ¶
type ErrCannotResolveLink LinkSpec
func (ErrCannotResolveLink) Error ¶
func (err ErrCannotResolveLink) Error() string
type ErrDataIngestion ¶
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 ¶
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 ¶
func (ErrInvalidForeignKeys) Error ¶
func (err ErrInvalidForeignKeys) Error() string
type ErrInvalidInput ¶
ErrInvalidInput is used for errors due to incorrect values, unexpected syntax, etc.
func (ErrInvalidInput) Error ¶
func (e ErrInvalidInput) Error() string
type ErrInvalidLinkSpec ¶
func (ErrInvalidLinkSpec) Error ¶
func (err ErrInvalidLinkSpec) Error() string
type ErrInvalidSchema ¶
type ErrInvalidSchema string
func (ErrInvalidSchema) Error ¶
func (e ErrInvalidSchema) Error() string
type ErrInvalidValidator ¶
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 ¶
func (ErrInvalidValue) Error ¶
func (e ErrInvalidValue) Error() string
type ErrInvalidValuesetSpec ¶
type ErrInvalidValuesetSpec struct {
Msg string
}
func (ErrInvalidValuesetSpec) Error ¶
func (e ErrInvalidValuesetSpec) Error() string
type ErrMultipleParentNodes ¶
type ErrMultipleParentNodes struct {
Of string
}
ErrMultipleParentNodes is used to denote multiple parentnodes detected during data ingestion
func (ErrMultipleParentNodes) Error ¶
func (e ErrMultipleParentNodes) Error() string
type ErrMultipleTargetsFound ¶
type ErrMultipleTargetsFound struct {
ID string
}
func (ErrMultipleTargetsFound) Error ¶
func (err ErrMultipleTargetsFound) Error() string
type ErrMultipleTypes ¶
type ErrMultipleTypes string
ErrMultipleTypes denotes multiple incompatible types declared for an attribute
func (ErrMultipleTypes) Error ¶
func (e ErrMultipleTypes) Error() string
type ErrNoParentNode ¶
type ErrNoParentNode struct {
Of string
}
ErrNoParentNode is used to denote no parent nodes for an ingested node
func (ErrNoParentNode) Error ¶
func (e ErrNoParentNode) Error() string
type ErrNotFound ¶
type ErrNotFound string
ErrNotFound is used for all not-found errors.
func (ErrNotFound) Error ¶
func (e ErrNotFound) Error() string
type ErrSchemaValidation ¶
func (ErrSchemaValidation) Error ¶
func (e ErrSchemaValidation) Error() string
type ErrValidation ¶
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 ¶
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
}
func (ErrValueset) Error ¶
func (e ErrValueset) Error() string
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
ValuesetFunc func(ValuesetLookupRequest) (ValuesetLookupResponse, 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) ArrayAsNode ¶
func (*Ingester) EmbedSchemaNode ¶
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) Instantiate ¶
func (ingester *Ingester) Instantiate(ictx IngestionContext) (string, graph.Edge, graph.Node, IngestionContext, error)
Instantiate the latest schema node element in the context, and connect it to its parent. Returns the new ingestion context to add nodes after the new node. If the new node is an object or array, the returned ingestion context is a level deeper.
func (*Ingester) Link ¶
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 because this link may refer to a node with no ingested data.
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 ¶
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, test, ingest func(*Ingester, IngestionContext) (graph.Node, error)) (graph.Node, error)
Polymorphic tests all options in the schema by calling ingest func to find the actual type. Then ingests using that option
func (*Ingester) ProcessValueset ¶
func (ingester *Ingester) ProcessValueset(ctx IngestionContext, rootDocumentNode, schemaNode graph.Node) error
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) TestPolymorphicOptions ¶
func (ingester *Ingester) TestPolymorphicOptions(ictx IngestionContext, ingest func(*Ingester, IngestionContext) (graph.Node, error)) ([]PolymorphicOption, error)
TestPolymorphicOptions ingests data at the current location using all polymorphic options with OnlySchemaAttributes set to true, and returns the results of those ingestions
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 ¶
Interner interface is used to keep a string table to reduce memory footprint by eliminated repeated keys
type JSONGraph ¶
type JSONGraph struct {
Nodes []JSONGraphNode `json:"nodes"`
Edges []JSONGraphEdge `json:"edges"`
}
type JSONGraphEdge ¶
type JSONGraphEdge struct {
From int `json:"from"`
To int `json:"to"`
Label string `json:"label,omitempty"`
Properties map[string]*PropertyValue `json:"properties,omitempty"`
}
JSONGraphEdge includes the from-to node indexes, the label and properties
type JSONGraphNode ¶
type JSONGraphNode struct {
N int `json:"n"`
ID string `json:"id,omitempty"`
Labels []string `json:"labels,omitempty"`
Properties map[string]*PropertyValue `json:"properties,omitempty"`
}
JSONGraphNode includes a node index, labels, and properties of the node
type JSONMarshaler ¶
type JSONMarshaler struct {
// contains filtered or unexported fields
}
JSONMarshaler marshals/unmarshals a graph
func NewJSONMarshaler ¶
func NewJSONMarshaler(interner Interner) *JSONMarshaler
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 Layer ¶
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 ¶
LayersFromGraph returns the layers from an existing graph. All Schema and Overlay nodes are returned as layers.
func NewLayerInGraph ¶
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 UnmarshalLayer ¶
UnmarshalLayer unmarshals a schema ar overlay
func UnmarshalLayerFromSlice ¶
func (*Layer) Clone ¶
Clone returns a copy of the layer in a new graph. If the graph contains other layers, they are not copied.
func (*Layer) CloneInto ¶
CloneInto clones the layer into the targetgraph. If the source graph contains other layers, they are not copied.
func (*Layer) Compose ¶
Compose schema layers. Directly modifies the source and the target. The source must be an overlay.
func (*Layer) FindAttributeByID ¶
FindAttributeByID returns the attribute and the path to it
func (*Layer) FindFirstAttribute ¶
FindFirstAttribute returns the first attribute for which the predicate holds
func (*Layer) ForEachAttribute ¶
ForEachAttribute calls f with each attribute node, depth first. If f returns false, iteration stops
func (*Layer) ForEachAttributeOrdered ¶
ForEachAttributeOrdered calls f with each attribute node, depth first and in order. If f returns false, iteration stops
func (*Layer) GetAttributeByID ¶
GetAttributeByID returns the attribute node by its ID.
func (*Layer) GetAttributePath ¶
GetAttributePath returns the path to the given attribute node
func (*Layer) GetAttributesByID ¶
GetAttributesByID returns attribute nodes by ID
func (*Layer) GetEncoding ¶
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 ¶
GetEntityIDNodes returns the entity id attribute IDs from the layer root node
func (*Layer) GetLayerRootNode ¶
GetLayerRootNode returns the root node of the schema
func (*Layer) GetLayerType ¶
GetLayerType returns the layer type, SchemaTerm or OverlayTerm.
func (*Layer) GetSchemaRootNode ¶
GetSchemaRootNode returns the root node of the object defined by the schema
func (*Layer) GetValueType ¶
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) SetLayerType ¶
SetLayerType sets if the layer is a schema or an overlay
func (*Layer) SetValueType ¶
SetValueType sets the value types of the 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 ¶
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 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) AppendString ¶
type PolymorphicOption ¶
type PropertyContainer ¶
type PropertyContainer interface {
GetProperties() map[string]*PropertyValue
}
PropertyContainer is an object that contains properties. Node and Edge are property containers
type PropertyValue ¶
type PropertyValue struct {
// contains filtered or unexported fields
}
PropertyValue can be a string or []string. It is an immutable value object
func AsPropertyValue ¶
func AsPropertyValue(in interface{}, exists bool) *PropertyValue
func ComposeProperty ¶
func ComposeProperty(context *Context, key string, targetValue, sourceValue *PropertyValue) (*PropertyValue, error)
ComposeProperty composes targetValue and sourceValue for key
func GetEntityIDFields ¶
func GetEntityIDFields(node graph.Node) *PropertyValue
GetEntityIDFields returns the value of the entity ID fields from a document node
func GetNodeOrSchemaProperty ¶
func GetNodeOrSchemaProperty(node graph.Node, key string) (*PropertyValue, bool)
GetNodeOrSchemaProperty gets the node property with the key from the node, or from the schema nodes it is attached to
func IntPropertyValue ¶
func IntPropertyValue(i int) *PropertyValue
IntPropertyValue converts the int value to string, and returns a string value
func ListAppend ¶
func ListAppend(v1, v2 *PropertyValue) *PropertyValue
ListAppend appends v2 and v1
func SetUnion ¶
func SetUnion(v1, v2 *PropertyValue) *PropertyValue
SetUnion computes the set union of properties v1 and v2
func StringPropertyValue ¶
func StringPropertyValue(s string) *PropertyValue
StringPropertyValue creates a string value
func StringSlicePropertyValue ¶
func StringSlicePropertyValue(s []string) *PropertyValue
StringSlicePropertyValue creates a []string value. If s is nil, it creates an empty slice
func (*PropertyValue) AsInt ¶
func (p *PropertyValue) AsInt() int
AsInt attempts to return the underlying string value as integer
func (*PropertyValue) AsInterfaceSlice ¶
func (p *PropertyValue) AsInterfaceSlice() []interface{}
AsInterfaceSlice returns an interface slice of the underlying value if it is a []string.
func (*PropertyValue) AsString ¶
func (p *PropertyValue) AsString() string
AsString returns the value as string
func (*PropertyValue) AsStringSlice ¶
func (p *PropertyValue) AsStringSlice() []string
AsStringSlice returns the value as string slice. If the underlying value is not a string slice, returns nil
func (PropertyValue) Clone ¶
func (p PropertyValue) Clone() *PropertyValue
func (*PropertyValue) Equal ¶
func (p *PropertyValue) Equal(v *PropertyValue) bool
Equal compares two property values, and returns true if they are equal
func (PropertyValue) GetNativeValue ¶
func (p PropertyValue) GetNativeValue() interface{}
GetNativeValue is used bythe expression evaluators to access the native value of the property
func (*PropertyValue) Has ¶
func (p *PropertyValue) Has(s string) bool
Has checks if p has the given string or is equal to it
func (*PropertyValue) IsEqual ¶
func (p *PropertyValue) IsEqual(q *PropertyValue) bool
IsEqual tests if two values are equal
func (*PropertyValue) IsInt ¶
func (p *PropertyValue) IsInt() bool
Returns true if the underlying value is a string, and that string can be converted to int
func (*PropertyValue) IsString ¶
func (p *PropertyValue) IsString() bool
IsString returns true if the underlying value is a string
func (*PropertyValue) IsStringSlice ¶
func (p *PropertyValue) IsStringSlice() bool
IsStringSlice returns true if the underlying value is a string slice
func (PropertyValue) MarshalJSON ¶
func (p PropertyValue) MarshalJSON() ([]byte, error)
func (PropertyValue) MarshalYAML ¶
func (p PropertyValue) MarshalYAML() (interface{}, error)
func (*PropertyValue) MustStringSlice ¶
func (p *PropertyValue) MustStringSlice() []string
MustStringSlice returns the value as a string slice. If the underlying value is not a string slice, returns a string slice containing one element. If p is nil, returns nil
func (*PropertyValue) Slice ¶
func (p *PropertyValue) Slice() []string
Slice returns the property value as a slice. If the property value is a string, returns a slice containing that value. If the property value is nil, returns an empty slice
func (PropertyValue) String ¶
func (p PropertyValue) String() string
func (*PropertyValue) UnmarshalJSON ¶
func (p *PropertyValue) UnmarshalJSON(in []byte) error
func (*PropertyValue) UnmarshalYAML ¶
func (p *PropertyValue) UnmarshalYAML(u func(interface{}) error) error
type SchemaLoader ¶
SchemaLoader interface defines the LoadSchema method that loads schemas by reference
type SchemaLoaderFunc ¶
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 SchemaVariant ¶
type SchemaVariant struct {
ID string
Type string
ValueType 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 (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 Validator ¶
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 ¶
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
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.
SourceID string
// Optional lookup table IDs. If ommitted, all compatible tables are
// looked up
TableIDs []string
// Ordered list of valueset keys. The request to the valueset
// function will use these as the request keys
RequestKeys []string
// Ordered list of attribute ids containing valueset request
// values. The elements of this match the keys array
RequestValues []string
// The keys of the valueset result
ResultKeys []string
// The attribute ids of the nodes under this node to receive values
ResultValues []string
}
func ValuesetInfoFromNode ¶
func ValuesetInfoFromNode(node graph.Node) *ValuesetInfo
ValueSetInfoFromNode parses the valuese information from a node. Returns nil if the node does not have valueset info
func (*ValuesetInfo) GetRequest ¶
type ValuesetLookupRequest ¶
type ValuesetLookupResponse ¶
Source Files
¶
- bundle.go
- compile.go
- compose.go
- context.go
- copy.go
- docgraph.go
- encoding.go
- equal.go
- errors.go
- graph.go
- graphjson.go
- ingest.go
- intern.go
- layer.go
- ld.go
- ldmarshaler.go
- link.go
- logger.go
- marshallayer.go
- propertyvalue.go
- semcompilation.go
- semcomposition.go
- semtermmarshal.go
- semvalidation.go
- semvalue.go
- set.go
- slice.go
- terms.go
- termsemantics.go
- testutil.go
- valueset.go
- variant.go