Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated vocab and shapes and added multi-valued property ordering #622

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
132 changes: 66 additions & 66 deletions specs/sysml/Resources/genVocabAndShapes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"# Initial imports and local methods\n",
"from rdflib import Graph, URIRef, Literal, Namespace, RDF, XSD, RDFS, OWL, DCTERMS\n",
"from rdflib import Graph, URIRef, Literal, Namespace, RDF, XSD, RDFS, OWL, DCTERMS, BNode\n",
"from pyecore.ecore import EClass, EAttribute, EReference, EString, EObject, EEnum\n",
"from pyecore.resources import ResourceSet, URI\n",
"from bs4 import BeautifulSoup\n",
Expand Down Expand Up @@ -77,7 +77,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -130,7 +130,16 @@
" s = oslc_sysmlv2.term(name)\n",
" g.add((s, RDF.type, RDF.Property))\n",
" g.add((s, RDFS.label, Literal(name)))\n",
" g.add((s, RDFS.comment, Literal(comment(a))))\n",
" # does the property already have a comment?\n",
" pcomment = g.value(s, RDFS.comment)\n",
" if pcomment is not None:\n",
" # This is a property with multiple domains\n",
" # Concatenate the comment for each domain class into a single comment\n",
" pcomment = pcomment + '\\n' + c.name+': '+comment(a)\n",
" g.remove((s, RDFS.comment, None))\n",
" g.add((s, RDFS.comment, Literal(pcomment)))\n",
" else:\n",
" g.add((s, RDFS.comment, Literal(c.name+': '+comment(a))))\n",
" g.add((s, RDFS.isDefinedBy, URIRef(oslc_sysmlv2)))\n",
" if isinstance(c, EEnum):\n",
" g.add((oslc_sysmlv2.term(c.name), RDF.type, RDFS.Class))\n",
Expand Down Expand Up @@ -173,7 +182,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -200,22 +209,41 @@
" case 'Integer': return XSD.integer\n",
" case _: return oslc_sysmlv2.term(a.eType.name)\n",
"\n",
"def addClassProperties(eclass, shape, graph):\n",
" # generate the properties specific to this ResourceShape\n",
" for a in eclass.eStructuralFeatures:\n",
" name = a.name # use the class name as a prefix to the attribute name to ensure they are unique\n",
" propval = BNode()\n",
" graph.add((shape, oslc.property, propval))\n",
"\n",
" # and create the oslc:Property elements defined by this EClass\n",
" graph.add((propval, RDF.type, oslc.Property))\n",
" graph.add((propval, oslc.name, Literal(name)))\n",
" graph.add((propval, oslc.occurs, multiplicity(a)))\n",
" graph.add((propval, oslc.propertyDefinition, URIRef(oslc_sysmlv2.term(name))))\n",
" graph.add((propval, oslc.readOnly, Literal('false',datatype=XSD.boolean)))\n",
" if isinstance(a, EReference):\n",
" graph.add((propval, oslc.valueType, oslc.Resource))\n",
" graph.add((propval, oslc.range, oslc_sysmlv2.term(a.eType.name)))\n",
" graph.add((propval, oslc.representation, oslc.Either))\n",
" elif isinstance(a, EAttribute):\n",
" graph.add((propval, oslc.range, valueType(a)))\n",
" graph.add((propval, DCTERMS.description, Literal(comment(a,strip=False), datatype=RDF.XMLLiteral)))\n",
"\n",
"\n",
"def addSuperclassProperties(eclass, shape, graph):\n",
" if eclass.eSuperTypes is not None and len(eclass.eSuperTypes) >= 1:\n",
" for super in eclass.eSuperTypes:\n",
" # recursively add the properties for the superclasses\n",
" addSuperclassProperties(super, shape, graph)\n",
" # and add the properties for this superclass\n",
" for a in super.eStructuralFeatures:\n",
" name = a.name # don't use the class name as a prefix to the attribute name to ensure they are unique\n",
" graph.add((shape, oslc.property, URIRef(oslc_sysml_shapes.term(name))))\n",
" addClassProperties(super, shape, graph)\n",
"\n",
" # some useful RDF namespaces\n",
"vann = Namespace('http://purl.org/vocab/vann/')\n",
"oslc = Namespace('http://open-services.net/ns/core#')\n",
"oslc_am = Namespace('http://open-services.net/ns/am#')\n",
"oslc_sysml_shapes = Namespace('https://www.omg.org/spec/SysML/shapes/20240801#') # OMG namespace versioned for constraints\n",
"oslc_sysml_shapes = Namespace('http://www.omg.org/spec/SysML/shapes/20240801#') # OMG namespace versioned for constraints\n",
"#oslc_sysml_shapes = Namespace('http://open-services.net/ns/sysmlv2/shapes/20240801#') # OASIS namespace\n",
"\n",
"oslc_sysmlv2 = Namespace('http://www.omg.org/spec/SysML/2.0#') # OMG namespace\n",
Expand Down Expand Up @@ -262,28 +290,8 @@
" g.add((shape, oslc.describes, URIRef(oslc_sysmlv2.term(c.name))))\n",
"\n",
" # add all the properties inherited from all superclasses up to Element\n",
" addSuperclassProperties(c, shape, g)\n",
"\n",
" # generate the properties specific to this ResourceShape\n",
" for a in c.eStructuralFeatures:\n",
" name = a.name # use the class name as a prefix to the attribute name to ensure they are unique\n",
" g.add((shape, oslc.property, URIRef(oslc_sysml_shapes.term(name))))\n",
"\n",
" # and create the oslc:Property elements defined by this EClass\n",
" s = oslc_sysml_shapes.term(name)\n",
" g.add((s, RDF.type, oslc.Property))\n",
" g.add((s, oslc.name, Literal(name)))\n",
" g.add((s, oslc.occurs, multiplicity(a)))\n",
" g.add((s, oslc.propertyDefinition, URIRef(oslc_sysmlv2.term(name))))\n",
" g.add((s, oslc.readOnly, Literal('false',datatype=XSD.boolean)))\n",
" if isinstance(a, EReference):\n",
" g.add((s, oslc.valueType, oslc.Resource))\n",
" g.add((s, oslc.range, oslc_sysmlv2.term(a.eType.name)))\n",
" g.add((s, oslc.representation, oslc.Either))\n",
" elif isinstance(a, EAttribute):\n",
" g.add((s, oslc.range, valueType(a)))\n",
" g.add((s, DCTERMS.description, Literal(comment(a,strip=False), datatype=RDF.XMLLiteral)))\n",
"\n",
" #addSuperclassProperties(c, shape, g)\n",
" addClassProperties(c, shape, g)\n",
"\n",
" # add the inherited oslc_am:Resource properties\n",
" g.add((shape, oslc.property, oslc_sysml_shapes.type))\n",
Expand Down Expand Up @@ -517,16 +525,16 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Graph identifier=N58639f80d4ca4d92b9b18c039b7dafba (<class 'rdflib.graph.Graph'>)>"
"<Graph identifier=N7ecb2e30740041a2bdd517297751cad5 (<class 'rdflib.graph.Graph'>)>"
]
},
"execution_count": 22,
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -549,7 +557,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 44,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -2560,7 +2568,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -2614,7 +2622,16 @@
" s = oslc_kerml.term(name)\n",
" g.add((s, RDF.type, RDF.Property))\n",
" g.add((s, RDFS.label, Literal(name)))\n",
" g.add((s, RDFS.comment, Literal(comment(a))))\n",
" pcomment = g.value(s, RDFS.comment)\n",
" if pcomment is not None:\n",
" # This is a property with multiple domains\n",
" # Concatenate the comment for each domain class into a single comment\n",
" pcomment = pcomment + '\\n' + c.name+': '+comment(a)\n",
" g.remove((s, RDFS.comment, None))\n",
" g.add((s, RDFS.comment, Literal(pcomment)))\n",
" else:\n",
" g.add((s, RDFS.comment, Literal(c.name+': '+comment(a))))\n",
" g.add((s, RDFS.isDefinedBy, URIRef(oslc_sysmlv2)))\n",
" g.add((s, RDFS.isDefinedBy, URIRef(oslc_kerml)))\n",
" if isinstance(c, EEnum):\n",
" g.add((oslc_kerml.term(c.name), RDF.type, RDFS.Class))\n",
Expand Down Expand Up @@ -2660,7 +2677,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -2684,13 +2701,13 @@
"g.add((s, RDFS.label, Literal(\"OSLC Kernel Modeling Language (KerML) Constraints\")))\n",
"g.add((s, DCTERMS.dateCopyrighted, Literal(\"2012-2024\")))\n",
"g.add((s, DCTERMS.description, Literal(\"<p>Constraints on vocabulary terms defined in the OSLC Kernel Modeling Language (KerML) namespace.</p>\", datatype=RDF.XMLLiteral)))\n",
"g.add((s, DCTERMS.hasVersion, Literal(\"PSD01\")))\n",
"g.add((s, DCTERMS.isPartOf, URIRef(\"https://docs.oasis-open-projects.org/oslc-op/sysml/v2.0/psd01/sysml-spec.html\")))\n",
"g.add((s, DCTERMS.issued, Literal(\"2024-04-25\", datatype=XSD.date)))\n",
"#g.add((s, DCTERMS.hasVersion, Literal(\"PSD01\")))\n",
"#g.add((s, DCTERMS.isPartOf, URIRef(\"https://docs.oasis-open-projects.org/oslc-op/sysml/v2.0/psd01/sysml-spec.html\")))\n",
"#g.add((s, DCTERMS.issued, Literal(\"2024-04-25\", datatype=XSD.date)))\n",
"g.add((s, DCTERMS.license, URIRef(\"http://www.apache.org/licenses/LICENSE-2.0\")))\n",
"g.add((s, DCTERMS.publisher, URIRef(\"https://open-services.net/about/\")))\n",
"g.add((s, DCTERMS.source, URIRef(\"https://docs.oasis-open-projects.org/oslc-op/sysml/v2.0/psd01/sysml-shapes.ttl\")))\n",
"g.add((s, DCTERMS.title, Literal(\"OSLC System Modeling Language (SysML) Version 2.0 Constraints\")))\n",
"#g.add((s, DCTERMS.source, URIRef(\"https://docs.oasis-open-projects.org/oslc-op/sysml/v2.0/psd01/sysml-shapes.ttl\")))\n",
"g.add((s, DCTERMS.title, Literal(\"OSLC Kernel Modeling Language (SysML) Version 2.0 Constraints\")))\n",
"\n",
"for c in mm_root.eClassifiers:\n",
" # Generate the ResourceShape\n",
Expand All @@ -2701,26 +2718,9 @@
" g.add((shape, DCTERMS.description, Literal(comment(c,strip=False),datatype=RDF.XMLLiteral)))\n",
" g.add((shape, oslc.describes, URIRef(oslc_sysmlv2.term(c.name))))\n",
"\n",
" # generate the properties to the ResourceShape\n",
" for a in c.eStructuralFeatures:\n",
" name = a.name # don't use the class name as a prefix to the attribute name to ensure they are unique\n",
" g.add((shape, oslc.property, URIRef(oslc_sysml_shapes.term(name))))\n",
"\n",
" # and create the oslc:Property\n",
" s = oslc_sysml_shapes.term(name)\n",
" g.add((s, RDF.type, oslc.Property))\n",
" g.add((s, oslc.name, Literal(name)))\n",
" g.add((s, oslc.occurs, multiplicity(a)))\n",
" g.add((s, oslc.propertyDefinition, URIRef(oslc_sysmlv2.term(name))))\n",
" g.add((s, oslc.readOnly, Literal('false',datatype=XSD.boolean)))\n",
" if isinstance(a, EReference):\n",
" g.add((s, oslc.valueType, oslc.Resource))\n",
" g.add((s, oslc.range, oslc_sysmlv2.term(a.eType.name)))\n",
" g.add((s, oslc.representation, oslc.Either))\n",
" elif isinstance(a, EAttribute):\n",
" g.add((s, oslc.range, valueType(a)))\n",
" g.add((s, DCTERMS.description, Literal(comment(a,strip=False), datatype=RDF.XMLLiteral)))\n",
"\n",
" # add all the properties inherited from all superclasses up to Element\n",
" #addSuperclassProperties(c, shape, g)\n",
" addClassProperties(c, shape, g)\n",
"\n",
" # add the inherited oslc_am:Resource properties\n",
" g.add((shape, oslc.property, oslc_sysml_shapes.type))\n",
Expand Down Expand Up @@ -2933,14 +2933,14 @@
"or its value are traced to a requirement).\"\"\", datatype=RDF.XMLLiteral)))\n",
"\n",
"\n",
"g.serialize(destination='../sysml-shapes.ttl')\n",
"g.serialize(destination='../kerml-shapes.ttl')\n",
"\n",
"with open('../sysml-shapes.ttl','r') as f:\n",
" with open('../temp.ttl','w') as f2: \n",
" f2.write(copyright)\n",
" f2.write(f.read())\n",
"os.remove('../sysml-shapes.ttl')\n",
"os.rename('../temp.ttl','../sysml-shapes.ttl')"
"os.remove('../kerml-shapes.ttl')\n",
"os.rename('../temp.ttl','../kerml-shapes.ttl')"
]
},
{
Expand Down
Loading