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 LocalName(iri string) string
- func QualifiedNameOf(iri string) (string, bool)
- func WriteTurtle(g *Graph) []byte
- 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) 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
- 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#" // 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:" // 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 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, }
DefaultPrefixes are the prefix bindings written on every serialized graph.
Functions ¶
func LocalName ¶
LocalName returns the part of iri after the last '#', '/' or ':' — the metaclass or property name for a vocabulary IRI. An element IRI returns the whole qualified name it encodes, since the segments of a qualified name are one name and not a path.
func QualifiedNameOf ¶
QualifiedNameOf reverses ElementIRI, returning the qualified name an element IRI encodes and whether iri is in the element namespace at all.
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 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 (*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) 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 ElementIRI ¶
ElementIRI returns the element IRI for a fully-qualified SysML name. Qualified names are kept legible (`urn:sysmlv2:element:Demo::Vehicle`) and only the characters an IRI cannot carry are percent-escaped, so the IRI is deterministic and reversible.
func OpenSysMLTerm ¶
OpenSysMLTerm returns the IRI of a name in the OpenSysML extension namespace.
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.