diff --git a/docs/figs/Untitled Diagram.drawio b/docs/figs/Untitled Diagram.drawio new file mode 100644 index 0000000..b23a612 --- /dev/null +++ b/docs/figs/Untitled Diagram.drawio @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/docs/figs/dlite_cuds.svg b/docs/figs/dlite_cuds.svg new file mode 100644 index 0000000..56e3bbd --- /dev/null +++ b/docs/figs/dlite_cuds.svg @@ -0,0 +1,4 @@ + + + +
Shared knowledge base
Shared knowle...
query
query
dlite_cuds
Python library

from_cuds_metadata()
from_cuds()
to_cuds()
dlite_cuds...
uses
uses
DLite plugin
cuds
DLite plugin...
uses
uses
OTEAPI plugin
Use existing oteapi-dlite strategies:
parse, generate
OTEAPI plugin...
query
query
osp-core
osp-core
uses
uses
MODS
MODS
Standalone library only depending on tripper and DLite.

Accessing the knowledge base via Tripper.
Standalone library only dependi...
Shared knowledge base
Shared knowle...
query
query
dlite_cuds
Python library

from_cuds_metadata()
from_cuds()
to_cuds()
dlite_cuds...
uses
uses
DLite plugin
cuds

Maybe not needed??
DLite plugin...
uses
uses
OTEAPI plugin
Based on existing plugins in dlite_cuds
OTEAPI plugin...
query
query
osp-core
osp-core
uses
uses
MODS
MODS
Standalone library only depending on tripper and DLite.

Accessing the knowledge base via Tripper.
Standalone library only dependi...
Alternative design
Alternative design
Viewer does not support full SVG 1.1
diff --git a/docs/figs/example_data.svg b/docs/figs/example_data.svg new file mode 100644 index 0000000..46e78de --- /dev/null +++ b/docs/figs/example_data.svg @@ -0,0 +1,4 @@ + + + +
ontology.example.yml
ontology.example.yml
storedIn
storedIn
ex.ttl
ex.ttl
storedIn
storedIn
example_ABox.ttl
example_ABox.ttl
generate
generate
generate_example_a_box.py
generate_example_a_box.py
instances.json
instances.json
generate
generate
mkcoll.py
mkcoll.py
hasInput
hasInput
TypeOne.json
TypeOne.json
hasInput
hasInput
TypeTwo.json
TypeTwo.json
hasInput
hasInput
TypeThree.json
TypeThree.json
generate
generate
hasInput
hasInput
convert_ontology_to_ttl.py
convert_ontology_to_ttl.py
Files in the example folder
Files in the example folder
Knowledge base
Knowledge base
generate
generate
hasInput
hasInput
from_cuds_metadata()
from_cuds_metadata()
generate
generate
hasInput
hasInput
from_cuds()
from_cuds()
hasInput
hasInput
hasInput
hasInput
populate
populate
to_cuds()
to_cuds()
Colour coding
Colour coding
Added by Sean
Added by Sean
Added by SINTEF
Added by SINTEF
Planned stuff
Planned stuff
Text is not SVG - cannot display
\ No newline at end of file diff --git a/example/TypeOne.json b/example/TypeOne.json new file mode 100644 index 0000000..366bdcb --- /dev/null +++ b/example/TypeOne.json @@ -0,0 +1,15 @@ +{ + "uri": "http://onto-ns.com/meta/0.1/TypeOne", + "description": "", + "dimensions": {}, + "properties": { + "dpOne": { + "type": "string", + "description": "" + }, + "dpTwo": { + "type": "int", + "description": "" + } + } +} diff --git a/example/TypeThree.json b/example/TypeThree.json new file mode 100644 index 0000000..71c5b1d --- /dev/null +++ b/example/TypeThree.json @@ -0,0 +1,11 @@ +{ + "uri": "http://onto-ns.com/meta/0.1/TypeThree", + "description": "", + "dimensions": {}, + "properties": { + "dpTwo": { + "type": "int", + "description": "" + } + } +} diff --git a/example/TypeTwo.json b/example/TypeTwo.json new file mode 100644 index 0000000..fd743ab --- /dev/null +++ b/example/TypeTwo.json @@ -0,0 +1,19 @@ +{ + "uri": "http://onto-ns.com/meta/0.1/TypeTwo", + "description": "", + "dimensions": {}, + "properties": { + "dpOne": { + "type": "string", + "description": "" + }, + "dpTwo": { + "type": "int", + "description": "" + }, + "dpThree": { + "type": "float", + "description": "" + } + } +} diff --git a/example/convert_ontology_to_ttl.py b/example/convert_ontology_to_ttl.py new file mode 100644 index 0000000..88dcd8a --- /dev/null +++ b/example/convert_ontology_to_ttl.py @@ -0,0 +1,33 @@ +"""Generates `ex` ontology ttl file""" +import os + +import rdflib +from osp.core.ontology import Ontology +from osp.core.ontology.parser import OntologyParser + + +def export_ontology(ontology_namespace): + """Converts ex ontology to a ttl file and exports as ex.ttl""" + ontology_graph = rdflib.graph.Graph() + packages_path = os.path.expanduser(os.path.join("~", ".osp_ontologies")) + package_path = os.path.join(packages_path, ontology_namespace) + + export_file_path = os.path.join(os.getcwd(), f"{ontology_namespace}.ttl") + + if os.path.exists(f"{package_path}.yml"): + ontology = Ontology(from_parser=OntologyParser.get_parser(package_path)) + ontology_graph += ontology.graph + else: + raise FileNotFoundError( + f"Package {ontology_namespace} not " + f"found in {packages_path}. Are " + f"you sure it is installed?" + ) + + result = ontology_graph.serialize(format="ttl", encoding="UTF-8").decode("UTF-8") + with open(export_file_path, "w+", encoding="utf-8") as file_handle: + file_handle.write(result) + + +if __name__ == "__main__": + export_ontology("ex") diff --git a/example/ex.ttl b/example/ex.ttl new file mode 100644 index 0000000..68a49c4 --- /dev/null +++ b/example/ex.ttl @@ -0,0 +1,73 @@ +@prefix ns1: . +@prefix ns2: . +@prefix owl: . +@prefix rdfs: . +@prefix xsd: . + + ns2:_default_rel . + + a owl:Class ; + rdfs:subClassOf [ a owl:Restriction ; + owl:cardinality 1 ; + owl:onProperty ], + ns2:Entity ; + ns1:prefLabel "TypeThree"@en . + + a owl:Class ; + rdfs:subClassOf [ a owl:Restriction ; + owl:cardinality 1 ; + owl:onProperty ], + ns2:Entity, + ; + ns1:prefLabel "TypeTwo"@en . + + a owl:ObjectProperty ; + rdfs:isDefinedBy "inverse of second object property"@en ; + rdfs:subPropertyOf ns2:passiveRelationship ; + owl:inverseOf ; + ns1:prefLabel "iOPTwo"@en . + + a owl:Class ; + rdfs:subClassOf [ a owl:Restriction ; + owl:cardinality 1 ; + owl:onProperty ], + [ a owl:Restriction ; + owl:cardinality 1 ; + owl:onProperty ], + ns2:Entity ; + ns1:prefLabel "TypeOne"@en . + + a owl:DatatypeProperty, + owl:FunctionalProperty ; + rdfs:range xsd:string ; + rdfs:subPropertyOf ns2:attribute ; + ns1:prefLabel "dpOne"@en . + + a owl:DatatypeProperty, + owl:FunctionalProperty ; + rdfs:range xsd:float ; + rdfs:subPropertyOf ns2:attribute ; + ns1:prefLabel "dpThree"@en . + + a owl:ObjectProperty ; + rdfs:isDefinedBy "inverse of the default relationship"@en ; + rdfs:subPropertyOf ns2:passiveRelationship ; + owl:inverseOf ; + ns1:prefLabel "iOPOne"@en . + + a owl:ObjectProperty ; + rdfs:isDefinedBy "second object property"@en ; + rdfs:subPropertyOf ns2:activeRelationship ; + ns1:prefLabel "opTwo"@en . + + a owl:DatatypeProperty, + owl:FunctionalProperty ; + rdfs:range xsd:integer ; + rdfs:subPropertyOf ns2:attribute ; + ns1:prefLabel "dpTwo"@en . + + a owl:ObjectProperty ; + rdfs:isDefinedBy "default relationship"@en ; + rdfs:subPropertyOf ns2:activeRelationship ; + owl:inverseOf ; + ns1:prefLabel "opOne"@en . diff --git a/example/example_ABox.ttl b/example/example_ABox.ttl new file mode 100644 index 0000000..3517524 --- /dev/null +++ b/example/example_ABox.ttl @@ -0,0 +1,29 @@ +@prefix cuba: . +@prefix ex: . +@prefix rdf: . +@prefix xsd: . + +cuba:_serialization rdf:first "f817bd09-3945-4325-9a60-62ecca19ea3c" . + + a ex:TypeThree ; + ex:dpTwo 3 ; + ex:iOPTwo . + + a ex:TypeTwo ; + ex:dpOne "g"^^xsd:string ; + ex:dpThree "8.9"^^xsd:float ; + ex:dpTwo 4 ; + ex:iOPTwo . + + a ex:TypeTwo ; + ex:dpOne "b"^^xsd:string ; + ex:dpThree "2.5"^^xsd:float ; + ex:dpTwo 5 ; + ex:iOPOne ; + ex:opTwo . + + a ex:TypeOne ; + ex:dpOne "a"^^xsd:string ; + ex:dpTwo 1 ; + ex:opOne ; + ex:opTwo . diff --git a/example/generate_example_a_box.py b/example/generate_example_a_box.py new file mode 100644 index 0000000..d0f748b --- /dev/null +++ b/example/generate_example_a_box.py @@ -0,0 +1,21 @@ +"""Generates an example ABox""" +from osp.core.namespaces import ex +from osp.core.utils import export_cuds + + +def generate_example(): + """Generates and exports example ABox""" + inst1 = ex.TypeOne(dpOne="a", dpTwo=1) + inst2 = ex.TypeTwo(dpOne="b", dpTwo=5, dpThree=2.5) + inst3 = ex.TypeThree(dpTwo=3) + inst4 = ex.TypeTwo(dpOne="g", dpTwo=4, dpThree=8.9) + + inst2.add(inst4, rel=ex.opTwo) + inst1.add(inst2, rel=ex.opOne) + inst1.add(inst3, rel=ex.opTwo) + + export_cuds(inst1, file="example_ABox.ttl") + + +if __name__ == "__main__": + generate_example() diff --git a/example/instances.json b/example/instances.json new file mode 100644 index 0000000..701bd6d --- /dev/null +++ b/example/instances.json @@ -0,0 +1,71 @@ +{ + "f8e99b4f-4e0a-5bf5-be29-248964aa1f51": { + "uri": "http://www.osp-core.com/cuds#db11661e-e815-4f36-b5a6-2bafe25f09b6", + "meta": "http://onto-ns.com/meta/0.1/TypeTwo", + "dimensions": { + }, + "properties": { + "dpOne": "b", + "dpTwo": 5, + "dpThree": 2.5 + } + }, + "9cb54433-ba6d-4d8b-9fab-1cb4aba27dae": { + "meta": "http://onto-ns.com/meta/0.1/Collection", + "dimensions": { + "nrelations": 18 + }, + "properties": { + "relations": [ + ["inst1", "_is-a", "Instance"], + ["inst1", "_has-uuid", "2a917046-a0ba-5714-a9bf-f7f610f11451"], + ["inst1", "_has-meta", "http://onto-ns.com/meta/0.1/TypeOne"], + ["inst2a", "_is-a", "Instance"], + ["inst2a", "_has-uuid", "91eb70b8-5d79-54bc-b96c-fc9ee126672a"], + ["inst2a", "_has-meta", "http://onto-ns.com/meta/0.1/TypeTwo"], + ["inst2b", "_is-a", "Instance"], + ["inst2b", "_has-uuid", "f8e99b4f-4e0a-5bf5-be29-248964aa1f51"], + ["inst2b", "_has-meta", "http://onto-ns.com/meta/0.1/TypeTwo"], + ["inst3", "_is-a", "Instance"], + ["inst3", "_has-uuid", "cbc76b74-195c-5e77-855e-a1e434ce18c9"], + ["inst3", "_has-meta", "http://onto-ns.com/meta/0.1/TypeThree"], + ["inst1", "ex:opOne", "inst2b"], + ["inst1", "ex:opTwo", "inst3"], + ["inst2a", "ex:iOPTwo", "inst2b"], + ["inst2b", "ex:iOPOne", "inst1"], + ["inst2b", "ex:opTwo", "inst2a"], + ["inst3", "ex:iOPTwo", "inst1"] + ] + } + }, + "2a917046-a0ba-5714-a9bf-f7f610f11451": { + "uri": "http://www.osp-core.com/cuds#f817bd09-3945-4325-9a60-62ecca19ea3c", + "meta": "http://onto-ns.com/meta/0.1/TypeOne", + "dimensions": { + }, + "properties": { + "dpOne": "a", + "dpTwo": 1 + } + }, + "91eb70b8-5d79-54bc-b96c-fc9ee126672a": { + "uri": "http://www.osp-core.com/cuds#7dc3081f-72cb-4754-9623-e821b352fd14", + "meta": "http://onto-ns.com/meta/0.1/TypeTwo", + "dimensions": { + }, + "properties": { + "dpOne": "g", + "dpTwo": 4, + "dpThree": 8.9 + } + }, + "cbc76b74-195c-5e77-855e-a1e434ce18c9": { + "uri": "http://www.osp-core.com/cuds#5c29896e-b51f-4994-903f-090a2dedbac3", + "meta": "http://onto-ns.com/meta/0.1/TypeThree", + "dimensions": { + }, + "properties": { + "dpTwo": 3 + } + } +} diff --git a/example/mkcoll.py b/example/mkcoll.py new file mode 100644 index 0000000..c73c4b4 --- /dev/null +++ b/example/mkcoll.py @@ -0,0 +1,54 @@ +from pathlib import Path + +import dlite + +thisdir = Path(__file__).resolve().parent +dlite.storage_path.append(thisdir) + +TypeOne = dlite.get_instance("http://onto-ns.com/meta/0.1/TypeOne") +TypeTwo = dlite.get_instance("http://onto-ns.com/meta/0.1/TypeTwo") +TypeThree = dlite.get_instance("http://onto-ns.com/meta/0.1/TypeThree") + + +inst1 = TypeOne(id="http://www.osp-core.com/cuds#f817bd09-3945-4325-9a60-62ecca19ea3c") +inst1.dpOne = "a" +inst1.dpTwo = 1 + +inst2a = TypeTwo(id="http://www.osp-core.com/cuds#7dc3081f-72cb-4754-9623-e821b352fd14") +inst2a.dpOne = "g" +inst2a.dpTwo = 4 +inst2a.dpThree = 8.9 + +inst2b = TypeTwo(id="http://www.osp-core.com/cuds#db11661e-e815-4f36-b5a6-2bafe25f09b6") +inst2b.dpOne = "b" +inst2b.dpTwo = 5 +inst2b.dpThree = 2.5 + +inst3 = TypeThree( + id="http://www.osp-core.com/cuds#5c29896e-b51f-4994-903f-090a2dedbac3" +) +inst3.dpTwo = 3 + + +coll = dlite.Collection() +coll.add("inst1", inst1) +coll.add("inst2a", inst2a) +coll.add("inst2b", inst2b) +coll.add("inst3", inst3) + +# coll.add_relation(inst1.uri, "ex:opOne", inst2b.uri) +# coll.add_relation(inst1.uri, "ex:opTwo", inst3.uri) +# coll.add_relation(inst2a.uri, "ex:iOPTwo", inst2b.uri) +# coll.add_relation(inst2b.uri, "ex:iOPOne", inst1.uri) +# coll.add_relation(inst2b.uri, "ex:opTwo", inst2a.uri) +# coll.add_relation(inst3.uri, "ex:iOPTwo", inst1.uri) + +coll.add_relation("inst1", "ex:opOne", "inst2b") +coll.add_relation("inst1", "ex:opTwo", "inst3") +coll.add_relation("inst2a", "ex:iOPTwo", "inst2b") +coll.add_relation("inst2b", "ex:iOPOne", "inst1") +coll.add_relation("inst2b", "ex:opTwo", "inst2a") +coll.add_relation("inst3", "ex:iOPTwo", "inst1") + +# coll.save("yaml", "instances.yaml", "mode=w") +coll.save("json", "instances.json", "mode=w") diff --git a/example/ontology.example.yml b/example/ontology.example.yml new file mode 100644 index 0000000..c6f39c1 --- /dev/null +++ b/example/ontology.example.yml @@ -0,0 +1,67 @@ +--- +version: "0.0.1" +namespace: "ex" +author: "CMCL Innovations" + +ontology: + ################ RELATIONSHIPS ################ + opOne: + default_rel: true + description: "default relationship" + inverse: ex.iOPOne + subclass_of: + - cuba.activeRelationship + + iOPOne: + description: "inverse of the default relationship" + inverse: ex.opOne + subclass_of: + - cuba.passiveRelationship + + opTwo: + description: "second object property" + subclass_of: + - cuba.activeRelationship + + iOPTwo: + description: "inverse of second object property" + inverse: ex.opTwo + subclass_of: + - cuba.passiveRelationship + + ################ MAIN ENTITIES ################ + #================================================# + TypeOne: + subclass_of: + - cuba.Entity + attributes: + ex.dpOne: + ex.dpTwo: + + TypeTwo: + subclass_of: + - cuba.Entity + - ex.TypeOne + attributes: + ex.dpThree: + + TypeThree: + subclass_of: + - cuba.Entity + attributes: + ex.dpTwo: + + dpOne: + subclass_of: + - cuba.attribute + datatype: STRING + + dpTwo: + subclass_of: + - cuba.attribute + datatype: INT + + dpThree: + subclass_of: + - cuba.attribute + datatype: FLOAT