Skip to content

Commit

Permalink
Merge pull request #36 from dice-group/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Demirrr committed May 3, 2024
2 parents ea48dc9 + 3910f04 commit 5994940
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10.11" ]
python-version: [ "3.10.13" ]
max-parallel: 5

steps:
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ OWL Ontologies.
Have a look at the [Documentation](https://dice-group.github.io/owlapy/).

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

### Installation from Source
``` bash
git clone https://github.com/dice-group/owlapy
Expand All @@ -17,10 +15,9 @@ or
```bash
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 @@ -46,7 +43,7 @@ teacher_that_hasChild_male = OWLObjectIntersectionOf([hasChild_male, teacher])
# You can render and print owl class expressions in description logics syntax (and vice-versa)
print(owl_expression_to_dl(teacher_that_hasChild_male))
# (∃ hasChild.male) ⊓ teacher
print(owl_expression_to_sparql("?x", teacher_that_hasChild_male))
print(owl_expression_to_sparql(teacher_that_hasChild_male))
# 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> . } }
```

Expand All @@ -59,7 +56,6 @@ 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).
</details>

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

**Version:** owlapy 1.0.0
**Version:** owlapy 1.0.1

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

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/usage_examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ from owlapy import owl_expression_to_sparql, owl_expression_to_dl, owl_expressio
print(owl_expression_to_dl(ce))
# Result: male ⊓ (≥ 1 hasChild.person)

print(owl_expression_to_sparql(expression=ce))
print(owl_expression_to_sparql(ce))
# Result: SELECT DISTINCT ?x WHERE { ?x a <http://example.com/family#male> . { SELECT ?x WHERE { ?x <http://example.com/family#hasChild> ?s_1 . ?s_1 a <http://example.com/family#person> . } GROUP BY ?x HAVING ( COUNT ( ?s_1 ) >= 1 ) } }

print(owl_expression_to_manchester(ce))
Expand Down
2 changes: 1 addition & 1 deletion owlapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .render import owl_expression_to_dl, owl_expression_to_manchester
from .parser import dl_to_owl_expression, manchester_to_owl_expression
from .converter import owl_expression_to_sparql
__version__ = '1.0.0'
__version__ = '1.0.2'
4 changes: 3 additions & 1 deletion owlapy/class_expression/restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from abc import ABCMeta, abstractmethod
from ..meta_classes import HasFiller, HasCardinality, HasOperands
from typing import TypeVar, Generic, Final, Sequence, Union, Iterable
from .nary_boolean_expression import OWLObjectIntersectionOf
from .nary_boolean_expression import OWLObjectIntersectionOf, OWLObjectUnionOf
from .class_expression import OWLAnonymousClassExpression, OWLClassExpression
from ..owl_property import OWLPropertyExpression, OWLObjectPropertyExpression, OWLDataPropertyExpression
from ..owl_data_ranges import OWLPropertyRange, OWLDataRange
Expand Down Expand Up @@ -461,6 +461,7 @@ class OWLQuantifiedDataRestriction(OWLQuantifiedRestriction[OWLDataRange],
_filler: OWLDataRange

def __init__(self, filler: OWLDataRange):
assert isinstance(filler, OWLDataRange), "filler must be an OWLDataRange"
self._filler = filler

def get_filler(self) -> OWLDataRange:
Expand All @@ -478,6 +479,7 @@ class OWLDataCardinalityRestriction(OWLCardinalityRestriction[OWLDataRange],

@abstractmethod
def __init__(self, cardinality: int, property: OWLDataPropertyExpression, filler: OWLDataRange):
assert isinstance(filler, OWLDataRange), "filler must be an OWLDataRange"
super().__init__(cardinality, filler)
self._property = property

Expand Down
8 changes: 4 additions & 4 deletions owlapy/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def _(self, ce: OWLDataAllValuesFrom):
def _(self, ce: OWLDataHasValue):
property_expression = ce.get_property()
value = ce.get_filler()
assert isinstance(value, OWLDataProperty)
assert isinstance(value, OWLLiteral)
self.append_triple(self.current_variable, property_expression, value)

@process.register
Expand Down Expand Up @@ -587,10 +587,10 @@ def as_query(self,
converter = Owl2SparqlConverter()


def owl_expression_to_sparql(root_variable: str = "?x",
expression: OWLClassExpression = None,
def owl_expression_to_sparql(expression: OWLClassExpression = None,
root_variable: str = "?x",
values: Optional[Iterable[OWLNamedIndividual]] = None,
named_individuals: bool = False)->str:
named_individuals: bool = False) -> str:
"""Convert an OWL Class Expression (https://www.w3.org/TR/owl2-syntax/#Class_Expressions) into a SPARQL query
root variable: the variable that will be projected
expression: the class expression to be transformed to a SPARQL query
Expand Down
3 changes: 2 additions & 1 deletion owlapy/owl_axiom.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""OWL Axioms"""
from abc import ABCMeta, abstractmethod
from itertools import combinations

from typing import TypeVar, List, Optional, Iterable, Generic, Final, Union
from .owl_property import OWLDataPropertyExpression, OWLObjectPropertyExpression
from .owl_object import OWLObject, OWLEntity
from .owl_datatype import OWLDatatype, OWLDataRange
from .meta_classes import HasOperands
from .owl_property import OWLPropertyExpression, OWLProperty
from .class_expression import OWLClassExpression, OWLClass
from .class_expression import OWLClassExpression, OWLClass, OWLNothing, OWLThing, OWLObjectUnionOf
from .owl_individual import OWLIndividual
from .iri import IRI
from owlapy.owl_annotation import OWLAnnotationSubject, OWLAnnotationValue
Expand Down
16 changes: 16 additions & 0 deletions owlapy/owl_literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def get_datatype(self) -> OWLDatatype:
The OWLDatatype that types this literal.
"""
pass


@total_ordering
class _OWLLiteralImplDouble(OWLLiteral):
__slots__ = '_v'
Expand Down Expand Up @@ -222,6 +224,8 @@ def parse_double(self) -> float:
def get_datatype(self) -> OWLDatatype:
# documented in parent
return DoubleOWLDatatype


@total_ordering
class _OWLLiteralImplInteger(OWLLiteral):
__slots__ = '_v'
Expand Down Expand Up @@ -275,6 +279,14 @@ def __init__(self, value, type_=None):
value = bool(strtobool(value))
self._v = value

def get_literal(self) -> str:
"""Gets the lexical value of this literal. Note that the language tag is not included.
boolean True/False should be true/false in string
Returns:
The lexical value of this literal.
"""
return str(self._v).lower()

def __eq__(self, other):
if type(other) is type(self):
return self._v == other._v
Expand All @@ -297,6 +309,8 @@ def parse_boolean(self) -> bool:
def get_datatype(self) -> OWLDatatype:
# documented in parent
return BooleanOWLDatatype


@total_ordering
class _OWLLiteralImplString(OWLLiteral):
__slots__ = '_v'
Expand Down Expand Up @@ -339,6 +353,8 @@ def parse_string(self) -> str:
def get_datatype(self) -> OWLDatatype:
# documented in parent
return StringOWLDatatype


@total_ordering
class _OWLLiteralImplDate(OWLLiteral):
__slots__ = '_v'
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
setup(
name="owlapy",
description="OWLAPY is a Python Framework for creating and manipulating OWL Ontologies.",
version="1.0.0",
version="1.0.2",
packages=find_packages(),
install_requires=[
"pandas>=1.5.0",
Expand All @@ -16,10 +16,10 @@
author_email='caglardemir8@gmail.com',
url='https://github.com/dice-group/owlapy',
classifiers=[
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.10.13",
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Topic :: Scientific/Engineering"],
python_requires='>=3.10',
python_requires='>=3.10.13',
long_description=long_description,
long_description_content_type="text/markdown",
)
2 changes: 1 addition & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_readme(self):
male_teachers_with_children = OWLObjectIntersectionOf([males_with_children, teacher])

assert owl_expression_to_dl(male_teachers_with_children)=="(∃ hasChild.male) ⊓ teacher"
assert owl_expression_to_sparql("?x", male_teachers_with_children)=="""SELECT
assert owl_expression_to_sparql(male_teachers_with_children)=="""SELECT
DISTINCT ?x WHERE {
?x <http://example.com/society#hasChild> ?s_1 .
?s_1 a <http://example.com/society#male> .
Expand Down

0 comments on commit 5994940

Please sign in to comment.