-
Notifications
You must be signed in to change notification settings - Fork 10
/
step1_generate_metadata.py
executable file
·58 lines (47 loc) · 1.81 KB
/
step1_generate_metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Step 1 - Generate metadata from ontology
----------------------------------------
This step takes the ontology from the vertical case and generates
metadata from it.
Here we use DLite as metadata framework, which is a SOFT
implementation in C. Other frameworks, like CUDS, could equally well
have been used, but the metadata structure would have been different.
This generator maps OWL classes to dlite metadata entities which are
placed into a collection. OWL class properties are mapped into
relations between the entities in the collection. The only relations
that are treated especially are `has_property` and `is_property_for`,
that are mapped into properties of the generated metadata entities.
The generated metadata is finally serialised into a JSON file.
"""
import os
from emmo2meta import EMMO2Meta
from ontopy import get_ontology
# Load our ontology from the vertical case
ontopath = os.path.abspath(
os.path.join(
# os.path.dirname(__file__), "..", "vertical", "usercase_ontology.owl"
os.path.dirname(__file__),
"..",
"demo.owl",
)
)
onto = get_ontology(ontopath)
onto.load()
# hmm, the base iri has cnanged... - bug in owlready2?
onto.base_iri = "http://www.emmc.info/emmc-csa/demo#"
# Generate metadata and store it in a JSON file
#
# This does not include all of EMMO, but only the new classes,
# bonded_atom and all classes that these relates to.
classes = list(onto.classes()) + [
onto.BondedAtom,
onto.Integer,
onto.Real,
onto.String,
]
e = EMMO2Meta(ontology=onto, classes=classes, collid="usercase_ontology")
e.save("json", "usercase_metadata.json", "mode=w")
print("Generated metadata for the usercase ontology:")
print(f" {e.coll.count()} instances")
print(f" {len(list(e.coll.get_relations()))} relations")