diff --git a/README.md b/README.md
index 2cfcbc91..6dd942c2 100644
--- a/README.md
+++ b/README.md
@@ -25,11 +25,34 @@ pip3 install owlapy
```shell
# To download RDF knowledge graphs
wget https://files.dice-research.org/projects/Ontolearn/KGs.zip -O ./KGs.zip && unzip KGs.zip
-pytest -p no:warnings -x # Running 142 tests ~ 30 secs
+pytest -p no:warnings -x # Running 147 tests ~ 35 secs
```
## Examples
+### Sklearn to OWL Ontology
+
+ Click me!
+
+```python
+from owlapy.owl_ontology_manager import SyncOntologyManager
+from owlapy.util_owl_static_funcs import csv_to_rdf_kg
+import pandas as pd
+from sklearn.datasets import load_iris
+data = load_iris()
+df = pd.DataFrame(data.data, columns=data.feature_names)
+df.to_csv("iris_dataset.csv", index=False)
+path_kg = "iris_kg.owl"
+# Construct an RDF Knowledge Graph from a CSV file
+csv_to_rdf_kg(path_csv="iris_dataset.csv", path_kg=path_kg, namespace="http://owlapy.com/iris")
+onto = SyncOntologyManager().load_ontology(path_kg)
+assert len(onto.get_abox_axioms()) == 750
+
+```
+
+
+
+
### Exploring OWL Ontology
Click me!
diff --git a/owlapy/owl_literal.py b/owlapy/owl_literal.py
index d6ffb5bb..3154e487 100644
--- a/owlapy/owl_literal.py
+++ b/owlapy/owl_literal.py
@@ -257,7 +257,7 @@ def parse_integer(self) -> int:
Returns:
An integer value that is represented by this literal.
"""
- raise ValueError
+ return int(self._v)
def is_string(self) -> bool:
"""Whether this literal is typed as string."""
diff --git a/owlapy/util_owl_static_funcs.py b/owlapy/util_owl_static_funcs.py
index 1e8027b7..542ac243 100644
--- a/owlapy/util_owl_static_funcs.py
+++ b/owlapy/util_owl_static_funcs.py
@@ -62,7 +62,7 @@ def save_owl_class_expressions(expressions: OWLClassExpression | List[OWLClassEx
ontology.add_axiom(equivalent_classes_axiom)
ontology.save(path=path, inplace=False, rdf_format=rdf_format)
-def csv_to_rdf_kg(path_csv:str=None,path_kg:str=None,namespace:str=None,rdf_format:str=None):
+def csv_to_rdf_kg(path_csv:str=None,path_kg:str=None,namespace:str=None):
"""
Transfroms a CSV file to an RDF Knowledge Graph in RDF/XML format.
@@ -70,7 +70,6 @@ def csv_to_rdf_kg(path_csv:str=None,path_kg:str=None,namespace:str=None,rdf_form
path_csv (str): X
path_kg (str): X
namespace (str): X
- rdf_format(str):X
Raises:
AssertionError:
@@ -94,10 +93,6 @@ def csv_to_rdf_kg(path_csv:str=None,path_kg:str=None,namespace:str=None,rdf_form
assert path_kg is not None, f"path_kg cannot be None.Currently {path_kg}"
assert namespace is not None, "namespace cannot be None"
assert namespace[:7]=="http://", "First characters of namespace must be 'http://'"
- if rdf_format is None:
- rdf_format="rdfxml"
- else:
- assert rdf_format in ["ntriples", "turtle"]
# Initialize an Ontology Manager.
manager = SyncOntologyManager()
@@ -106,22 +101,27 @@ def csv_to_rdf_kg(path_csv:str=None,path_kg:str=None,namespace:str=None,rdf_form
# Read the CSV file
df = pd.read_csv(path_csv)
+
# () Iterate over rows
- for index, row in tqdm(df.iterrows()):
+ for index, row in (tqdm_bar := tqdm(df.iterrows()) ):
individual=OWLNamedIndividual(f"{namespace}#{str(index)}".replace(" ","_"))
+ tqdm_bar.set_description_str(f"Creating RDF Graph from Row:{index}")
+ # column_name is considered as a predicate
+ # value is considered as a data property
for column_name, value in row.to_dict().items():
- if isinstance(value, float):
- # Create an IRI for the predicate
- str_property_iri=f"{namespace}#{column_name}".replace(" ","_")
- str_property_iri=str_property_iri.replace("(","/")
- str_property_iri = str_property_iri.replace(")", "")
+ # Create an IRI for the predicate
+ str_property_iri = f"{namespace}#{column_name}".replace(" ", "_")
+ str_property_iri = str_property_iri.replace("(", "/")
+ str_property_iri = str_property_iri.replace(")", "")
+ if isinstance(value, float) or isinstance(value, int) or isinstance(value, str):
axiom = OWLDataPropertyAssertionAxiom(subject=individual,
property_=OWLDataProperty(iri=str_property_iri),
object_=OWLLiteral(value=value))
ontology.add_axiom(axiom)
-
else:
- raise NotImplementedError(f"How to represent value={value} has not been decided")
-
+ raise NotImplementedError(f"How to represent\n"
+ f"predicate=**{str_property_iri}**\n"
+ f"value=**{value}**\n"
+ f"has not been decided")
ontology.save(path=path_kg)
diff --git a/tests/test_owl_static_funcs.py b/tests/test_owl_static_funcs.py
index f1bd7771..668c99bb 100644
--- a/tests/test_owl_static_funcs.py
+++ b/tests/test_owl_static_funcs.py
@@ -10,8 +10,6 @@
import rdflib
from owlapy.owl_ontology_manager import SyncOntologyManager
-from sklearn.datasets import load_iris
-import pandas as pd
class TestRunningExamples:
def test_readme(self):
@@ -35,7 +33,6 @@ def test_csv_to_kg(self):
df = pd.DataFrame(data.data, columns=data.feature_names)
df['target'] = data.target
df.to_csv("iris_dataset.csv", index=False)
-
assert len(df) == 150
path_kg = "iris_kg.owl"
csv_to_rdf_kg(path_csv="iris_dataset.csv", path_kg=path_kg, namespace="http://example.com/society")