Skip to content

Commit 3529afe

Browse files
committed
update/docs
- Update README.txt with latest instructions. - Added Wiki to at https://github.com/JCGCosta/OntologyToAPI/wiki
1 parent 372ee55 commit 3529afe

4 files changed

Lines changed: 13 additions & 204 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/tmp
44
/samples
55
test.py
6-
energy_members.unqlite
6+
energy_members.unqlite
7+
/example/example.db

CHANGELOG.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
Change Log
22
===============
3-
VERSION="0.0.18"
4-
LAST_UPDATE="24/11/2025"
3+
VERSION="0.0.19"
4+
LAST_UPDATE="15/12/2025"
55
------------------
6-
- Update the BM ontology both in the file and README.md
7-
- Added description information for the BM endpoint by getting the rdfs:comment from the ontology BM concept
8-
- Fix with pathing issues in Linux/Mac in the UNQLITEConnection.py
6+
- Update README.txt with latest instructions.
7+
- Added Wiki to at https://github.com/JCGCosta/OntologyToAPI/wiki
98
------------------

README.md

Lines changed: 7 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -4,209 +4,18 @@
44
> knowledge, different data sources and implemented business models into fully functional APIs. The tool accepts ontologies
55
> specified in Turtle (.ttl), Resource Description Framework (.rdf)
66
> and Web Ontology Language (.owl).
7-
7+
>
88
> [![Publish to PyPI and TestPyPI](https://github.com/JCGCosta/OntologyToAPI/actions/workflows/python-publish.yml/badge.svg)](https://github.com/JCGCosta/OntologyToAPI/actions/workflows/python-publish.yml)
99
10+
---
1011

11-
## Ontological Framework:
12-
13-
- The following classes, relationships and data properties serve as a semantic blueprint for both metadata and business models.
14-
15-
<img src="https://github.com/JCGCosta/OntologyToAPI/blob/master/OntologicalFramework.jpg?raw=true" alt="AbstractOntologyClasses" title="Abstract Ontology Classes.">
16-
17-
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:
35-
36-
```turtle
37-
# ./metadata_example.ttl
38-
39-
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
40-
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
41-
@prefix owl: <http://www.w3.org/2002/07/owl#> .
42-
43-
@prefix md: <http://www.cedri.com/OntologyToAPI-Metadata#> .
44-
@prefix comm: <http://www.cedri.com/OntologyToAPI-Communications#> .
45-
46-
@prefix ex: <http://example.org/> .
47-
48-
# Class Definitions
49-
50-
ex:Temperature_C rdf:type owl:Class ;
51-
rdfs:subClassOf md:Metadata ;
52-
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." .
57-
58-
# Individuals for Metadata and Communication
59-
60-
ex:SQLITE_DB rdf:type owl:NamedIndividual ,
61-
comm:DatabaseCommunication ;
62-
comm:hasConnectionString "sqlite+aiosqlite:///example.db" ;
63-
comm:usesTechnology "SQLITE" .
64-
65-
ex:Temperature_C_Source rdf:type owl:NamedIndividual ,
66-
md:Source ;
67-
md:hasCommunicationTechnology ex:SQLITE_DB ;
68-
md:hasDescription "Retrieves the temperature data from a local SQLite database." ;
69-
md:hasQuery "SELECT temperature_c FROM weather;" .
70-
71-
ex:Temperature_C_MD rdf:type owl:NamedIndividual ,
72-
ex:Temperature_C ;
73-
md:hasSource ex:Temperature_C_Source ;
74-
md:hasType "float" .
75-
76-
ex:Relative_Humidity_Source rdf:type owl:NamedIndividual ,
77-
md:Source ;
78-
md:hasCommunicationTechnology ex:SQLITE_DB ;
79-
md:hasDescription "Retrieves the relative humidity data from a local SQLite database." ;
80-
md:hasQuery "SELECT r_humidity FROM weather;" .
81-
82-
ex:Relative_Humidity_MD rdf:type owl:NamedIndividual ,
83-
ex:Relative_Humidity ;
84-
md:hasSource ex:Relative_Humidity_Source ;
85-
md:hasType "float" .
86-
```
87-
88-
- Ontology file with triples to represent temperature convertion sample in the OntologyToAPI framework:
89-
90-
```turtle
91-
# ./bm_example.ttl
92-
93-
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
94-
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
95-
@prefix owl: <http://www.w3.org/2002/07/owl#> .
96-
97-
@prefix md: <http://www.cedri.com/OntologyToAPI-Metadata#> .
98-
@prefix comm: <http://www.cedri.com/OntologyToAPI-Communications#> .
99-
@prefix bm: <http://www.cedri.com/OntologyToAPI-BusinessModel#> .
100-
@prefix excode: <http://www.cedri.com/OntologyToAPI-ExternalCode#> .
101-
102-
@prefix ex: <http://example.org/> .
103-
104-
# Class Definitions
105-
106-
ex:CelsiusToFahrenheitBM rdf:type owl:Class ;
107-
rdfs:subClassOf bm:BusinessModel ;
108-
rdfs:comment "This business model allows the convertion from Celsius to Fahrenheit." .
109-
110-
# Individuals for Business Models
111-
112-
ex:CelsiusToFahrenheit.py rdf:type owl:NamedIndividual ,
113-
excode:ExternalCode ;
114-
excode:hasFunction "convert_temperature_c_to_f" ;
115-
excode:hasPythonFile "bm.py" ;
116-
excode:requiresLib "requests" .
117-
118-
ex:Temperature_P rdf:type owl:NamedIndividual ,
119-
bm:Parameter ;
120-
bm:hasParameterLabel "temperature_c" ;
121-
bm:hasParameterType "float" .
122-
123-
ex:CelsiusToFahrenheit rdf:type owl:NamedIndividual ,
124-
ex:CelsiusToFahrenheitBM ;
125-
bm:requiresMetadata ex:Temperature_C_MD;
126-
bm:hasExternalCode ex:CelsiusToFahrenheit.py ;
127-
bm:hasParameter ex:Temperature_P .
128-
```
129-
130-
- Code to have the business model implementation:
131-
132-
```python
133-
# ./bm.py
134-
135-
async def convert_temperature_c_to_f(data):
136-
if not data.metadata and data.params["temperature_c"] is None:
137-
return {"error": "No temperature was provided from Metadata or from the endpoint Parameters."}
138-
if data.params["temperature_c"] is not None:
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 + 32 for 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-
def configuring_a_sample_sqlite_database():
161-
if not 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
20513

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
20715

16+
<img src="https://github.com/JCGCosta/OntologyToAPI/blob/master/example/APIEndpoints.png?raw=true" alt="APIEndpoints" title="APIEndpoints.">
20817

209-
## Supported communication technologies are (Currently):
18+
### Supported communication technologies are (Currently):
21019

21120
#### Stateful Connections
21221
- "SOCKET" - For Socket connections using asyncio streams
@@ -219,7 +28,7 @@ python main.py
21928
- "MONGODB" - For MongoDB Databases using motor driver
22029
- "UNQLITE" - For UnQLite Databases using unqlite+asyncio driver
22130

222-
## Next Steps:
31+
### Next Steps:
22332

22433
Next steps involve extending the support for new communication technologies.
22534
- "FILE" - For File operations using aiofiles driver

example/APIEndpoints.png

40.5 KB
Loading

0 commit comments

Comments
 (0)