-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,20 @@ | ||
# owlapy | ||
**Version: 0.1.0** | ||
|
||
Owlapy is loosely based on owlapi, successfully representing the main | ||
owl objects in python. | ||
|
||
Other than that, Owlapy also offers some extra functionalities: | ||
- `Owl2SparqlConverter` to convert owl class expressions to SPARQL syntax. | ||
- `DLSyntaxObjectRenderer` to render owl objects to description logics. | ||
- `ManchesterOWLSyntaxParser` to parse strings of manchester syntax to owl class expression. | ||
|
||
For more, please feel free to explore the project for yourself which is made | ||
easier due to the well documented code. | ||
|
||
|
||
## Installation | ||
|
||
```shell | ||
pip install owlapy | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""OWLAPY - loosely based on OWL API. | ||
Many help texts copied from OWL API [1] | ||
OWLAPI licence: LGPL and Apache | ||
[1] https://github.com/owlcs/owlapi | ||
""" | ||
|
||
# the import order must be fixed otherwise there are circular import errors |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def MOVE(*args): | ||
""""Move" an imported class to the current module by setting the classes __module__ attribute. | ||
This is useful for documentation purposes to hide internal packages in sphinx. | ||
Args: | ||
args: List of classes to move. | ||
""" | ||
from inspect import currentframe | ||
f = currentframe() | ||
f = f.f_back | ||
mod = f.f_globals['__name__'] | ||
for cls in args: | ||
cls.__module__ = mod |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"""Extra classes.""" | ||
import logging | ||
from abc import ABCMeta | ||
from typing import Iterable | ||
|
||
from owlapy.model import OWLNamedIndividual, OWLObjectProperty, OWLReasoner, OWLDataProperty, OWLDataRange, \ | ||
OWLLiteral | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class OWLReasonerEx(OWLReasoner, metaclass=ABCMeta): | ||
"""Extra convenience methods for OWL Reasoners | ||
(Not part of OWLAPI)""" | ||
|
||
# default | ||
def data_property_ranges(self, pe: OWLDataProperty, direct: bool = False) -> Iterable[OWLDataRange]: | ||
"""Gets the data ranges that are the direct or indirect ranges of this property with respect to the imports | ||
closure of the root ontology. | ||
Args: | ||
pe: The property expression whose ranges are to be retrieved. | ||
direct: Specifies if the direct ranges should be retrieved (True), or if all ranges should be retrieved | ||
(False). | ||
Returns: | ||
""" | ||
for ax in self.get_root_ontology().data_property_range_axioms(pe): | ||
yield ax.get_range() | ||
if not direct: | ||
logger.warning("indirect not implemented") | ||
# TODO: | ||
|
||
# default | ||
def all_data_property_values(self, pe: OWLDataProperty, direct: bool = True) -> Iterable[OWLLiteral]: | ||
"""Gets all values for the given data property expression that appear in the knowledge base. | ||
Args: | ||
pe: The data property expression whose values are to be retrieved | ||
direct: Specifies if only the direct values of the data property pe should be retrieved (True), or if | ||
the values of sub properties of pe should be taken into account (False). | ||
Returns: | ||
A set of OWLLiterals containing literals such that for each literal l in the set, the set of reasoner | ||
axioms entails DataPropertyAssertion(pe ind l) for any ind. | ||
""" | ||
onto = self.get_root_ontology() | ||
for ind in onto.individuals_in_signature(): | ||
for lit in self.data_property_values(ind, pe, direct): | ||
yield lit | ||
|
||
# default | ||
def ind_data_properties(self, ind: OWLNamedIndividual, direct: bool = True) -> Iterable[OWLDataProperty]: | ||
"""Gets all data properties for the given individual that appear in the knowledge base. | ||
Args: | ||
ind: The named individual whose data properties are to be retrieved | ||
direct: Specifies if the direct data properties should be retrieved (True), or if all | ||
data properties should be retrieved (False), so that sub properties are taken into account. | ||
Returns: | ||
All data properties pe where the set of reasoner axioms entails DataPropertyAssertion(pe ind l) | ||
for atleast one l. | ||
""" | ||
onto = self.get_root_ontology() | ||
for dp in onto.data_properties_in_signature(): | ||
try: | ||
next(iter(self.data_property_values(ind, dp, direct))) | ||
yield dp | ||
except StopIteration: | ||
pass | ||
|
||
# default | ||
def ind_object_properties(self, ind: OWLNamedIndividual, direct: bool = True) -> Iterable[OWLObjectProperty]: | ||
"""Gets all object properties for the given individual that appear in the knowledge base. | ||
Args: | ||
ind: The named individual whose object properties are to be retrieved | ||
direct: Specifies if the direct object properties should be retrieved (True), or if all | ||
object properties should be retrieved (False), so that sub properties are taken into account. | ||
Returns: | ||
All data properties pe where the set of reasoner axioms entails ObjectPropertyAssertion(pe ind ind2) | ||
for atleast one ind2. | ||
""" | ||
onto = self.get_root_ontology() | ||
for op in onto.object_properties_in_signature(): | ||
try: | ||
next(iter(self.object_property_values(ind, op, direct))) | ||
yield op | ||
except StopIteration: | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Abstract renderer and parser classes.""" | ||
from abc import abstractmethod, ABCMeta | ||
|
||
from owlapy.model import OWLObject | ||
|
||
|
||
class OWLObjectRenderer(metaclass=ABCMeta): | ||
"""Abstract class with a render method to render an OWL Object into a string.""" | ||
@abstractmethod | ||
def set_short_form_provider(self, short_form_provider) -> None: | ||
"""Configure a short form provider that shortens the OWL objects during rendering. | ||
Args: | ||
short_form_provider: Short form provider. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
def render(self, o: OWLObject) -> str: | ||
"""Render OWL Object to string. | ||
Args: | ||
o: OWL Object. | ||
Returns: | ||
String rendition of OWL object. | ||
""" | ||
pass | ||
|
||
|
||
class OWLObjectParser(metaclass=ABCMeta): | ||
"""Abstract class with a parse method to parse a string to an OWL Object.""" | ||
@abstractmethod | ||
def parse_expression(self, expression_str: str) -> OWLObject: | ||
"""Parse a string to an OWL Object. | ||
Args: | ||
expression_str (str): Expression string. | ||
Returns: | ||
The OWL Object which is represented by the string. | ||
""" | ||
pass |