Skip to content

Commit

Permalink
Merge pull request #9 from dice-group/develop
Browse files Browse the repository at this point in the history
New Release
  • Loading branch information
Demirrr authored Mar 28, 2024
2 parents 18f9d7c + 9682754 commit 6f758d4
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 61 deletions.
53 changes: 24 additions & 29 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
#name: Python package
#
#on: [push,pull_request]
#
#jobs:
# build:
# runs-on: ubuntu-latest
# strategy:
# matrix:
# python-version: ["3.9"]
# max-parallel: 5
# steps:
# - uses: actions/checkout@v3
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}
#
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install -r requirements.txt
#
# - name: Test with pytest
# run: |
# pip install pytest
# wget https://files.dice-research.org/projects/Ontolearn/KGs.zip
# unzip KGs.zip
# pytest -p no:warnings -x
name: Python package

on: [push,pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10.13"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
- name: Test with pytest
run: |
python -m pytest -p no:warnings -x
22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# OWLpy: OWL in Python

# OWLAPY

## Installation
<details><summary> Click me! </summary>
Expand All @@ -15,9 +14,8 @@ pip3 install owlapy
```
</details>



## Usage
<details><summary> Click me! </summary>

In this example we start with a simple atomic class expression and move to some more complex
ones and finally render and print the last of them in description logics syntax.
Expand All @@ -26,6 +24,7 @@ ones and finally render and print the last of them in description logics syntax.
from owlapy.render import DLSyntaxObjectRenderer
from owlapy.model import IRI, OWLClass, OWLObjectProperty, OWLObjectSomeValuesFrom, \
OWLObjectIntersectionOf
from owlapy.owl2sparql.converter import owl_expression_to_sparql

# Create an IRI object using the iri as a string for 'male' class.
male_iri = IRI.create('http://example.com/society#male')
Expand All @@ -46,7 +45,7 @@ male_teachers_with_children = OWLObjectIntersectionOf([males_with_children, teac
# You can render and print owl class expressions in description logics syntax
print(DLSyntaxObjectRenderer().render(male_teachers_with_children))
# (∃ hasChild.male) ⊓ teacher
print(Owl2SparqlConverter().as_query("?x", male_teachers_with_children))
print(owl_expression_to_sparql("?x", male_teachers_with_children))
# SELECT DISTINCT ?x WHERE { ?x <http://example.com/society#hasChild> ?s_1 . ?s_1 a <http://example.com/society#male> . ?x a <http://example.com/society#teacher> . } }
```
For more, you can check the [API documentation](https://ontolearn-docs-dice-group.netlify.app/autoapi/owlapy/#module-owlapy).
Expand All @@ -61,14 +60,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 model](https://ontolearn-docs-dice-group.netlify.app/autoapi/owlapy/model/#module-owlapy.model).
</details>


### Are you looking for more?

The java _owlapi_ library also offers classes for OWL ontology, manager and reasoner.
We have also implemented those classes in python, but for the time being we are
not including them in owlapy. You can find all of those classes in
[Ontolearn](https://github.com/dice-group/Ontolearn/tree/develop), which is a
python library that offers more than just that.

In case you have any question or request please don't hesitate to open an issue.
## How to cite
Currently, we are working on our manuscript describing our framework.
22 changes: 13 additions & 9 deletions owlapy/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
"""The OWL-APy Model classes and methods.
Their names should match those of OWL API [1].
If OWL API has streaming and getter API, it is enough to provide the streaming API only.
Many help texts copied from OWL API.
[1] https://github.com/owlcs/owlapi"""
"""@TODO: CD: This is not a python code. We should refactor this model module."""

from abc import ABCMeta, abstractmethod
from functools import total_ordering
Expand Down Expand Up @@ -245,6 +237,14 @@ def get_nnf(self) -> 'OWLClass':
# documented in parent
return self

@property
def str(self):
return self.get_iri().as_str()

@property
def reminder(self)->str:
"""The reminder of the IRI """
return self.get_iri().get_remainder()

class OWLPropertyExpression(OWLObject, metaclass=ABCMeta):
"""Represents a property or possibly the inverse of a property."""
Expand Down Expand Up @@ -408,6 +408,10 @@ def is_owl_top_object_property(self) -> bool:
# documented in parent
return self.get_iri() == OWLRDFVocabulary.OWL_TOP_OBJECT_PROPERTY.get_iri()

@property
def str(self)->str:
return self.get_iri().as_str()


class OWLObjectInverseOf(OWLObjectPropertyExpression):
"""Represents the inverse of a property expression (ObjectInverseOf). This can be used to refer to the inverse of
Expand Down
19 changes: 19 additions & 0 deletions owlapy/model/_iri.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,30 @@ def as_iri(self) -> 'IRI':

def as_str(self) -> str:
"""
CD: Should be deprecated.
Returns:
The string that specifies the IRI.
"""
return self._namespace + self._remainder

@property
def str(self) -> str:
"""
Returns:
The string that specifies the IRI.
"""
return self.as_str()

@property
def reminder(self) -> str:
"""
Returns:
The string corresponding to the reminder of the IRI.
"""
return self.reminder()

def get_short_form(self) -> str:
"""Gets the short form.
Expand Down
13 changes: 12 additions & 1 deletion owlapy/owl2sparql/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def _(self, ce: OWLObjectOneOf):
self.append(",")
assert isinstance(ind, OWLNamedIndividual)
self.append(f"<{ind.to_string_id()}>")
self.append(f" )")
self.append(f" ) )")

@process.register
def _(self, ce: OWLDataSomeValuesFrom):
Expand Down Expand Up @@ -626,3 +626,14 @@ def as_query(self,
query = "\n".join(qs)
parseQuery(query)
return query


converter = Owl2SparqlConverter()


def owl_expression_to_sparql(root_variable: str,
ce: OWLClassExpression,
count: bool = False,
values: Optional[Iterable[OWLNamedIndividual]] = None,
named_individuals: bool = False):
return converter.as_query(root_variable, ce, count, values, named_individuals)
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
install_requires=[
"pandas>=1.5.0",
"rdflib>=6.0.2",
"parsimonious>=0.8.1"],
author='Ontolearn Team',
"parsimonious>=0.8.1",
"pytest>=8.1.1"],
author='Caglar Demir',
author_email='caglardemir8@gmail.com',
url='https://github.com/dice-group/owlapy',
classifiers=[
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Topic :: Scientific/Engineering"],
python_requires='>=3.8',
python_requires='>=3.10',
long_description=long_description,
long_description_content_type="text/markdown",
)

0 comments on commit 6f758d4

Please sign in to comment.