Documentation
¶
Overview ¶
Package rdf provides the minimal RDF graph model, Turtle writer and Turtle reader that the SysML v2 ↔ RDF conversion in internal/core/export is built on.
The model is deliberately small: an ordered list of triples over IRIs and literals. Blank nodes, RDF collections and named graphs are not represented at all, so a Turtle document that uses them is rejected with a diagnostic rather than silently losing data — a converted model that quietly dropped statements would be worse than one that refused to convert.
Index ¶
- Constants
- Variables
- func AnnotateCollections(g *Graph) error
- func CollectionJSON(subject Term, values []Term) (string, error)
- func DecodeElementID(id string) (string, bool)
- func DecodeExpressionNodeID(id string) (string, []string, bool)
- func DecodeOwningMembershipID(id string) (string, bool)
- func EncodeElementID(qualifiedName string) string
- func ExpressionNodeID(owner, position string) string
- func IsAnnotationJSON(iri string) bool
- func LocalName(iri string) string
- func OwningMembershipID(memberQualifiedName string) string
- func ReferenceID(subject, target Term) string
- func ScopeQualifier(org, projectID string) string
- func ValueJSON(subject, value Term) (string, error)
- func WriteTurtle(g *Graph) []byte
- type AnnotationError
- type CollectionConflictError
- type CollectionMember
- type Graph
- func (g *Graph) Add(subject, predicate, object Term)
- func (g *Graph) AddTriple(t Triple)
- func (g *Graph) BoolValue(subject Term, predicate string) bool
- func (g *Graph) Has(t Triple) bool
- func (g *Graph) HasProperty(subject Term, predicate string) bool
- func (g *Graph) Len() int
- func (g *Graph) Lexical(subject Term, predicate string) (string, bool)
- func (g *Graph) Object(subject Term, predicate string) (Term, bool)
- func (g *Graph) Objects(subject Term, predicate string) []Term
- func (g *Graph) Subjects() []Term
- func (g *Graph) Triples() []Triple
- func (g *Graph) Type(subject Term) string
- type ParseError
- type Term
- func AnnotationJSONTerm(key string) Term
- func Bool(value bool) Term
- func ElementIRI(qualifiedName string) Term
- func ElementIRIForID(id string) Term
- func ExpressionIRI(owner Term, path string) Term
- func IRI(iri string) Term
- func Int(value int) Term
- func OpenSysMLTerm(name string) Term
- func OwningMembershipIRI(qualifiedName string) Term
- func OwningMembershipIRIOf(member Term) Term
- func ReferenceIRI(subject Term, id string) Term
- func ScopedElementIRIForID(qualifier, id string) Term
- func String(value string) Term
- func SysMLTerm(name string) Term
- func TypedLiteral(value, datatype string) Term
- type TermKind
- type Triple
Constants ¶
const ( // RDFNS is the RDF syntax namespace. RDFNS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" // XSD is the XML Schema datatype namespace. XSD = "http://www.w3.org/2001/XMLSchema#" // OWL is the Web Ontology Language namespace; the SysML ontology types a // LiteralRational's value owl:real. OWL = "http://www.w3.org/2002/07/owl#" // SysML is the OMG SysML vocabulary namespace, used for metaclasses and // metamodel properties. SysML = "https://www.omg.org/spec/SysML#" // Element is the base IRI for the elements of a converted model. Element = "urn:sysmlv2:element:" // OpenSysML namespaces the few properties this tool needs that the SysML // metamodel does not define: declaration order, and the source text of // expressions. They are namespaced separately so a consumer can tell our // additions from the standard vocabulary and ignore them. OpenSysML = "urn:opensysml:sysml:" // Expression is the base IRI for the nodes of an expression graph: the // subexpressions of a value, bound, guard or condition, which are elements // of the abstract syntax without a qualified name of their own. Expression = "urn:opensysml:expr:" // AnnotationJSON is the namespace of the JSON literals Flexo reads a collection // from (ANNOTATION_JSON in Namespaces.kt); <AnnotationJSON><key> holds the array. AnnotationJSON = "urn:sysmlv2:annotation:json:" // LegacyExtension is the extension namespace this tool wrote before the // project was renamed. It is recognized only so a graph carrying it can be // refused rather than read as if its properties were absent. LegacyExtension = "urn:systemica:sysml:" )
Namespace IRIs. The SysML vocabulary, element base and prefix labels match the ones the Flexo MMS SysML v2 service writes into its triplestore (Namespaces.kt), so a graph produced here loads into that service and a graph read out of it converts back to source here.
const ExpressionPrefix = "expr"
ExpressionPrefix is the prefix label bound to the expression namespace. It is written only on a graph that carries an expression graph.
const RDFType = RDFNS + "type"
RDFType is the rdf:type predicate IRI.
Variables ¶
var DefaultPrefixes = map[string]string{ "rdf": RDFNS, "xsd": XSD, "sysml": SysML, "elmt": Element, "sysx": OpenSysML, "json": AnnotationJSON, }
DefaultPrefixes are the prefix bindings written on every serialized graph. The labels match the service's own prefix mapping.
Functions ¶
func AnnotateCollections ¶ added in v0.5.0
AnnotateCollections adds the annotation literal for every sysml: property a subject states more than once, in triple order; an annotation already present is kept.
func CollectionJSON ¶ added in v0.5.0
CollectionJSON spells the values of subject as the service stores a collection: a JSON array of {"@id": <id>} references and typed primitives.
func DecodeElementID ¶ added in v0.1.1
DecodeElementID reverses EncodeElementID, reporting whether id is a well-formed encoding. A malformed escape, a byte outside [A-Za-z0-9_-] or an invalid UTF-8 result is rejected rather than guessed at.
func DecodeExpressionNodeID ¶ added in v0.3.0
DecodeExpressionNodeID reverses ExpressionNodeID, returning the qualified name of the element the node belongs to and the positions leading down to it. An encoded id can hold `_p` itself — `::p` encodes to `__p` — so the owner is the shortest prefix before a separator that is a well-formed id on its own; a `_p` inside an encoded id leaves a prefix ending in a lone '_', which never is.
func DecodeOwningMembershipID ¶ added in v0.3.0
DecodeOwningMembershipID reverses OwningMembershipID, returning the qualified name of the member the membership owns.
func EncodeElementID ¶ added in v0.1.1
EncodeElementID encodes a qualified name as an element id in [A-Za-z0-9_-]+: `::` becomes `__`, a byte in [A-Za-z0-9-] stands for itself, and every other byte — a literal '_' included — becomes '_' plus two lowercase hex digits.
func ExpressionNodeID ¶ added in v0.3.0
ExpressionNodeID returns the id of the expression node at position under the element or outer node with id owner. Positions nest, so the ids compose, and the result stays in [A-Za-z0-9_-]+ so a consumer restricting ids to that can address the node.
func IsAnnotationJSON ¶ added in v0.5.0
IsAnnotationJSON reports whether iri is a collection annotation predicate.
func LocalName ¶
LocalName returns the part of iri after the last '#', '/' or ':' — the metaclass or property name for a vocabulary IRI, or the encoded id for an element IRI.
func OwningMembershipID ¶ added in v0.3.0
OwningMembershipID returns the id of the OwningMembership that owns the member with the given qualified name. The membership sits between exactly one namespace and one member, so the member's own identity determines it.
func ReferenceID ¶ added in v0.5.0
ReferenceID spells target as the @id of a member of subject: the bare id within the subject's project scope, `<qualifier>:<id>` across scopes (an empty qualifier being the unscoped root), so the id alone names the target exactly.
func ScopeQualifier ¶ added in v0.4.3
ScopeQualifier encodes a project scope as an IRI-safe qualifier. '.' never appears in an encoded id, so distinct scopes give distinct qualifiers.
func ValueJSON ¶ added in v0.5.0
ValueJSON spells one value of subject as a collection member; two spellings compare by it.
func WriteTurtle ¶
WriteTurtle serializes g as a Turtle document: the prefix bindings the graph carries, then one block per subject in insertion order, with the subject's predicates grouped and separated by ';'.
Types ¶
type AnnotationError ¶ added in v0.5.0
type AnnotationError struct {
Subject string // subject IRI
Key string // property key: the annotation predicate's local name
Note string
}
AnnotationError is a collection annotation the reader cannot take as a collection: not exactly one literal, not the JSON array the service stores, or an array that repeats a member, which no set of triples can hold.
func (*AnnotationError) Error ¶ added in v0.5.0
func (e *AnnotationError) Error() string
type CollectionConflictError ¶ added in v0.5.0
type CollectionConflictError struct {
Subject string // subject IRI
Key string // property key: the local name of the sysml: predicate
Triples []string // members as the typed triples state them, as JSON
Annotation []string // members as the annotation states them, as JSON
}
CollectionConflictError is a collection stated as typed triples and as a JSON annotation with different members; the reader refuses rather than pick one.
func (*CollectionConflictError) Error ¶ added in v0.5.0
func (e *CollectionConflictError) Error() string
type CollectionMember ¶ added in v0.5.0
type CollectionMember struct {
ID string // @id of a reference member, as ReferenceID spells it; empty for a literal
Literal Term // typed literal of a primitive member
}
CollectionMember is one parsed annotation member: a reference by id, or a literal.
func ParseCollectionJSON ¶ added in v0.5.0
func ParseCollectionJSON(text string) ([]CollectionMember, error)
ParseCollectionJSON reads a collection annotation: a JSON array of {"@id": …} objects and primitives, which is all the service stores.
func (CollectionMember) JSON ¶ added in v0.5.0
func (m CollectionMember) JSON() (string, error)
JSON spells the member back as it stands in the annotation.
type Graph ¶
type Graph struct {
// Prefixes maps prefix label to namespace IRI for serialization. It never
// affects the meaning of the graph.
Prefixes map[string]string
// contains filtered or unexported fields
}
Graph is an ordered set of triples. Insertion order is preserved so that a serialized document is stable, and duplicates are dropped so that repeated conversion of the same model is idempotent.
func NewGraph ¶
func NewGraph() *Graph
NewGraph returns an empty graph carrying the SysML prefix bindings.
func ParseTurtle ¶
ParseTurtle reads the subset of Turtle that WriteTurtle emits: @prefix and @base directives, IRI and prefixed-name terms, quoted literals with optional datatype or language tag, the `a` keyword, and the ';' and ',' groupings.
Blank nodes ('[]', '_:x'), collections ('( ... )') and the numeric and boolean literal shorthands are rejected rather than approximated: this reader exists to convert a graph back into source, and a construct it cannot represent has to surface as an error instead of a silently smaller model.
func ReconcileCollections ¶ added in v0.5.0
ReconcileCollections returns a graph whose sysml: triples state every annotated collection in annotation order: materialized if annotation-only, checked if both. A graph without annotations is returned as it is.
func (*Graph) BoolValue ¶
BoolValue returns the boolean value of (subject, predicate), defaulting to false when absent. Any lexical form other than "true" or "1" is false, which matches the way the exporter only ever writes true.
func (*Graph) HasProperty ¶ added in v0.3.0
HasProperty reports whether the subject states the predicate at all.
func (*Graph) Lexical ¶
Lexical returns the lexical form of the first object of (subject, predicate), for a property whose value is read as text regardless of whether it was written as an IRI or a literal.
func (*Graph) Object ¶
Object returns the first object of (subject, predicate) and whether one exists. A property the mapping treats as single-valued is read with this.
func (*Graph) Objects ¶
Objects returns the objects of every (subject, predicate) statement, in insertion order.
type ParseError ¶
ParseError reports the line at which a Turtle document could not be read.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type Term ¶
type Term struct {
Kind TermKind
// Value is the IRI for TermIRI, or the lexical form for TermLiteral.
Value string
// Datatype is the datatype IRI of a literal. Empty means xsd:string for a
// plain literal, and is always empty when Lang is set.
Datatype string
// Lang is the BCP 47 language tag of a literal, empty when untagged.
Lang string
}
Term is one RDF node: an IRI or a literal.
func AnnotationJSONTerm ¶ added in v0.5.0
AnnotationJSONTerm returns the annotation predicate carrying key's collection.
func ElementIRI ¶
ElementIRI returns the element IRI for a fully-qualified SysML name: the element namespace followed by EncodeElementID of the name, so the id after the last ':' is readable, deterministic, and valid for a consumer that restricts ids to [A-Za-z0-9_-]+.
func ElementIRIForID ¶ added in v0.4.3
ElementIRIForID returns the element IRI carrying an effective id directly: an annotated id when the element declares one, an encoded name otherwise.
func ExpressionIRI ¶ added in v0.2.0
ExpressionIRI returns the IRI of one node of an expression graph: the id of the term it hangs off — an element or an outer subexpression — with the position it holds, so its identity comes from where it sits in the model rather than being minted, and its id is valid where an element id is.
func OpenSysMLTerm ¶
OpenSysMLTerm returns the IRI of a name in the OpenSysML extension namespace.
func OwningMembershipIRI ¶ added in v0.3.0
OwningMembershipIRI returns the IRI of the OwningMembership through which a namespace owns the member named by qualifiedName. It is in the element namespace, since a membership is an element of the abstract syntax in its own right, and its id can never collide with an element's.
func OwningMembershipIRIOf ¶ added in v0.4.3
OwningMembershipIRIOf derives the membership IRI from the member's own subject IRI, so it inherits the member's effective id and scope qualifier.
func ReferenceIRI ¶ added in v0.5.0
ReferenceIRI is the element IRI an @id names from subject: the scope it spells, else the subject's own.
func ScopedElementIRIForID ¶ added in v0.4.3
ScopedElementIRIForID qualifies an element IRI with its project scope, for a graph carrying more than one scope, whose ids may legitimately repeat across scopes. The id still follows the last ':', so LocalName returns it.
func SysMLTerm ¶
SysMLTerm returns the IRI of a name in the SysML vocabulary, used for both metaclasses (`sysml:PartUsage`) and properties (`sysml:declaredName`).
func TypedLiteral ¶
TypedLiteral returns a literal with an explicit datatype IRI.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ontology holds the SysML v2 metamodel term table generated from the Open-MBEE OWL rendering, plus the domain/range check built on it.
|
Package ontology holds the SysML v2 metamodel term table generated from the Open-MBEE OWL rendering, plus the domain/range check built on it. |
|
gen
command
Command gen writes internal/core/rdf/ontology/table.go from a local checkout of https://github.com/Open-MBEE/sysmlv2-rdf-ontology, which is not vendored here.
|
Command gen writes internal/core/rdf/ontology/table.go from a local checkout of https://github.com/Open-MBEE/sysmlv2-rdf-ontology, which is not vendored here. |