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 DecodeElementID(id string) (string, bool)
- func EncodeElementID(qualifiedName string) string
- func LocalName(iri string) string
- 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
- func Bool(value bool) Term
- func ElementIRI(qualifiedName 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 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#" // 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:" // 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, }
DefaultPrefixes are the prefix bindings written on every serialized graph.
Functions ¶
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 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 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 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: 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 ExpressionIRI ¶ added in v0.2.0
ExpressionIRI returns the IRI of one node of an expression graph: the local id of the term it hangs off — an element or an outer subexpression — followed by the path to this node, so every node's identity is derived from where it sits in the model rather than minted.
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.
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. |