Documentation
¶
Index ¶
- Constants
- Variables
- func ComposeProperties(target, source map[string]*PropertyValue) error
- func Copy(in, target *digraph.Graph, nodeSelector func(Node) bool, ...) map[Node]Node
- func CopyPropertyMap(m map[string]*PropertyValue) map[string]*PropertyValue
- func DeepEqual(i1, i2 interface{}) error
- func DescendToListElements(in []interface{}) []interface{}
- func FilterAttributeTypes(types []string) []string
- func FilterNonLayerTypes(types []string) []string
- func FilterValue(value interface{}, docnode Node, properties map[string]*PropertyValue) interface{}
- func FirstReachable(from Node, nodePredicate func(Node, []Node) bool, ...) (Node, []Node)
- func ForEachAttributeNode(root Node, f func(node Node, path []Node) bool) bool
- func ForEachAttributeNodeOrdered(root Node, f func(node Node, path []Node) bool) bool
- func GetFilteredValue(schemaNode, docNode Node) interface{}
- func GetKeyValue(key string, node interface{}) (interface{}, bool)
- func GetLDListElements(node interface{}) []interface{}
- func GetNodeFilteredValue(node Node) interface{}
- func GetNodeID(node interface{}) string
- func GetNodeTypes(node interface{}) []string
- func GetSliceByTermsFunc(includeTerms []string, includeAttributeNodes bool) func(*Layer, Node) Node
- func GetStringValue(key string, node interface{}) string
- func GetTermMetadata(term string) interface{}
- func IsAttributeNode(a Node) bool
- func IsAttributeTreeEdge(edge Edge) bool
- func IsDocumentEdge(edge digraph.Edge) bool
- func IsDocumentNode(a Node) bool
- func IterateDescendants(from Node, nodeFunc func(Node, []Node) bool, ...) bool
- func MakeErrInvalidInput(id ...string) error
- func MarshalLayer(layer *Layer) interface{}
- func MarshalSchemaManifest(manifest *SchemaManifest) interface{}
- func NewTerm(term string, isID, isList bool, comp CompositionType, md interface{}) string
- func RegisterTerm(t TermSemantics)
- func RunTestsFromFile(t *testing.T, file string, unmarshal func(json.RawMessage) (TestCase, error))
- func SortEdges(edges []Edge)
- func SortEdgesItr(edges digraph.Edges) digraph.Edges
- func SortNodes(nodes []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 UnmarshalGraph(input interface{}) (*digraph.Graph, error)
- func ValidateDocumentNode(node Node) error
- func ValidateDocumentNodeBySchema(node, schemaNode Node) error
- type Compiler
- type Composer
- type CompositionType
- type Edge
- type EdgeCompiler
- type EdgeFuncResult
- type EdgeSet
- type EncodingIndex
- type ErrDuplicateAttributeID
- type ErrDuplicateNodeID
- type ErrInvalidInput
- type ErrInvalidValidator
- type ErrMultipleTypes
- type ErrNotFound
- type ErrTerm
- type ErrUnknownOperator
- type ErrValidation
- type ErrValidatorCompile
- type LDMarshaler
- type Layer
- func (l *Layer) Clone() *Layer
- func (layer *Layer) Compose(source *Layer) error
- func (l *Layer) FindAttributeByID(id string) (Node, []Node)
- func (l *Layer) FindFirstAttribute(predicate func(Node) bool) (Node, []Node)
- func (l *Layer) ForEachAttribute(f func(Node, []Node) bool) bool
- func (l *Layer) ForEachAttributeOrdered(f func(Node, []Node) bool) bool
- func (l *Layer) GetAttributePath(node Node) []Node
- func (l *Layer) GetEncoding() (encoding.Encoding, error)
- func (l *Layer) GetID() string
- func (l *Layer) GetLayerInfoNode() Node
- func (l *Layer) GetLayerType() string
- func (l *Layer) GetSchemaRootNode() Node
- func (l *Layer) GetTargetType() string
- func (l *Layer) NewNode(ID string, types ...string) Node
- func (l *Layer) RenameBlankNodes(namer func(Node))
- func (l *Layer) SetID(ID string)
- func (l *Layer) SetLayerType(t string)
- func (l *Layer) SetTargetType(t string)
- func (layer *Layer) Slice(layerType string, nodeFilter func(*Layer, Node) Node) *Layer
- type Node
- type NodeCompiler
- type NodeSet
- type NopFilter
- type 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) Has(s string) bool
- func (p *PropertyValue) IsInt() bool
- func (p *PropertyValue) IsString() bool
- func (p *PropertyValue) IsStringSlice() bool
- func (p PropertyValue) String() string
- type SchemaManifest
- type TermCompiler
- type TermSemantics
- type TestCase
- type Types
- type Validator
- type ValueFilter
- type Walk
Constants ¶
const LS = "https://lschema.org/"
Variables ¶
var ( // SchemaTerm is the layer type for schemas SchemaTerm = NewTerm(LS+"Schema", false, false, NoComposition, nil) // OverlayTerm is the layer type for overlays OverlayTerm = NewTerm(LS+"Overlay", false, false, NoComposition, nil) // SchemaManifestTerm is the schema manifest type SchemaManifestTerm = NewTerm(LS+"SchemaManifest", false, false, NoComposition, nil) // TargetType is the term specifying the data type for the attribute defined TargetType = NewTerm(LS+"targetType", true, false, SetComposition, nil) // DescriptionTerm is used for comments/descriptions DescriptionTerm = NewTerm(LS+"description", false, false, SetComposition, nil) // AttributeNameTerm represents the name of an attribute AttributeNameTerm = NewTerm(LS+"attributeName", false, false, ErrorComposition, nil) // AttributeIndexTerm represents the index of an array element AttributeIndexTerm = NewTerm(LS+"attributeIndex", false, false, NoComposition, nil) // AttributeValueTerm represents the value of an attribute AttributeValueTerm = NewTerm(LS+"attributeValue", false, false, ErrorComposition, nil) // LayerRootTerm is an edge term that connects layer node to the root node of the schema LayerRootTerm = NewTerm(LS+"layer", false, false, ErrorComposition, nil) // DefaultValueTerm is the default value for an attribute if attribute is not present DefaultValueTerm = NewTerm(LS+"defaultValue", false, false, OverrideComposition, nil) // LabelTerm defines one or more presentation layer labels for the attribute LabelTerm = NewTerm(LS+"label", false, false, OverrideComposition, nil) )
var ( // CharacterEncodingTerm is used to specify a character encoding for // the data processed with the layer CharacterEncodingTerm = NewTerm(LS+"characterEncoding", false, false, OverrideComposition, nil) // InstanceOfTerm is an edge term that is used to connect values with // their schema specifications InstanceOfTerm = NewTerm(LS+"data#instanceOf", false, false, ErrorComposition, nil) BundleTerm = NewTerm(LS+"SchemaManifest#bundle", false, false, ErrorComposition, nil) SchemaBaseTerm = NewTerm(LS+"SchemaManifest#schema", true, false, ErrorComposition, nil) OverlaysTerm = NewTerm(LS+"SchemaManifest#overlays", true, true, ErrorComposition, nil) )
var AnyEdgePredicate = func(Edge) bool { return true }
AnyEdgePredicate accepts all edges
var AnyNodePredicate = func(Node) bool { return true }
AnyNodePredicate accepts all nodes
var AttributeTypes = struct { Value string Object string Array string Reference string Composite string Polymorphic string Attribute string }{ Value: NewTerm(LS+"Value", false, false, OverrideComposition, nil), Object: NewTerm(LS+"Object", false, false, OverrideComposition, nil), Array: NewTerm(LS+"Array", false, false, OverrideComposition, nil), Reference: NewTerm(LS+"Reference", false, false, OverrideComposition, nil), Composite: NewTerm(LS+"Composite", false, false, OverrideComposition, nil), Polymorphic: NewTerm(LS+"Polymorphic", false, false, OverrideComposition, nil), Attribute: NewTerm(LS+"Attribute", false, false, OverrideComposition, nil), }
AttributeTypes defines the terms describing attribute types. Each attribute must have one of the attribute types plus the Attribute type, marking the object as an attribute.
var DataEdgeTerms = struct { // Type of a document node // Edge label linking attribute nodes to an object node ObjectAttributes string // Edge label linking array element nodes to an array node ArrayElements string }{ ObjectAttributes: NewTerm(LS+"data/object#attributes", false, false, ErrorComposition, nil), ArrayElements: NewTerm(LS+"data/array#elements", false, false, ErrorComposition, nil), }
var DocumentNodeTerm = NewTerm(LS+"DocumentNode", false, false, ErrorComposition, nil)
DocumentNodeTerm is ithe type of document nodes
var ErrAttributeWithoutID = errors.New("Attribute without id")
var ErrCompositionSourceNotOverlay = errors.New("Composition source is not an overlay")
var ErrIncompatibleComposition = errors.New("Incompatible composition of layers")
var ErrInvalidComposition = errors.New("Invalid composition")
var ErrInvalidEncodingIndex = errors.New("Invalid encoding index")
ErrInvalidEncodingIndex is used to return error about an invalid or unrecognized character encoding
var ErrInvalidExpression = errors.New("Invalid expression")
var ErrInvalidJsonLdGraph = errors.New("Invalid JsonLd graph")
var ErrInvalidPredicate = errors.New("Invalid predicate")
var ErrNotALayer = errors.New("Not a layer")
var ErrNotASchemaManifest = errors.New("Not a schema manifest")
var IncludeAllNodesInSliceFunc = func(layer *Layer, nd Node) Node {
return nd.Clone().(*node)
}
IncludeAllNodesInSliceFunc includes all the nodes in the slice
var LayerTerms = struct { // Unordered named attributes (json object) Attributes string // Ordered named attributes (json object, xml elements) AttributeList string // Reference to another schema. This will be resolved to another // schema during compilation Reference string // ArrayItems contains the definition for the items of the array ArrayItems string // All components of a composite attribute AllOf string // All options of a polymorphic attribute OneOf string }{ Attributes: NewTerm(LS+"Object#attributes", false, false, ErrorComposition, nil), AttributeList: NewTerm(LS+"Object#attributeList", false, true, ErrorComposition, nil), Reference: NewTerm(LS+"Reference#reference", true, false, ErrorComposition, nil), ArrayItems: NewTerm(LS+"Array#items", false, false, ErrorComposition, nil), AllOf: NewTerm(LS+"Composite#allOf", false, true, ErrorComposition, nil), OneOf: NewTerm(LS+"Polymorphic#oneOf", false, true, ErrorComposition, nil), }
LayerTerms includes type specific terms recognized by the schema compiler. These are terms used to define elements of an attribute.
Functions ¶
func ComposeProperties ¶
func ComposeProperties(target, source map[string]*PropertyValue) error
ComposeProperties will combine the properties in source to target. The target properties will be modified directly
func Copy ¶
func Copy(in, target *digraph.Graph, nodeSelector func(Node) bool, edgeSelector func(Edge) bool) map[Node]Node
Copy in to target using the node selectors. Return a node map from the in to target nodes
func CopyPropertyMap ¶
func CopyPropertyMap(m map[string]*PropertyValue) map[string]*PropertyValue
CopyPropertyMap returns a copy of the property map
func DeepEqual ¶
func DeepEqual(i1, i2 interface{}) error
DeepEqual test equivalence between two JSON trees
func DescendToListElements ¶
func DescendToListElements(in []interface{}) []interface{}
If in is a @list, returns its elements
func FilterAttributeTypes ¶
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 FilterValue ¶
func FilterValue(value interface{}, docnode Node, properties map[string]*PropertyValue) interface{}
FilterValue computes the processed node value
func FirstReachable ¶
func FirstReachable(from Node, nodePredicate func(Node, []Node) bool, edgePredicate func(Edge, []Node) bool) (Node, []Node)
FirstReachable returns the first reachable node for which nodePrdicate returns true, using only the edges for which edgePredicate returns true.
func ForEachAttributeNode ¶
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 ¶
ForEachAttributeNodeOrdered calls f with each attribute node, depth first, preserving order. Path contains all the nodes from root to the current node. If f returns false, iteration stops. This function visits each node only once
func GetFilteredValue ¶
func GetFilteredValue(schemaNode, docNode Node) interface{}
GetFilteredValue filters the value through the schema properties and then through the node properties before returning
func GetKeyValue ¶
GetKeyValue returns the value of the key in the node. The node must be a map
func GetLDListElements ¶
func GetLDListElements(node interface{}) []interface{}
GetLDListElements returns the elements of a @list node. The input can be a [{"@list":elements}] or {@list:elements}. If the input cannot be interpreted as a list, returns nil
func GetNodeFilteredValue ¶
func GetNodeFilteredValue(node Node) interface{}
GetNodeFilteredValue returns the field value processed by the schema value filters, and then the node value filters
func GetNodeID ¶
func GetNodeID(node interface{}) string
GetNodeID returns the node @id. The argument must be a map
func GetNodeTypes ¶
func GetNodeTypes(node interface{}) []string
GetNodeTypes returns the node @type. The argument must be a map
func GetSliceByTermsFunc ¶
GetSliceByTermsFunc is used in the Slice function to select nodes by the properties it contains. If includeAttributeNodes is true, attributes nodes are included unconditionally even though the node does not contain any of the terms.
func GetStringValue ¶
GetStringValue returns a string value from the node with the key. The node must be a map
func GetTermMetadata ¶
func GetTermMetadata(term string) interface{}
GetTermMetadata returns metadata about a term
func IsAttributeNode ¶
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 a data edge term
func IsDocumentNode ¶
func IterateDescendants ¶
func IterateDescendants(from Node, nodeFunc func(Node, []Node) bool, edgeFunc func(Edge, []Node) EdgeFuncResult, ordered bool) bool
IterateDescendants iterates the descendants of the node based on the results of nodeFunc and edgeFunc.
For each visited node, if nodeFunc is not nil, nodeFunc is called with the node and the path to the node. If nodeFunc returns false, processing stops.
For each outgoing edge, if edgeFunc is not nil, edgeFunc is called with the edge and the path to the source node. If edgeFunc returns FollowEdgeResult, the edge is followed. If edgeFunc returnd DontFollowEdgeResult, edge is skipped. If edgeFunc returns StopEdgeResult, iteration stops.
func MakeErrInvalidInput ¶
func MarshalLayer ¶
func MarshalLayer(layer *Layer) interface{}
Marshals the layer into an expanded jsonld document
func MarshalSchemaManifest ¶
func MarshalSchemaManifest(manifest *SchemaManifest) interface{}
MarshalSchemaNanifest returns a compact jsonld document for the manifest
func NewTerm ¶
func NewTerm(term string, isID, isList bool, comp CompositionType, md interface{}) string
NewTerm registers a term with given semantics, and returns the term.
func RegisterTerm ¶
func RegisterTerm(t TermSemantics)
func RunTestsFromFile ¶
func SortEdgesItr ¶
SortEdgesItr sorts the edges by index
func StringSetIntersection ¶
StringSetIntersection returns the common elements of s1 and s2
func StringSetSubtract ¶
Returns all elements that are in s1 but not in s2
func StringSetToSlice ¶
func StringSetUnion ¶
StringSetUnion returns s1 setunion s2
func UnmarshalGraph ¶
Unmarshal a graph
func ValidateDocumentNode ¶
ValidateDocumentNode runs the validators for the document node
func ValidateDocumentNodeBySchema ¶
ValidateDocumentNodeBySchema runs the validators for the document node
Types ¶
type Compiler ¶
type Compiler struct { // Loader loads a layer using a strong reference. Loader func(string) (*Layer, error) }
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 Edge ¶
type Edge interface { digraph.Edge GetLabelStr() string // Clone returns a new edge that is a copy of this one but // unconnected to any nodes Clone() Edge GetProperties() map[string]*PropertyValue GetCompiledDataMap() map[interface{}]interface{} }
func CloneWithLabel ¶
CloneWithLabel returns a copy of the schema edge with a new label
func GetLayerEdgeBetweenNodes ¶
GetAttributeEdgeBetweenNodes returns the attribute edges between two nodes. If there are no direct edges, return nil
type EdgeCompiler ¶
type EdgeCompiler interface { // CompileEdge gets an edge and compiles the associated term on that // edge. It should store tje compiled state into edge.Compiled with // an opaque key CompileEdge(Edge) error }
EdgeCompiler interface represents term compilation algorithm when the term is an edge
During schema compilation, if the term metadata for the edge label implements EdgeCompiler, this method is called.
func GetEdgeCompiler ¶
func GetEdgeCompiler(term string) EdgeCompiler
GetEdgeCompiler return a compiler that will compile the term when the term is an edge label
type EdgeFuncResult ¶
type EdgeFuncResult int
const ( FollowEdgeResult EdgeFuncResult = iota SkipEdgeResult StopEdgeResult )
type EdgeSet ¶
type EdgeSet map[Edge]struct{}
An EdgeSet is a set of edges
func NewEdgeSet ¶
NewEdgeSet creates a new edge set containing the given edges
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 ErrDuplicateAttributeID ¶
type ErrDuplicateAttributeID string
func (ErrDuplicateAttributeID) Error ¶
func (e ErrDuplicateAttributeID) Error() string
type ErrDuplicateNodeID ¶
type ErrDuplicateNodeID string
func (ErrDuplicateNodeID) Error ¶
func (e ErrDuplicateNodeID) Error() string
type ErrInvalidInput ¶
func (ErrInvalidInput) Error ¶
func (e ErrInvalidInput) 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 ErrMultipleTypes ¶
type ErrMultipleTypes string
func (ErrMultipleTypes) Error ¶
func (e ErrMultipleTypes) Error() string
type ErrNotFound ¶
type ErrNotFound string
func (ErrNotFound) Error ¶
func (e ErrNotFound) Error() string
type ErrUnknownOperator ¶
type ErrUnknownOperator struct {
Operator string
}
func (ErrUnknownOperator) Error ¶
func (e ErrUnknownOperator) 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 LDMarshaler ¶
type LDMarshaler struct { // If set, generates node identifiers from the given node. It should // be able to generate blank node IDs if the node is to be // represented as an RDF blank node, or if the node does not have an // ID. // // If not set, the default generator function uses the string node // id, or _b:<n> if the node does not have an id. NodeIDGeneratorFunc func(Node) string // If set, generates edge labels for the given edge. If it is not set, // the default is to use the edge label. If edge does not have a // label, EdgeLabelGeneratorFunc func(Edge) string }
LDMarshaler renders a graph in JSON-LD flattened format
func (*LDMarshaler) Marshal ¶
func (rd *LDMarshaler) Marshal(input *digraph.Graph) interface{}
type Layer ¶
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 UnmarshalLayer ¶
UnmarshalLayer unmarshals a schema ar overlay
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) GetAttributePath ¶
GetPath returns the path to the given attribute node
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) GetLayerInfoNode ¶
GetLayerInfoNode 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) GetTargetType ¶
GetTargetType returns the value of the targetType field from the layer information node
func (*Layer) NewNode ¶
NewNode creates a new node for the layer with the given ID and types, and adds the node to the layer
func (*Layer) RenameBlankNodes ¶
RenameBlankNodes will call namerFunc for each blank node, so they can be renamed and won't cause name clashes
func (*Layer) SetLayerType ¶
SetLayerType sets if the layer is a schema or an overlay
func (*Layer) SetTargetType ¶
SetTargetType sets the targe types of the layer
type Node ¶
type Node interface { digraph.Node // Return the types of the node GetTypes() *Types // Return node ID GetID() string // Set node ID SetID(string) // Clone returns a new node that is a copy of this one, but the // returned node is not connected Clone() Node // Value of the document node, nil if the node is not a document node GetValue() interface{} SetValue(interface{}) GetIndex() int SetIndex(int) // GetProperties returns the name/value pairs of the node. The // values are either string or []string. When cloned, the new node // receives a deep copy of the map GetProperties() map[string]*PropertyValue // Returns the compiled data map. This map is used to store // compilation information related to the node, and its contents are // unspecified. If the node is cloned with compiled data map, the // new node will get a shallow copy of the compiled data GetCompiledDataMap() map[interface{}]interface{} }
Node is the node type used for schema layer graphs
func InstanceOf ¶
InstanceOf returns the transitive closure of all the nodes that are connect to this node via instanceOf term,
type NodeCompiler ¶
type NodeCompiler interface { // CompileNode gets a node and compiles the associated term on that // node. It should store the compiled state into node.Compiled with // the an opaque key CompileNode(Node) error }
NodeCompiler interface represents term compilation algorithm when the term is a node.
During schema compilation, if a node is found to be a semantic annotation node (i.e. not an attribute node), and if the term metadata for the node label implements NodeCompiler, this function is called to compile the node.
func GetNodeCompiler ¶
func GetNodeCompiler(term string) NodeCompiler
GetNodeCompiler return a compiler that will compile the term when the term is a node label
type NodeSet ¶
type NodeSet struct {
// contains filtered or unexported fields
}
NodeSet is a set of nodes
func NewNodeSet ¶
NewNodeSet constructs a new nodeset from the given nodes
type NopFilter ¶
type NopFilter struct{}
NopFilter does not modify the underlying value
func (NopFilter) FilterValue ¶
type PropertyValue ¶
type PropertyValue struct {
// contains filtered or unexported fields
}
PropertyValue can be a string or []string. It is an immutable value object
func IntPropertyValue ¶
func IntPropertyValue(i int) *PropertyValue
IntPropertyValue converts the int value to string, and returns a string value
func ListAppend ¶
func ListAppend(v1, v2 *PropertyValue) *PropertyValue
ListAppend appends v2 and v1
func SetUnion ¶
func SetUnion(v1, v2 *PropertyValue) *PropertyValue
SetUnion computes the set union of properties v1 and v2
func StringPropertyValue ¶
func StringPropertyValue(s string) *PropertyValue
StringPropertyValue creates a string value
func StringSlicePropertyValue ¶
func StringSlicePropertyValue(s []string) *PropertyValue
StringSlicePropertyValue creates a []string value. If s is nil, it creates an empty slice
func (*PropertyValue) AsInt ¶
func (p *PropertyValue) AsInt() int
AsInt attempts to return the underlying string value as integer
func (*PropertyValue) AsInterfaceSlice ¶
func (p *PropertyValue) AsInterfaceSlice() []interface{}
AsInterfaceSlice returns an interface slice of the underlying value if it is a []string
func (*PropertyValue) AsString ¶
func (p *PropertyValue) AsString() string
AsString returns the value as string
func (*PropertyValue) AsStringSlice ¶
func (p *PropertyValue) AsStringSlice() []string
AsStringSlice returns the value as string slice
func (PropertyValue) Clone ¶
func (p PropertyValue) Clone() *PropertyValue
func (*PropertyValue) Equal ¶
func (p *PropertyValue) Equal(v *PropertyValue) bool
Equal compares two property values, and returns true if they are equal
func (*PropertyValue) Has ¶
func (p *PropertyValue) Has(s string) bool
Has checks if p has the given string or is equal to it
func (*PropertyValue) IsInt ¶
func (p *PropertyValue) IsInt() bool
Returns true if the underlying value is a string, and that string can be converted to int
func (*PropertyValue) IsString ¶
func (p *PropertyValue) IsString() bool
IsString returns true if the underlying value is a string
func (*PropertyValue) IsStringSlice ¶
func (p *PropertyValue) IsStringSlice() bool
IsStringSlice returns true if the underlying value is a string slice
func (PropertyValue) String ¶
func (p PropertyValue) String() string
type SchemaManifest ¶
type SchemaManifest struct { ID string Type string TargetType string Bundle string Schema string Overlays []string }
SchemaManifest contains the minimal information to define a schema variant with an optional bundle
func UnmarshalSchemaManifest ¶
func UnmarshalSchemaManifest(in interface{}) (*SchemaManifest, error)
Unmarshals the given jsonld document into a schema manifest
func (*SchemaManifest) GetID ¶
func (m *SchemaManifest) GetID() string
GetID returns the schema manifest ID
type TermCompiler ¶
type TermCompiler interface { // CompileTerm gets a term and its value, and returns an object that // will be placed in the Compiled map of the node or the edge. CompileTerm(string, *PropertyValue) (interface{}, error) }
TermCompiler interface represents term compilation algorithm. This is used to compile terms stored as node/edge properties. If the term metadata implements TermCompiler, this method is called, and the result is stored in the Compiled map of the node/edge with the term as the key.
func GetTermCompiler ¶
func GetTermCompiler(term string) TermCompiler
GetTermCompiler return a compiler that will compile the term when the term is a node/edge property
type TermSemantics ¶
type TermSemantics struct { // The term Term string `json:"term" yaml:"term"` // If true, the term value is an @id (IRI). In JSON-LD, the values for // this term will be marshalled as @id IsID bool `json:"isId" yaml:"isId"` // If true, the term is a list. In JSON-LD, its elements will be // marshaled under @list IsList bool `json:"isList" yaml:"isList"` Composition CompositionType `json:"composition,omitempty" yaml:"composition,omitempty"` Metadata interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty"` }
TermSemantics is used to describe how a term operates within the layered schemas framework.
func GetTermInfo ¶
func GetTermInfo(term string) TermSemantics
func (TermSemantics) Compose ¶
func (t TermSemantics) Compose(target, src *PropertyValue) (*PropertyValue, error)
type Types ¶
type Types struct {
// contains filtered or unexported fields
}
Types is a set of strings for representing node types
func CombineNodeTypes ¶
CombineNodeTypes returns a combination of the types of all the given nodes
func (*Types) Add ¶
Add adds new types. The result is the set-union of the existing types and the given types
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 ValueFilter ¶
type ValueFilter interface {
FilterValue(interface{}, Node) interface{}
}
A ValueFilter applies a filter to the node value
func GetValueFilter ¶
func GetValueFilter(term string) ValueFilter
GetValueFilter returns the value filter for the term. If the term has none, returns NopFilter
type Walk ¶
type Walk struct {
// contains filtered or unexported fields
}
A Walk specifies an edge-node-edge-node... predicate sequence. The predicates alter, it starts with an edge predicate, and then follows a node predicate, edge predicate, etc. In the end, the walk specifies all the nodes selected by the paths defined by the edge-node predicates.