Skip to content

Commit

Permalink
Merge pull request #42 from dice-group/ontology_manipulation
Browse files Browse the repository at this point in the history
Ontology manipulation
  • Loading branch information
Demirrr authored May 27, 2024
2 parents 20f4a61 + 247daae commit c337a9d
Show file tree
Hide file tree
Showing 14 changed files with 4,342 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ jobs:
- name: Test with pytest
run: |
wget https://files.dice-research.org/projects/Ontolearn/KGs.zip
unzip KGs.zip
python -m pytest -p no:warnings -x
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# OWLAPY

OWLAPY is a Python Framework that serves as a base structure for creating and manipulating
OWL Ontologies.
OWLAPY is a Python Framework for creating and manipulating OWL Ontologies.

Have a look at the [Documentation](https://dice-group.github.io/owlapy/).

## Installation

### Installation from Source
``` bash
git clone https://github.com/dice-group/owlapy
Expand Down Expand Up @@ -57,5 +57,7 @@ class. In the above examples we have introduced 3 types of class expressions:
Like we showed in this example, you can create all kinds of class expressions using the
OWL objects in [owlapy api](https://dice-group.github.io/owlapy/autoapi/owlapy/index.html).

Check also the [examples](https://github.com/dice-group/owlapy/tree/develop/examples) folder.

## How to cite
Currently, we are working on our manuscript describing our framework.
10 changes: 6 additions & 4 deletions docs/usage/main.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# About owlapy

**Version:** owlapy 1.0.1
**Version:** owlapy 1.0.2

**GitHub repository:** [https://github.com/dice-group/owlapy](https://github.com/dice-group/owlapy)

**Publisher and maintainer:** [DICE](https://dice-research.org/) - data science research group of [Paderborn University](https://www.uni-paderborn.de/en/university).

**Contact**: [onto-learn@lists.uni-paderborn.de](mailto:onto-learn@lists.uni-paderborn.de)

**License:** GNU Affero General Public License v3 or later (AGPLv3+)
**License:** MIT License

--------------------------------------------------------------------------------------------
## What is owlapy?
Owlapy is an open-source software library in python that is used to represent entities
in OWL 2 Web Ontology Language.

We identified the gap of having a library that will serve as a base structure
for representing OWL entities in python and like that, owlapy was created. Owlapy
for representing OWL entities and for manipulating OWL Ontologies in python, and like that, owlapy was created. Owlapy
is loosely based on its java-counterpart, _owlapi_. Owlapy is currently utilized
by powerful libraries such as [Ontolearn](https://github.com/dice-group/Ontolearn)
and [OntoSample](https://github.com/alkidbaci/OntoSample).
Expand All @@ -27,7 +27,9 @@ focus on knowledge graphs and class expression learnings.
---------------------------------------

## What does owlapy have to offer?

- Create, manipulate and save Ontologies.
- Retrieving information from the signature of the ontology.
- Reasoning over ontology.
- Represent every notation in
[OWL 2 Structural Specification and Functional-Style Syntax](https://www.w3.org/TR/owl2-syntax/)
including:
Expand Down
3 changes: 2 additions & 1 deletion docs/usage/usage_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,5 @@ print(manchester_to_owl_expression("female and (hasChild max 2 person)", namespa
```

In these examples we showed a fraction of **owlapy**. You can explore the
[api documentation](owlapy) to learn more about all classes in owlapy.
[api documentation](owlapy) to learn more about all classes in owlapy and check more
examples in the [examples](https://github.com/dice-group/owlapy/tree/develop/examples) directory.
File renamed without changes.
46 changes: 46 additions & 0 deletions examples/ontology_modification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from owlapy.class_expression import OWLClass
from owlapy.owl_axiom import OWLDeclarationAxiom, OWLClassAxiom, OWLClassAssertionAxiom
from owlapy.owl_individual import OWLNamedIndividual
from owlapy.owl_ontology_manager import OntologyManager
from owlapy.iri import IRI
from owlapy.static_funcs import download_external_files

# Download the datasets if KGs does not exist.
download_external_files("https://files.dice-research.org/projects/Ontolearn/KGs.zip")

# Load the 'father' ontology using a new ontology manager.
manager = OntologyManager()
onto = manager.load_ontology(IRI.create(f'file://../KGs/Family/father.owl'))

# Let's see what classes does this ontology has
[print(_) for _ in onto.classes_in_signature()]

# Create a new class
new_class = OWLClass(IRI.create('http://example.com/father#child'))

# Add a declaration axiom for this class using ontology manager
manager.add_axiom(ontology=onto, axiom=OWLDeclarationAxiom(new_class))

# Check whether the new class is added in the signature of the ontology
print("------------------------")
[print(_) for _ in onto.classes_in_signature()]

# Add an individual of type child in the ontology
new_ind = OWLNamedIndividual('http://example.com/father#lulu')
manager.add_axiom(onto, OWLClassAssertionAxiom(new_ind, new_class))

# Check if Lulu is added

print("----------------------")
[print(_) for _ in onto.individuals_in_signature()]

# Save the modified ontology locally (otherwise the changes will be lost)
manager.save_ontology(ontology=onto, document_iri=IRI.create("file:/../KGs/Family/father_modified.owl"))
# NOTE: using the same name will overwrite the current file with the new one.


"""
You can also remove axioms by using manage.remove_axiom.
There are countless axioms which you can add or remove from an ontology.
Check them here: https://dice-group.github.io/owlapy/autoapi/owlapy/owl_axiom/index.html
"""
Loading

0 comments on commit c337a9d

Please sign in to comment.