Skip to content
Draft
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
10 changes: 10 additions & 0 deletions docs/figs/Untitled Diagram.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<mxfile host="app.diagrams.net" modified="2023-12-06T12:37:08.086Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" version="22.1.5" etag="K0obKH-73bEU9V0lB224" type="github">
<diagram name="Page-1" id="npF7nOJxLP0afzf-HzOP">
<mxGraphModel>
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
</root>
</mxGraphModel>
</diagram>
</mxfile>
4 changes: 4 additions & 0 deletions docs/figs/dlite_cuds.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/figs/example_data.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions example/TypeOne.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"uri": "http://onto-ns.com/meta/0.1/TypeOne",
"description": "",
"dimensions": {},
"properties": {
"dpOne": {
"type": "string",
"description": ""
},
"dpTwo": {
"type": "int",
"description": ""
}
}
}
11 changes: 11 additions & 0 deletions example/TypeThree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"uri": "http://onto-ns.com/meta/0.1/TypeThree",
"description": "",
"dimensions": {},
"properties": {
"dpTwo": {
"type": "int",
"description": ""
}
}
}
19 changes: 19 additions & 0 deletions example/TypeTwo.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
}
}
33 changes: 33 additions & 0 deletions example/convert_ontology_to_ttl.py
Original file line number Diff line number Diff line change
@@ -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")
73 changes: 73 additions & 0 deletions example/ex.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
@prefix ns1: <http://www.w3.org/2004/02/skos/core#> .
@prefix ns2: <http://www.osp-core.com/cuba#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://www.osp-core.com/ex#> ns2:_default_rel <http://www.osp-core.com/ex#opOne> .

<http://www.osp-core.com/ex#TypeThree> a owl:Class ;
rdfs:subClassOf [ a owl:Restriction ;
owl:cardinality 1 ;
owl:onProperty <http://www.osp-core.com/ex#dpTwo> ],
ns2:Entity ;
ns1:prefLabel "TypeThree"@en .

<http://www.osp-core.com/ex#TypeTwo> a owl:Class ;
rdfs:subClassOf [ a owl:Restriction ;
owl:cardinality 1 ;
owl:onProperty <http://www.osp-core.com/ex#dpThree> ],
ns2:Entity,
<http://www.osp-core.com/ex#TypeOne> ;
ns1:prefLabel "TypeTwo"@en .

<http://www.osp-core.com/ex#iOPTwo> a owl:ObjectProperty ;
rdfs:isDefinedBy "inverse of second object property"@en ;
rdfs:subPropertyOf ns2:passiveRelationship ;
owl:inverseOf <http://www.osp-core.com/ex#opTwo> ;
ns1:prefLabel "iOPTwo"@en .

<http://www.osp-core.com/ex#TypeOne> a owl:Class ;
rdfs:subClassOf [ a owl:Restriction ;
owl:cardinality 1 ;
owl:onProperty <http://www.osp-core.com/ex#dpOne> ],
[ a owl:Restriction ;
owl:cardinality 1 ;
owl:onProperty <http://www.osp-core.com/ex#dpTwo> ],
ns2:Entity ;
ns1:prefLabel "TypeOne"@en .

<http://www.osp-core.com/ex#dpOne> a owl:DatatypeProperty,
owl:FunctionalProperty ;
rdfs:range xsd:string ;
rdfs:subPropertyOf ns2:attribute ;
ns1:prefLabel "dpOne"@en .

<http://www.osp-core.com/ex#dpThree> a owl:DatatypeProperty,
owl:FunctionalProperty ;
rdfs:range xsd:float ;
rdfs:subPropertyOf ns2:attribute ;
ns1:prefLabel "dpThree"@en .

<http://www.osp-core.com/ex#iOPOne> a owl:ObjectProperty ;
rdfs:isDefinedBy "inverse of the default relationship"@en ;
rdfs:subPropertyOf ns2:passiveRelationship ;
owl:inverseOf <http://www.osp-core.com/ex#opOne> ;
ns1:prefLabel "iOPOne"@en .

<http://www.osp-core.com/ex#opTwo> a owl:ObjectProperty ;
rdfs:isDefinedBy "second object property"@en ;
rdfs:subPropertyOf ns2:activeRelationship ;
ns1:prefLabel "opTwo"@en .

<http://www.osp-core.com/ex#dpTwo> a owl:DatatypeProperty,
owl:FunctionalProperty ;
rdfs:range xsd:integer ;
rdfs:subPropertyOf ns2:attribute ;
ns1:prefLabel "dpTwo"@en .

<http://www.osp-core.com/ex#opOne> a owl:ObjectProperty ;
rdfs:isDefinedBy "default relationship"@en ;
rdfs:subPropertyOf ns2:activeRelationship ;
owl:inverseOf <http://www.osp-core.com/ex#iOPOne> ;
ns1:prefLabel "opOne"@en .
29 changes: 29 additions & 0 deletions example/example_ABox.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@prefix cuba: <http://www.osp-core.com/cuba#> .
@prefix ex: <http://www.osp-core.com/ex#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

cuba:_serialization rdf:first "f817bd09-3945-4325-9a60-62ecca19ea3c" .

<http://www.osp-core.com/cuds#5c29896e-b51f-4994-903f-090a2dedbac3> a ex:TypeThree ;
ex:dpTwo 3 ;
ex:iOPTwo <http://www.osp-core.com/cuds#f817bd09-3945-4325-9a60-62ecca19ea3c> .

<http://www.osp-core.com/cuds#7dc3081f-72cb-4754-9623-e821b352fd14> a ex:TypeTwo ;
ex:dpOne "g"^^xsd:string ;
ex:dpThree "8.9"^^xsd:float ;
ex:dpTwo 4 ;
ex:iOPTwo <http://www.osp-core.com/cuds#db11661e-e815-4f36-b5a6-2bafe25f09b6> .

<http://www.osp-core.com/cuds#db11661e-e815-4f36-b5a6-2bafe25f09b6> a ex:TypeTwo ;
ex:dpOne "b"^^xsd:string ;
ex:dpThree "2.5"^^xsd:float ;
ex:dpTwo 5 ;
ex:iOPOne <http://www.osp-core.com/cuds#f817bd09-3945-4325-9a60-62ecca19ea3c> ;
ex:opTwo <http://www.osp-core.com/cuds#7dc3081f-72cb-4754-9623-e821b352fd14> .

<http://www.osp-core.com/cuds#f817bd09-3945-4325-9a60-62ecca19ea3c> a ex:TypeOne ;
ex:dpOne "a"^^xsd:string ;
ex:dpTwo 1 ;
ex:opOne <http://www.osp-core.com/cuds#db11661e-e815-4f36-b5a6-2bafe25f09b6> ;
ex:opTwo <http://www.osp-core.com/cuds#5c29896e-b51f-4994-903f-090a2dedbac3> .
21 changes: 21 additions & 0 deletions example/generate_example_a_box.py
Original file line number Diff line number Diff line change
@@ -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()
71 changes: 71 additions & 0 deletions example/instances.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
54 changes: 54 additions & 0 deletions example/mkcoll.py
Original file line number Diff line number Diff line change
@@ -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")
Loading