Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TOAR-II FastAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
toar-data
TOAR-II FastAPI
Commits
6a595f00
Commit
6a595f00
authored
4 years ago
by
Sabine Schröder
Browse files
Options
Downloads
Patches
Plain Diff
onthologies: also added new entries to generic ('oneOf') classes
parent
d08ec2b5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#58442
passed
4 years ago
Stage: deploy
Stage: pages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
toardb/utils/TOARII_ontology.py
+51
-15
51 additions, 15 deletions
toardb/utils/TOARII_ontology.py
toardb/utils/onto_example.py
+0
-1
0 additions, 1 deletion
toardb/utils/onto_example.py
with
51 additions
and
16 deletions
toardb/utils/TOARII_ontology.py
+
51
−
15
View file @
6a595f00
...
...
@@ -4,9 +4,15 @@ class TOAR_Ontology
===================
"""
__author__
=
"
Sabine Schroeder
"
__version__
=
"
0.9.1
"
__maintainer__
=
"
Sabine Schroeder
"
__email__
=
"
s.schroeder@fz-juelich.de
"
import
rdflib
from
rdflib
import
URIRef
,
Literal
from
rdflib.namespace
import
RDF
,
RDFS
,
SKOS
from
rdflib
import
URIRef
,
Literal
,
BNode
from
rdflib.namespace
import
RDF
,
RDFS
,
SKOS
,
OWL
from
rdflib.collection
import
Collection
class
TOAR_Ontology
:
"""
...
...
@@ -27,22 +33,25 @@ class TOAR_Ontology:
get_class(title):
find the onthology class for the given title
def show_class_definition(ont_class):
get_class_by_id(self, id):
find the onthology class for the given id
show_class_definition(ont_class):
show information on given ontology class
show_entries(ont_class):
show information on given ontology class
def
add_entry(self, ont_class, idcount, label, definition):
add_entry(self, ont_class, idcount, label, definition):
add entry to given ontology class
def
check_entry(entry, ont_class):
check_entry(entry, ont_class):
check whether entry is a valid value of the ontology
print(format=
""
):
Prints the onthology in the given format
def
save(self, filename):
save(self, filename):
save the onthology in json-ld format to the given file
"""
...
...
@@ -58,12 +67,21 @@ class TOAR_Ontology:
"""
find the onthology class for the given title
"""
for
s
,
p
,
o
in
self
.
graph
.
triples
(
(
None
,
RDF
.
type
,
rdflib
.
URIRef
(
"
http://www.w3.org/2002/07/owl#
Class
"
)
)
):
for
s
,
p
,
o
in
self
.
graph
.
triples
(
(
None
,
RDF
.
type
,
OWL
.
Class
)
):
value
=
self
.
graph
.
value
(
subject
=
s
,
predicate
=
RDFS
.
label
)
if
value
and
value
.
strip
()
==
title
.
strip
():
ont_class
=
s
return
ont_class
def
get_class_by_id
(
self
,
id
):
"""
find the onthology class for the given id
"""
for
s
,
p
,
o
in
self
.
graph
.
triples
(
(
None
,
RDF
.
type
,
OWL
.
Class
)
):
if
s
.
strip
()
==
id
.
strip
():
ont_class
=
s
return
ont_class
def
show_class_definition
(
self
,
ont_class
):
"""
show information on given ontology class
...
...
@@ -85,15 +103,33 @@ class TOAR_Ontology:
"""
add entry to given ontology class
"""
print
(
f
"
add entry to
'
{
ont_class
}
'"
)
s
=
URIRef
(
f
"
http://www.fz-juelich.de/ontologies/2020/ToarOntotology#OWLNamedIndividual_
{
idcount
:
06
d
}
"
)
p
=
URIRef
(
"
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
"
)
# still to do:
# how to get rid of "http://www.fz-juelich.de/ontologies/2020/ToarOntotology"?!
subject
=
URIRef
(
f
"
http://www.fz-juelich.de/ontologies/2020/ToarOntotology#OWLNamedIndividual_
{
idcount
:
06
d
}
"
)
p
=
RDF
.
type
o
=
URIRef
(
ont_class
)
self
.
graph
.
add
((
s
,
p
,
o
))
o
=
URIRef
(
"
http://www.w3.org/2002/07/owl#NamedIndividual
"
)
self
.
graph
.
add
((
s
,
p
,
o
))
self
.
graph
.
add
((
s
,
RDFS
.
label
,
Literal
(
label
,
lang
=
"
en
"
)))
self
.
graph
.
add
((
s
,
SKOS
.
definition
,
Literal
(
definition
)))
self
.
graph
.
add
((
subject
,
p
,
o
))
o
=
OWL
.
NamedIndividual
self
.
graph
.
add
((
subject
,
p
,
o
))
self
.
graph
.
add
((
subject
,
RDFS
.
label
,
Literal
(
label
,
lang
=
"
en
"
)))
self
.
graph
.
add
((
subject
,
SKOS
.
definition
,
Literal
(
definition
)))
# if there is an equivalent class: add the entry also there!
for
s
,
p
,
o
in
self
.
graph
.
triples
(
(
ont_class
,
OWL
.
equivalentClass
,
None
)
):
equivalentClass
=
self
.
get_class_by_id
(
o
)
# get oneOf-List of equivalentClass
for
s
,
p
,
o
in
self
.
graph
.
triples
(
(
equivalentClass
,
OWL
.
oneOf
,
None
)
):
c
=
Collection
(
self
.
graph
,
BNode
(
o
))
c
.
append
(
subject
)
# The following is just an example how to iterate through a linked list
# # The obtained list is a linked list,
# # consisting of the first element and the rest (which is a linked list again)
# newSubject = o
# while newSubject != RDF.nil:
# for s, p, o in self.graph.triples( (newSubject, RDF.first, None) ):
# print(f"first {newSubject}: s={s}, p={p}, o={o}")
# for s, p, o in self.graph.triples( (newSubject, RDF.rest, None) ):
# print(f"rest {newSubject}: s={s}, p={p}, o={o}")
# newSubject=o
def
check_entry
(
self
,
entry
,
ont_class
):
"""
...
...
This diff is collapsed.
Click to expand it.
toardb/utils/onto_example.py
+
0
−
1
View file @
6a595f00
...
...
@@ -28,5 +28,4 @@ onto.add_entry(ccclass,196,'SX', 'Sint Maarten (Dutch part)')
onto
.
add_entry
(
ccclass
,
197
,
'
BE
'
,
'
Belgium
'
)
onto
.
check_entry
(
'
BE
'
,
ccclass
)
onto
.
show_entries
(
ccclass
)
#nun hier entsprechendes für Timezone
onto
.
save
(
'
TOAR-Ontology-TimeZone-CountryCode_20210128.owl
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment