ontolutils 0.2.0a1__tar.gz → 0.2.0a2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ontolutils-0.2.0a2/PKG-INFO +26 -0
- ontolutils-0.2.0a2/README.rst +60 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/classes/thing.py +2 -2
- ontolutils-0.2.0a2/ontolutils.egg-info/PKG-INFO +26 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils.egg-info/SOURCES.txt +1 -3
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/setup.cfg +1 -1
- ontolutils-0.2.0a1/PKG-INFO +0 -139
- ontolutils-0.2.0a1/README.md +0 -112
- ontolutils-0.2.0a1/ontolutils/classes/model.py +0 -12
- ontolutils-0.2.0a1/ontolutils/namespacelib/core.py +0 -0
- ontolutils-0.2.0a1/ontolutils.egg-info/PKG-INFO +0 -139
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/LICENSE +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/__init__.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/_version.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/classes/__init__.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/classes/decorator.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/classes/jsonld.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/classes/query_util.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/classes/typing.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/classes/utils.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/namespacelib/__init__.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/namespacelib/_version.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/namespacelib/codemeta.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/namespacelib/dev.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/namespacelib/m4i.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/namespacelib/obo.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/namespacelib/pivmeta.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/namespacelib/qudt_kind.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/namespacelib/qudt_unit.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/namespacelib/schema.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils/namespacelib/ssno.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils.egg-info/dependency_links.txt +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils.egg-info/requires.txt +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/ontolutils.egg-info/top_level.txt +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/pyproject.toml +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/setup.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/tests/test_classes.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/tests/test_namespaces.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/tests/test_query.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/tests/test_readme.py +0 -0
- {ontolutils-0.2.0a1 → ontolutils-0.2.0a2}/tests/test_version.py +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ontolutils
|
|
3
|
+
Version: 0.2.0a2
|
|
4
|
+
Summary: Utility library for the work with ontologies.
|
|
5
|
+
Home-page: https://github.com/matthiasprobst/ontology-utils
|
|
6
|
+
Author: Matthias Probst
|
|
7
|
+
Author-email: matthias.probst@kit.edu
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Development Status :: 3 - Alpha
|
|
16
|
+
Requires-Python: <3.13,>=3.8
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: rdflib
|
|
20
|
+
Requires-Dist: pydantic
|
|
21
|
+
Requires-Dist: python-dateutil
|
|
22
|
+
Requires-Dist: requests
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest>=7.1.2; extra == "test"
|
|
25
|
+
Provides-Extra: complete
|
|
26
|
+
Requires-Dist: pytest>=7.1.2; extra == "complete"
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Ontolutils - Utilities for "pythonic Things"
|
|
2
|
+
============================================
|
|
3
|
+
|
|
4
|
+
.. image:: https://github.com/matthiasprobst/ontology-utils/actions/workflows/tests.yml/badge.svg
|
|
5
|
+
:target: https://github.com/matthiasprobst/ontology-utils/actions/workflows/tests.yml/badge.svg
|
|
6
|
+
:alt: Tests Status
|
|
7
|
+
|
|
8
|
+
.. image:: https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue
|
|
9
|
+
:target: https://img.shields.io/badge/python-3.8%20%7C%203.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue
|
|
10
|
+
:alt: pyvers Status
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
This package helps you in generating ontology-related objects and let's you easily create JSON-LD files.
|
|
14
|
+
|
|
15
|
+
Imagine you want to describe a `prov:Agent` with an `foaf:mbox` (email address) but writing the JSON-LD file
|
|
16
|
+
yourself is too cumbersome. Do the following:
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
.. code-block:: python
|
|
20
|
+
|
|
21
|
+
from pydantic import EmailStr
|
|
22
|
+
|
|
23
|
+
from ontolutils import Thing, namespaces, urirefs
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@namespaces(prov="http://www.w3.org/ns/prov#",
|
|
27
|
+
foaf="http://xmlns.com/foaf/0.1/")
|
|
28
|
+
@urirefs(Agent='prov:Agent',
|
|
29
|
+
mbox='foaf:mbox')
|
|
30
|
+
class Agent(Thing):
|
|
31
|
+
"""Implementation of http://www.w3.org/ns/prov#Agent
|
|
32
|
+
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
mbox: EmailStr = None
|
|
36
|
+
Email address (foaf:mbox)
|
|
37
|
+
"""
|
|
38
|
+
mbox: EmailStr = None # foaf:mbox
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
Now, you can instantiate the class and use the `model_dump_jsonld` method to get a JSON-LD string:
|
|
42
|
+
|
|
43
|
+
.. code-block:: python
|
|
44
|
+
|
|
45
|
+
agent = Agent(mbox="my@email.com")
|
|
46
|
+
print(agent.model_dump_jsonld())
|
|
47
|
+
|
|
48
|
+
{
|
|
49
|
+
"@context": {
|
|
50
|
+
"prov": "http://www.w3.org/ns/prov#",
|
|
51
|
+
"foaf": "http://xmlns.com/foaf/0.1/"
|
|
52
|
+
},
|
|
53
|
+
"@type": "prov:Agent",
|
|
54
|
+
"foaf:mbox": "
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
Please visit the `documentation <https://ontology-utils.readthedocs.io/en/latest/>`_ for more information.
|
|
60
|
+
|
|
@@ -8,7 +8,6 @@ import rdflib
|
|
|
8
8
|
from pydantic import HttpUrl, FileUrl, BaseModel, ConfigDict
|
|
9
9
|
|
|
10
10
|
from .decorator import urirefs, namespaces, URIRefManager, NamespaceManager
|
|
11
|
-
from .model import ThingModel
|
|
12
11
|
from .typing import BlankNodeType
|
|
13
12
|
from .utils import split_URIRef
|
|
14
13
|
|
|
@@ -48,8 +47,9 @@ def serialize_fields(
|
|
|
48
47
|
dict
|
|
49
48
|
The serialized fields
|
|
50
49
|
"""
|
|
51
|
-
if isinstance(obj, str):
|
|
50
|
+
if isinstance(obj, (int, str, float, bool)):
|
|
52
51
|
return obj
|
|
52
|
+
|
|
53
53
|
if exclude_none:
|
|
54
54
|
serialized_fields = {URIRefManager[obj.__class__][k]: getattr(obj, k) for k in obj.model_fields if
|
|
55
55
|
getattr(obj, k) is not None and k not in ('id', '@id')}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ontolutils
|
|
3
|
+
Version: 0.2.0a2
|
|
4
|
+
Summary: Utility library for the work with ontologies.
|
|
5
|
+
Home-page: https://github.com/matthiasprobst/ontology-utils
|
|
6
|
+
Author: Matthias Probst
|
|
7
|
+
Author-email: matthias.probst@kit.edu
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Development Status :: 3 - Alpha
|
|
16
|
+
Requires-Python: <3.13,>=3.8
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: rdflib
|
|
20
|
+
Requires-Dist: pydantic
|
|
21
|
+
Requires-Dist: python-dateutil
|
|
22
|
+
Requires-Dist: requests
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest>=7.1.2; extra == "test"
|
|
25
|
+
Provides-Extra: complete
|
|
26
|
+
Requires-Dist: pytest>=7.1.2; extra == "complete"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
LICENSE
|
|
2
|
-
README.
|
|
2
|
+
README.rst
|
|
3
3
|
pyproject.toml
|
|
4
4
|
setup.cfg
|
|
5
5
|
setup.py
|
|
@@ -13,7 +13,6 @@ ontolutils.egg-info/top_level.txt
|
|
|
13
13
|
ontolutils/classes/__init__.py
|
|
14
14
|
ontolutils/classes/decorator.py
|
|
15
15
|
ontolutils/classes/jsonld.py
|
|
16
|
-
ontolutils/classes/model.py
|
|
17
16
|
ontolutils/classes/query_util.py
|
|
18
17
|
ontolutils/classes/thing.py
|
|
19
18
|
ontolutils/classes/typing.py
|
|
@@ -21,7 +20,6 @@ ontolutils/classes/utils.py
|
|
|
21
20
|
ontolutils/namespacelib/__init__.py
|
|
22
21
|
ontolutils/namespacelib/_version.py
|
|
23
22
|
ontolutils/namespacelib/codemeta.py
|
|
24
|
-
ontolutils/namespacelib/core.py
|
|
25
23
|
ontolutils/namespacelib/dev.py
|
|
26
24
|
ontolutils/namespacelib/m4i.py
|
|
27
25
|
ontolutils/namespacelib/obo.py
|
ontolutils-0.2.0a1/PKG-INFO
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: ontolutils
|
|
3
|
-
Version: 0.2.0a1
|
|
4
|
-
Summary: Utility library for the work with ontologies.
|
|
5
|
-
Home-page: https://github.com/matthiasprobst/ontology-utils
|
|
6
|
-
Author: Matthias Probst
|
|
7
|
-
Author-email: matthias.probst@kit.edu
|
|
8
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
-
Classifier: Operating System :: OS Independent
|
|
15
|
-
Classifier: Development Status :: 3 - Alpha
|
|
16
|
-
Requires-Python: <3.13,>=3.8
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
License-File: LICENSE
|
|
19
|
-
Requires-Dist: rdflib
|
|
20
|
-
Requires-Dist: pydantic
|
|
21
|
-
Requires-Dist: python-dateutil
|
|
22
|
-
Requires-Dist: requests
|
|
23
|
-
Provides-Extra: test
|
|
24
|
-
Requires-Dist: pytest>=7.1.2; extra == "test"
|
|
25
|
-
Provides-Extra: complete
|
|
26
|
-
Requires-Dist: pytest>=7.1.2; extra == "complete"
|
|
27
|
-
|
|
28
|
-
# Ontolutils - Utilities for work with ontologies
|
|
29
|
-
|
|
30
|
-

|
|
31
|
-

|
|
32
|
-
|
|
33
|
-
Utility library for the work with ontologies. Provides two features:
|
|
34
|
-
|
|
35
|
-
- [ontology wrapper classes](#ontology-wrapper-classes)
|
|
36
|
-
- [namespaces](#namespaces)
|
|
37
|
-
|
|
38
|
-
## Ontology wrapper classes
|
|
39
|
-
|
|
40
|
-
With the ontology wrapper classes, you can create objects of ontology classes, write them to a JSON-LD file and query
|
|
41
|
-
them again. Below, an example is made with the `prov` ontology:
|
|
42
|
-
|
|
43
|
-
```python
|
|
44
|
-
|
|
45
|
-
from pydantic import EmailStr
|
|
46
|
-
|
|
47
|
-
from ontolutils import Thing, namespaces, urirefs
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
@namespaces(prov="http://www.w3.org/ns/prov#",
|
|
51
|
-
foaf="http://xmlns.com/foaf/0.1/")
|
|
52
|
-
@urirefs(Agent='prov:Agent',
|
|
53
|
-
mbox='foaf:mbox')
|
|
54
|
-
class Agent(Thing):
|
|
55
|
-
"""Implementation of http://www.w3.org/ns/prov#Agent
|
|
56
|
-
|
|
57
|
-
Parameters
|
|
58
|
-
----------
|
|
59
|
-
mbox: EmailStr = None
|
|
60
|
-
Email address (foaf:mbox)
|
|
61
|
-
"""
|
|
62
|
-
mbox: EmailStr = None # foaf:mbox
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Dump/Serialize
|
|
67
|
-
|
|
68
|
-
What is very useful is serialization of the object. Since the class is a `pydantic` model, you can use the
|
|
69
|
-
`model_dump_json` method. However, this will return a JSON string. What we are interested in, is a JSON-LD string. For
|
|
70
|
-
this call the `model_dump_jsonld` method:
|
|
71
|
-
|
|
72
|
-
```python
|
|
73
|
-
agent = Agent(mbox="a@email.com")
|
|
74
|
-
agent.model_dump_jsonld()
|
|
75
|
-
# {
|
|
76
|
-
# "@context": {
|
|
77
|
-
# "owl": "http://www.w3.org/2002/07/owl#",
|
|
78
|
-
# "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
|
79
|
-
# "local": "http://example.org/",
|
|
80
|
-
# "prov": "http://www.w3.org/ns/prov#",
|
|
81
|
-
# "foaf": "http://xmlns.com/foaf/0.1/"
|
|
82
|
-
# },
|
|
83
|
-
# "@type": "prov:Agent",
|
|
84
|
-
# "foaf:mbox": "e@mail.com"
|
|
85
|
-
# }
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Load from file
|
|
89
|
-
|
|
90
|
-
Let's load an agent from a file:
|
|
91
|
-
|
|
92
|
-
```python
|
|
93
|
-
|
|
94
|
-
# usage:
|
|
95
|
-
agent = Agent(mbox="a@email.com")
|
|
96
|
-
# Agent(mbox=e@mail.com)
|
|
97
|
-
|
|
98
|
-
with open("agent.json", "w") as f:
|
|
99
|
-
f.write(agent.dump_jsonld())
|
|
100
|
-
|
|
101
|
-
found_agents = Agent.from_jsonld(source="agent.json")
|
|
102
|
-
|
|
103
|
-
found_agent = found_agents[0]
|
|
104
|
-
print(found_agent.mbox)
|
|
105
|
-
# Agent(mbox=e@mail.com)
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Namespaces
|
|
109
|
-
|
|
110
|
-
You may know namespaces from `rdflib`, which implements namespaces like `PROV` or `FOAF`:
|
|
111
|
-
|
|
112
|
-
```python
|
|
113
|
-
import rdflib
|
|
114
|
-
|
|
115
|
-
print(rdflib.PROV.Agent)
|
|
116
|
-
# rdflib.URIRef('http://www.w3.org/ns/prov#Agent')
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
But not all. The package `ontoutils` let's you generate namespaces from other resources. Some of them are
|
|
120
|
-
part of this package, like `CODEMETA` or `M4I`. Thus, you can do:
|
|
121
|
-
|
|
122
|
-
```python
|
|
123
|
-
|
|
124
|
-
from ontolutils import M4I
|
|
125
|
-
|
|
126
|
-
print(M4I.Tool)
|
|
127
|
-
# rdflib.URIRef('http://w3id.org/nfdi4ing/metadata4ing#Tool')
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## Limitations
|
|
131
|
-
|
|
132
|
-
Some namespaces may be incomplete due to vocabularies with names that are reserved words in Python. E.g. for
|
|
133
|
-
`schema.org`, "yield" or "True" will not be available like this:
|
|
134
|
-
|
|
135
|
-
```python
|
|
136
|
-
from ontolutils import SCHEMA
|
|
137
|
-
|
|
138
|
-
SCHEMA.yield # AttributeError: 'SchemaOrg' object has no attribute 'yield'
|
|
139
|
-
```
|
ontolutils-0.2.0a1/README.md
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# Ontolutils - Utilities for work with ontologies
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-

|
|
5
|
-
|
|
6
|
-
Utility library for the work with ontologies. Provides two features:
|
|
7
|
-
|
|
8
|
-
- [ontology wrapper classes](#ontology-wrapper-classes)
|
|
9
|
-
- [namespaces](#namespaces)
|
|
10
|
-
|
|
11
|
-
## Ontology wrapper classes
|
|
12
|
-
|
|
13
|
-
With the ontology wrapper classes, you can create objects of ontology classes, write them to a JSON-LD file and query
|
|
14
|
-
them again. Below, an example is made with the `prov` ontology:
|
|
15
|
-
|
|
16
|
-
```python
|
|
17
|
-
|
|
18
|
-
from pydantic import EmailStr
|
|
19
|
-
|
|
20
|
-
from ontolutils import Thing, namespaces, urirefs
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@namespaces(prov="http://www.w3.org/ns/prov#",
|
|
24
|
-
foaf="http://xmlns.com/foaf/0.1/")
|
|
25
|
-
@urirefs(Agent='prov:Agent',
|
|
26
|
-
mbox='foaf:mbox')
|
|
27
|
-
class Agent(Thing):
|
|
28
|
-
"""Implementation of http://www.w3.org/ns/prov#Agent
|
|
29
|
-
|
|
30
|
-
Parameters
|
|
31
|
-
----------
|
|
32
|
-
mbox: EmailStr = None
|
|
33
|
-
Email address (foaf:mbox)
|
|
34
|
-
"""
|
|
35
|
-
mbox: EmailStr = None # foaf:mbox
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Dump/Serialize
|
|
40
|
-
|
|
41
|
-
What is very useful is serialization of the object. Since the class is a `pydantic` model, you can use the
|
|
42
|
-
`model_dump_json` method. However, this will return a JSON string. What we are interested in, is a JSON-LD string. For
|
|
43
|
-
this call the `model_dump_jsonld` method:
|
|
44
|
-
|
|
45
|
-
```python
|
|
46
|
-
agent = Agent(mbox="a@email.com")
|
|
47
|
-
agent.model_dump_jsonld()
|
|
48
|
-
# {
|
|
49
|
-
# "@context": {
|
|
50
|
-
# "owl": "http://www.w3.org/2002/07/owl#",
|
|
51
|
-
# "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
|
52
|
-
# "local": "http://example.org/",
|
|
53
|
-
# "prov": "http://www.w3.org/ns/prov#",
|
|
54
|
-
# "foaf": "http://xmlns.com/foaf/0.1/"
|
|
55
|
-
# },
|
|
56
|
-
# "@type": "prov:Agent",
|
|
57
|
-
# "foaf:mbox": "e@mail.com"
|
|
58
|
-
# }
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## Load from file
|
|
62
|
-
|
|
63
|
-
Let's load an agent from a file:
|
|
64
|
-
|
|
65
|
-
```python
|
|
66
|
-
|
|
67
|
-
# usage:
|
|
68
|
-
agent = Agent(mbox="a@email.com")
|
|
69
|
-
# Agent(mbox=e@mail.com)
|
|
70
|
-
|
|
71
|
-
with open("agent.json", "w") as f:
|
|
72
|
-
f.write(agent.dump_jsonld())
|
|
73
|
-
|
|
74
|
-
found_agents = Agent.from_jsonld(source="agent.json")
|
|
75
|
-
|
|
76
|
-
found_agent = found_agents[0]
|
|
77
|
-
print(found_agent.mbox)
|
|
78
|
-
# Agent(mbox=e@mail.com)
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## Namespaces
|
|
82
|
-
|
|
83
|
-
You may know namespaces from `rdflib`, which implements namespaces like `PROV` or `FOAF`:
|
|
84
|
-
|
|
85
|
-
```python
|
|
86
|
-
import rdflib
|
|
87
|
-
|
|
88
|
-
print(rdflib.PROV.Agent)
|
|
89
|
-
# rdflib.URIRef('http://www.w3.org/ns/prov#Agent')
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
But not all. The package `ontoutils` let's you generate namespaces from other resources. Some of them are
|
|
93
|
-
part of this package, like `CODEMETA` or `M4I`. Thus, you can do:
|
|
94
|
-
|
|
95
|
-
```python
|
|
96
|
-
|
|
97
|
-
from ontolutils import M4I
|
|
98
|
-
|
|
99
|
-
print(M4I.Tool)
|
|
100
|
-
# rdflib.URIRef('http://w3id.org/nfdi4ing/metadata4ing#Tool')
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## Limitations
|
|
104
|
-
|
|
105
|
-
Some namespaces may be incomplete due to vocabularies with names that are reserved words in Python. E.g. for
|
|
106
|
-
`schema.org`, "yield" or "True" will not be available like this:
|
|
107
|
-
|
|
108
|
-
```python
|
|
109
|
-
from ontolutils import SCHEMA
|
|
110
|
-
|
|
111
|
-
SCHEMA.yield # AttributeError: 'SchemaOrg' object has no attribute 'yield'
|
|
112
|
-
```
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import abc
|
|
2
|
-
|
|
3
|
-
from pydantic import BaseModel, ConfigDict
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class ThingModel(abc.ABC, BaseModel):
|
|
7
|
-
"""Abstract class to be used by model classes"""
|
|
8
|
-
model_config = ConfigDict(extra='allow') # or 'forbid' or 'ignore'
|
|
9
|
-
|
|
10
|
-
@abc.abstractmethod
|
|
11
|
-
def _repr_html_(self) -> str:
|
|
12
|
-
"""Returns the HTML representation of the class"""
|
|
File without changes
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: ontolutils
|
|
3
|
-
Version: 0.2.0a1
|
|
4
|
-
Summary: Utility library for the work with ontologies.
|
|
5
|
-
Home-page: https://github.com/matthiasprobst/ontology-utils
|
|
6
|
-
Author: Matthias Probst
|
|
7
|
-
Author-email: matthias.probst@kit.edu
|
|
8
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
-
Classifier: Operating System :: OS Independent
|
|
15
|
-
Classifier: Development Status :: 3 - Alpha
|
|
16
|
-
Requires-Python: <3.13,>=3.8
|
|
17
|
-
Description-Content-Type: text/markdown
|
|
18
|
-
License-File: LICENSE
|
|
19
|
-
Requires-Dist: rdflib
|
|
20
|
-
Requires-Dist: pydantic
|
|
21
|
-
Requires-Dist: python-dateutil
|
|
22
|
-
Requires-Dist: requests
|
|
23
|
-
Provides-Extra: test
|
|
24
|
-
Requires-Dist: pytest>=7.1.2; extra == "test"
|
|
25
|
-
Provides-Extra: complete
|
|
26
|
-
Requires-Dist: pytest>=7.1.2; extra == "complete"
|
|
27
|
-
|
|
28
|
-
# Ontolutils - Utilities for work with ontologies
|
|
29
|
-
|
|
30
|
-

|
|
31
|
-

|
|
32
|
-
|
|
33
|
-
Utility library for the work with ontologies. Provides two features:
|
|
34
|
-
|
|
35
|
-
- [ontology wrapper classes](#ontology-wrapper-classes)
|
|
36
|
-
- [namespaces](#namespaces)
|
|
37
|
-
|
|
38
|
-
## Ontology wrapper classes
|
|
39
|
-
|
|
40
|
-
With the ontology wrapper classes, you can create objects of ontology classes, write them to a JSON-LD file and query
|
|
41
|
-
them again. Below, an example is made with the `prov` ontology:
|
|
42
|
-
|
|
43
|
-
```python
|
|
44
|
-
|
|
45
|
-
from pydantic import EmailStr
|
|
46
|
-
|
|
47
|
-
from ontolutils import Thing, namespaces, urirefs
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
@namespaces(prov="http://www.w3.org/ns/prov#",
|
|
51
|
-
foaf="http://xmlns.com/foaf/0.1/")
|
|
52
|
-
@urirefs(Agent='prov:Agent',
|
|
53
|
-
mbox='foaf:mbox')
|
|
54
|
-
class Agent(Thing):
|
|
55
|
-
"""Implementation of http://www.w3.org/ns/prov#Agent
|
|
56
|
-
|
|
57
|
-
Parameters
|
|
58
|
-
----------
|
|
59
|
-
mbox: EmailStr = None
|
|
60
|
-
Email address (foaf:mbox)
|
|
61
|
-
"""
|
|
62
|
-
mbox: EmailStr = None # foaf:mbox
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Dump/Serialize
|
|
67
|
-
|
|
68
|
-
What is very useful is serialization of the object. Since the class is a `pydantic` model, you can use the
|
|
69
|
-
`model_dump_json` method. However, this will return a JSON string. What we are interested in, is a JSON-LD string. For
|
|
70
|
-
this call the `model_dump_jsonld` method:
|
|
71
|
-
|
|
72
|
-
```python
|
|
73
|
-
agent = Agent(mbox="a@email.com")
|
|
74
|
-
agent.model_dump_jsonld()
|
|
75
|
-
# {
|
|
76
|
-
# "@context": {
|
|
77
|
-
# "owl": "http://www.w3.org/2002/07/owl#",
|
|
78
|
-
# "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
|
79
|
-
# "local": "http://example.org/",
|
|
80
|
-
# "prov": "http://www.w3.org/ns/prov#",
|
|
81
|
-
# "foaf": "http://xmlns.com/foaf/0.1/"
|
|
82
|
-
# },
|
|
83
|
-
# "@type": "prov:Agent",
|
|
84
|
-
# "foaf:mbox": "e@mail.com"
|
|
85
|
-
# }
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Load from file
|
|
89
|
-
|
|
90
|
-
Let's load an agent from a file:
|
|
91
|
-
|
|
92
|
-
```python
|
|
93
|
-
|
|
94
|
-
# usage:
|
|
95
|
-
agent = Agent(mbox="a@email.com")
|
|
96
|
-
# Agent(mbox=e@mail.com)
|
|
97
|
-
|
|
98
|
-
with open("agent.json", "w") as f:
|
|
99
|
-
f.write(agent.dump_jsonld())
|
|
100
|
-
|
|
101
|
-
found_agents = Agent.from_jsonld(source="agent.json")
|
|
102
|
-
|
|
103
|
-
found_agent = found_agents[0]
|
|
104
|
-
print(found_agent.mbox)
|
|
105
|
-
# Agent(mbox=e@mail.com)
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Namespaces
|
|
109
|
-
|
|
110
|
-
You may know namespaces from `rdflib`, which implements namespaces like `PROV` or `FOAF`:
|
|
111
|
-
|
|
112
|
-
```python
|
|
113
|
-
import rdflib
|
|
114
|
-
|
|
115
|
-
print(rdflib.PROV.Agent)
|
|
116
|
-
# rdflib.URIRef('http://www.w3.org/ns/prov#Agent')
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
But not all. The package `ontoutils` let's you generate namespaces from other resources. Some of them are
|
|
120
|
-
part of this package, like `CODEMETA` or `M4I`. Thus, you can do:
|
|
121
|
-
|
|
122
|
-
```python
|
|
123
|
-
|
|
124
|
-
from ontolutils import M4I
|
|
125
|
-
|
|
126
|
-
print(M4I.Tool)
|
|
127
|
-
# rdflib.URIRef('http://w3id.org/nfdi4ing/metadata4ing#Tool')
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## Limitations
|
|
131
|
-
|
|
132
|
-
Some namespaces may be incomplete due to vocabularies with names that are reserved words in Python. E.g. for
|
|
133
|
-
`schema.org`, "yield" or "True" will not be available like this:
|
|
134
|
-
|
|
135
|
-
```python
|
|
136
|
-
from ontolutils import SCHEMA
|
|
137
|
-
|
|
138
|
-
SCHEMA.yield # AttributeError: 'SchemaOrg' object has no attribute 'yield'
|
|
139
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|