Documentation
¶
Overview ¶
Package export saves a SysML v2 model to a file and converts between the two representations OpenSysML can write: SysML textual notation and RDF Turtle. It also reads a third, SysML v1 in XMI, which is migrated to v2 notation on the way in.
SysML output ¶
Saving a model that came from source writes that source, re-indented by internal/syntax/format. Printing the AST instead would drop comments, notes and anything the parser recorded as an ErrorNode, so a save has to keep the token stream (see the format package doc).
RDF output ¶
The graph uses the SysML vocabulary and element IRIs of the Flexo MMS SysML v2 service (https://www.omg.org/spec/SysML# and urn:sysmlv2:element:), so a converted model loads into that service's triplestore. Elements are addressed by qualified name (`urn:sysmlv2:element:Demo::Vehicle`), which makes the IRIs stable across conversions of the same model rather than newly generated each time.
Each element carries its metaclass as rdf:type and its declaration as SysML metamodel properties: declaredName, declaredShortName, owningNamespace, visibility, direction, the feature flags, the typing and specialization clauses, multiplicity bounds and its value; expression-valued positions are expression trees. Properties the metamodel does not define live in a separate urn:opensysml:sysml: namespace so a consumer can tell them from the standard vocabulary: memberIndex (declaration order, which the notation is sensitive to and RDF is not), hasBody, the end forms of heads that bind ends, and each element's lines as written, comments included, as sourceText and sourceTail.
XMI input ¶
SysML v1 as UML XMI (OMG XMI 2.5.1, the Eclipse UML2 .uml serialization Papyrus writes, or a .mdzip archive holding it) is migrated to v2 notation by internal/translate/migrate, then takes the notation path. XMI is never written.
RDF back to notation ¶
The structural triples are authoritative. An element is written from its source text while that text still states what the graph states — so comments and layout survive a round trip of an unedited model — and canonically where the two disagree or the graph carries no text, as one from another tool does not. docs/reference/rdf-mapping.md documents the mapping and its limitations.
Index ¶
- Constants
- func DerivedSatellite(metaclass string) bool
- func Destination(path string) (target string, info os.FileInfo, err error)
- func NormativeSubject(id, qualifiedName string) bool
- func ReadAPIJSON(data []byte) (*rdf.Graph, error)
- func ToRDF(file *source.SourceFile, root *ast.RootNamespace) (*rdf.Graph, error)
- func ToRDFWith(file *source.SourceFile, root *ast.RootNamespace, form IDForm) (*rdf.Graph, error)
- func ToSysML(graph *rdf.Graph) ([]byte, error)
- func WriteAPIJSON(graph *rdf.Graph) ([]byte, error)
- func WriteFile(path string, data []byte) (replaced bool, err error)
- type IDForm
- type UnsupportedError
Constants ¶
const RootNamespaceSuffix = "_ns"
RootNamespaceSuffix ends the id of the unnamed Namespace that owns a document's top-level elements in the API element form. An encoded id never ends in a lone '_', so the id collides with no element's or membership's.
Variables ¶
This section is empty.
Functions ¶
func DerivedSatellite ¶
DerivedSatellite reports whether metaclass is one the encoder derives from its side tables rather than a declaration — the materialized relationship elements, a conjugated port definition and its conjugation, a multiplicity range, or the membership relating an expression to its referent. A member element of such a metaclass carries a qualified name and stays addressable.
func Destination ¶
Destination returns the file a save should write and what is there now, which is nil when nothing is. A symlink resolves to what it points at, so saving over a linked model updates the model instead of unlinking it; a link that resolves to nothing is written where it points.
func NormativeSubject ¶
NormativeSubject reports whether id is the id the norm fixes for the subject a graph names qualifiedName: the library element the encoder writes under that name, or its owning membership, which names nothing. A user element that carries a library uuid is not the library element, so its id stays its own.
func ReadAPIJSON ¶
ReadAPIJSON parses the SysML v2 API's element form — a JSON array of element objects, or a single element object — into the same graph ParseTurtle yields: the "@type" and "@id" of each object and each metamodel key in document order. It is the inverse of WriteAPIJSON, so a graph it builds writes the same elements back; the unnamed root Namespace a document wraps its top-level elements in is dropped, as the Turtle form does not carry it.
func ToRDF ¶
func ToRDF(file *source.SourceFile, root *ast.RootNamespace) (*rdf.Graph, error)
ToRDF converts a parsed document into an RDF graph. file must be the source the tree was parsed from: every element and expression carries the notation it was written as alongside its structural triples, so the conversion needs the bytes as well as the tree.
func ToRDFWith ¶
func ToRDFWith(file *source.SourceFile, root *ast.RootNamespace, form IDForm) (*rdf.Graph, error)
ToRDFWith is ToRDF with the id form the caller asks for.
func ToSysML ¶
ToSysML converts an RDF graph back into SysML v2 source text. An element comes back as its sysx:sourceText, byte for byte, while that still states what the graph states, and in canonical notation otherwise.
A subject whose metaclass this mapping does not know, or which lacks the properties needed to rebuild its declaration, is reported as an UnsupportedError: a converted file that dropped an element would be worse than a failed conversion.
func WriteAPIJSON ¶
WriteAPIJSON serializes a graph as the SysML v2 API's element form: a JSON array of objects carrying "@type", "@id" and the metamodel properties as keys, the shape GET /projects/{p}/commits/{c}/elements serves. It is the same mapping the Turtle writer spells: the subjects of the graph in order, their sysml: and sysx: properties as values, each collection as the array its json: annotation states, and each multi-valued metamodel property as an array even when no annotation states it. The document's top-level elements are owned by the unnamed root Namespace the pilot's documents carry, which the Turtle form leaves out (see docs/reference/rdf-mapping.md).
func WriteFile ¶
WriteFile writes a converted model to path, reporting whether it replaced a file that was already there.
A regular file is written atomically: the bytes go to a temporary file in the same directory, are flushed, and are renamed over the destination, so an interrupted write leaves the previous model intact rather than a truncated or empty one. An existing file keeps its permissions, and a symlink is written through rather than replaced.
Anything that is not a regular file — a terminal, a pipe, /dev/null, a process substitution — is written directly, since there is no previous content to protect and replacing it by rename would destroy the pipe or device the user pointed at.
Types ¶
type IDForm ¶
type IDForm int
IDForm is how the encoder spells the derived ids of elements, memberships and expression nodes that no ElementId annotation declares.
const ( // IDQualifiedName derives each id from the element's qualified name, so an // id reads where its element sits in the model. The default. IDQualifiedName IDForm = iota // IDUUID derives each id as a name-based uuid the way the SysML v2 library // convention does: the model's package namespace is // uuid5(NamespaceURL, elementIRI(root)), and every derived id under it is // uuid5(pkg, the qualified-name-derived local id it otherwise carries). IDUUID )
func ParseIDForm ¶
ParseIDForm reads the -id flag's argument.
type UnsupportedError ¶
UnsupportedError reports a construct the conversion cannot represent. It names the element so the user can find it, rather than converting a model that silently lost part of itself.
func (*UnsupportedError) Error ¶
func (e *UnsupportedError) Error() string