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 APIJSONToSysML(data []byte, warn func(string)) ([]byte, error)
- func DeclarationNames(file *source.SourceFile, root *ast.RootNamespace) (map[source.Span]string, error)
- func DerivedSatellite(metaclass string) bool
- func Destination(path string) (target string, info os.FileInfo, err error)
- func IsPositionalIdentity(name string) bool
- func IsSourceRangeProperty(iri string) bool
- func LibraryReference(graph *rdf.Graph, subject rdf.Term) bool
- func ModelToRDFWith(documents []ModelDocument, form IDForm) (*rdf.Graph, error)
- func NormativeSubject(id, qualifiedName string) bool
- func PositionalIdentities(index *symbols.Index, docs []PositionalDocument, ...) (map[*symbols.Symbol]string, map[string]*symbols.Symbol)
- 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 ToSysMLWarn(graph *rdf.Graph, warn func(string)) ([]byte, error)
- func WriteAPIJSON(graph *rdf.Graph) ([]byte, error)
- func WriteFile(path string, data []byte) (replaced bool, err error)
- type APIJSONReadError
- type ElementIDs
- type IDForm
- type ModelDocument
- type PositionalDocument
- type Staged
- type UnsupportedError
Constants ¶
const AnnotationSuffix = "_an"
AnnotationSuffix names the Annotation by which a dependency owns a prefix metadata usage, after the usage it owns, as `_om` names a membership.
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 APIJSONToSysML ¶ added in v0.9.2
APIJSONToSysML reads an API element document and converts its owned graph.
func DeclarationNames ¶ added in v0.9.2
func DeclarationNames(file *source.SourceFile, root *ast.RootNamespace) (map[source.Span]string, error)
DeclarationNames maps declarations to their RDF qualified names by span. Unnamed declarations use the export's positional `@N` identity.
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 IsPositionalIdentity ¶ added in v0.9.2
IsPositionalIdentity reports whether a name contains a canonical `@N` segment.
func IsSourceRangeProperty ¶ added in v0.9.2
IsSourceRangeProperty reports whether iri is one of the four integers that place a declaration in its document: layout, which reading ignores.
func LibraryReference ¶ added in v0.9.2
LibraryReference reports whether subject names a library element the graph references rather than declares: it has no owner or owned relationships.
func ModelToRDFWith ¶ added in v0.9.2
func ModelToRDFWith(documents []ModelDocument, form IDForm) (*rdf.Graph, error)
ModelToRDFWith converts the documents of one model to a single graph. They are analyzed together, as a workspace analyzes them, and a reference from one document to an element another declares links the subject that document writes for it, as a reference within one document does. Each document's root elements name it (sysx:sourceDocument), since one graph no longer keeps the documents apart.
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 PositionalIdentities ¶ added in v0.9.2
func PositionalIdentities(index *symbols.Index, docs []PositionalDocument, identifies func(*symbols.Symbol) bool) (map[*symbols.Symbol]string, map[string]*symbols.Symbol)
PositionalIdentities maps symbols without qualified identities to export names.
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 ToSysMLWarn ¶ added in v0.9.2
ToSysMLWarn converts a graph to notation and reports non-fatal resolutions.
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 APIJSONReadError ¶ added in v0.9.2
type APIJSONReadError struct {
// contains filtered or unexported fields
}
APIJSONReadError reports a failure to parse an API element document.
func (*APIJSONReadError) Error ¶ added in v0.9.2
func (e *APIJSONReadError) Error() string
func (*APIJSONReadError) Unwrap ¶ added in v0.9.2
func (e *APIJSONReadError) Unwrap() error
type ElementIDs ¶ added in v0.9.2
type ElementIDs struct {
// contains filtered or unexported fields
}
ElementIDs reports the elementId a conversion of a model writes for each of its elements, in the qualified id form. It is read from that conversion itself — ToRDF for one document, modelToRDF (ModelToRDFWith) for several, the paths Convert takes — so a library file's copy, a declared id and scope qualification come out as they are written, and a model the conversion refuses has no ids at all.
func NewElementIDs ¶ added in v0.9.2
func NewElementIDs(documents []ModelDocument) (*ElementIDs, error)
NewElementIDs converts the documents of one model and records the elementId written for each element by its qualified (or positional) name. The error is the conversion's: a model Convert refuses has no elementIds to report.
func NewElementIDsOfDocument ¶ added in v0.9.2
func NewElementIDsOfDocument(name string, data []byte) (*ElementIDs, error)
NewElementIDsOfDocument is NewElementIDs for a model of one document, which is converted from its text as a conversion of one document is: parsed afresh, in the language its name gives it, then written alone (ToRDF). A document the parser cannot read whole converts to nothing, so it is refused.
func (*ElementIDs) Of ¶ added in v0.9.2
func (ids *ElementIDs) Of(fqn string) (string, bool)
Of is the elementId written for the element named fqn: the model's own as the conversion wrote it, or, for a standard library element the model does not declare, the normative id every reference to it carries. False where the conversion writes none, as for a library element a model annotates with an id of its own, whose references are written by name.
func (*ElementIDs) OfDeclaration ¶ added in v0.9.2
OfDeclaration is the elementId written for the element declared at decl, named fqn: the one its own declaration was written with where the conversion encoded that node, else Of(fqn). Two identity scopes may declare one qualified name, and the declaration tells their ids apart where the name cannot.
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 ModelDocument ¶ added in v0.9.2
type ModelDocument struct {
File *source.SourceFile
Root *ast.RootNamespace
}
ModelDocument is one parsed document of a model converted as a whole.
type PositionalDocument ¶ added in v0.9.2
type PositionalDocument struct {
File *source.SourceFile
Root *symbols.Scope
}
PositionalDocument pairs a source file with the scope containing its symbols.
type Staged ¶ added in v0.9.2
type Staged struct {
// contains filtered or unexported fields
}
Staged is a file written beside its destination but not yet renamed over it, so a set of files can be committed together or discarded.
func Stage ¶ added in v0.9.2
Stage writes data to a temporary file beside path, ready to Commit; path must be absent or a regular file, as there is nothing else to rename over.
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
Source Files
¶
- api_json_in.go
- api_json_out.go
- behavior.go
- doc.go
- element_ids.go
- end_forms.go
- id_form.go
- kinds.go
- library_names.go
- names.go
- names_identity.go
- positional.go
- precedence.go
- rdf_expr.go
- rdf_identity.go
- rdf_in.go
- rdf_in_normative.go
- rdf_in_toolkit.go
- rdf_normative.go
- rdf_out.go
- root_namespace.go
- source_text.go
- verbatim.go
- write.go