You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-198Lines changed: 7 additions & 198 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,209 +4,18 @@
4
4
> knowledge, different data sources and implemented business models into fully functional APIs. The tool accepts ontologies
5
5
> specified in Turtle (.ttl), Resource Description Framework (.rdf)
6
6
> and Web Ontology Language (.owl).
7
-
7
+
>
8
8
> [](https://github.com/JCGCosta/OntologyToAPI/actions/workflows/python-publish.yml)
9
9
10
+
---
10
11
11
-
## Ontological Framework:
12
-
13
-
- The following classes, relationships and data properties serve as a semantic blueprint for both metadata and business models.
The ontological framework is composed of four main modules:
18
-
19
-
-**Metadata Ontology Module:** This module defines the essential classes and properties required to describe the metadata and its sources (e.g. Query to be executed on the CommunicationTechnology).
20
-
-**BusinessModel Ontology Module:** This module captures the specific business logic and rules governing some operation, it requires an ExternalCode concretization, and it can require any metadata or parameter (To be sent in the API request).
21
-
-**ExternalCode Ontology Module:** This module has all the technical details to connect to an external code, it also adds the possibility to dynamically require python packages.
22
-
-**Communications Ontology Module:** This module describes the communication technologies that can be used to fetch the data of some metadata in multiple forms (e. g).
23
-
24
-
> A full documentation on how to extend your own ontologies using the OntologyToAPI framework is still in development, but you can check the example provided below. Or at https://github.com/JCGCosta/OntologyToAPI/tree/master/example
25
-
26
-
## Installing the Package
27
-
28
-
```bash
29
-
pip install -U ontologytoapi
30
-
```
31
-
32
-
## Running a Simple Example
33
-
34
-
- Ontology file with triples to a weather use case extending the OntologyToAPI framework:
rdfs:comment "A measure of the average kinetic energy of the particles within a substance, which corresponds to its hotness or coldness." .
53
-
54
-
ex:Relative_Humidity rdf:type owl:Class ;
55
-
rdfs:subClassOf md:Metadata ;
56
-
rdfs:comment "The ratio of the amount of water vapor currently in the air to the maximum amount the air could hold at that specific temperature, expressed as a percentage." .
ifnot data.metadata and data.params["temperature_c"] isNone:
137
-
return {"error": "No temperature was provided from Metadata or from the endpoint Parameters."}
138
-
if data.params["temperature_c"] isnotNone:
139
-
return {
140
-
"original": data.params["temperature_c"],
141
-
"converted": data.params["temperature_c"] *9/5+32
142
-
}
143
-
else:
144
-
return {
145
-
"original": [t["temperature_c"] for t in data.metadata["Temperature_C_MD"]],
146
-
"converted": [t["temperature_c"] *9/5+32for t in data.metadata["Temperature_C_MD"]]
147
-
}
148
-
```
149
-
150
-
- Code to generate the API:
151
-
152
-
```python
153
-
# ./main.py
154
-
155
-
import uvicorn
156
-
import sqlite3
157
-
from pathlib import Path
158
-
from OntologyToAPI.core.APIGenerator import APIGenerator
159
-
160
-
defconfiguring_a_sample_sqlite_database():
161
-
ifnot Path('example.db').exists():
162
-
with sqlite3.connect('example.db') as conn:
163
-
cursor = conn.cursor()
164
-
cursor.execute('''
165
-
CREATE TABLE IF NOT EXISTS weather (
166
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
167
-
temperature_c FLOAT NOT NULL,
168
-
r_humidity FLOAT NOT NULL
169
-
);
170
-
''')
171
-
cursor.execute("INSERT INTO weather (temperature_c, r_humidity) VALUES ('21.5', '60');")
172
-
cursor.execute("INSERT INTO weather (temperature_c, r_humidity) VALUES ('22.0', '58');")
173
-
cursor.execute("INSERT INTO weather (temperature_c, r_humidity) VALUES ('20.8', '65');")
174
-
conn.commit()
175
-
176
-
if__name__=="__main__":
177
-
configuring_a_sample_sqlite_database()
178
-
APIGen = APIGenerator(showLogs=True)
179
-
APIGen.load_ontologies(paths=[
180
-
"metadata_example.ttl",
181
-
"bm_example.ttl"
182
-
])
183
-
APIGen.serialize_ontologies()
184
-
api_app = APIGen.generate_api_routes()
185
-
uvicorn.run(api_app, host="127.0.0.1", port=5000)
186
-
```
187
-
188
-
- Your project structure should look something like this:
189
-
190
-
```
191
-
├── metadata_example.ttl
192
-
├── bm_example.ttl
193
-
├── bm.py
194
-
├── main.py
195
-
```
196
-
197
-
- Then you should be able to run the example as follows:
198
-
199
-
```bash
200
-
# To run the example, then execute:
201
-
python main.py
202
-
203
-
# You can access the API documentation at: http://localhost:5000
204
-
```
12
+
- A full documentation on how to extend your own ontologies using the OntologyToAPI framework is still in development, but you can check a small sample and docs at https://github.com/JCGCosta/OntologyToAPI/wiki
205
13
206
-
> From now on you must be ready to go and create your own ontological specification importing the [Ontology Modules](https://github.com/JCGCosta/OntologyToAPI/tree/master/OntologicalFramework) and extending it. You can do this by using the Protégé ontology editor (https://protege.stanford.edu/). Or if you prefer you can use any text editor to create your ontology files in the supported formats (.ttl, .rdf, .owl).
14
+
### Expected Results from a simple ontology specification
0 commit comments