diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 07b5b5dc..4b8019da 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,56 +1,63 @@ -#name: Build docs -# -#on: -# push: -# branches: -# - master -# - develop -# pull_request: -# -#jobs: -# docs: -# runs-on: ubuntu-latest -# strategy: -# max-parallel: 5 -# -# steps: -# - uses: actions/checkout@v3 -# - name: Install tox -# id: install-tox -# run: | -# pip install tox -# echo "tox_version=$(pip list | grep tox | tr -d ' ')" >> $GITHUB_OUTPUT -# - name: prepare required software -# run: | -# # epstopdf & dot & noto-fonts -# sudo apt update && sudo apt install texlive-font-utils graphviz fonts-noto -# - uses: actions/cache@v3 -# with: -# key: ${{ runner.os }}-${{ steps.install-tox.outputs.tox_version }}-docs-${{ hashFiles('environment.yml', 'tox.ini') }} -# path: .tox -# - name: Build docs with tox -# run: | -# tox -o -e docs -# - name: Build latex docs with tox -# run: | -# tox -o -e docs -- latex -# - name: Compile LaTeX document -# uses: docker://texlive/texlive:latest -# with: -# args: make -C docs/_build/latex -# - run: | -# cp docs/_build/latex/ontolearn.pdf docs/_build/html/ -# - name: Deploy to netlify -# uses: nwtgck/actions-netlify@v1.2 -# with: -# publish-dir: 'docs/_build/html' -# production-branch: develop -# github-token: ${{ secrets.GITHUB_TOKEN }} -# deploy-message: "Deploy from GitHub Actions ${{ github.sha }}" -# alias: ${{ github.head_ref }} -# enable-pull-request-comment: false -# enable-commit-comment: false -# env: -# NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} -# NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} -# timeout-minutes: 5 +name: Build docs + +on: + push: + branches: + - master + - develop + pull_request: + +jobs: + docs: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.9.18" ] + 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: Prepare required software + run: | + # epstopdf & dot & noto-fonts + sudo apt update && sudo apt install texlive-font-utils graphviz fonts-noto\ + + - name: Build docs + run: | + sphinx-build -M html docs/ docs/_build/ + + - name: Build LaTeX docs + run: | + sphinx-build -M latex docs/ docs/_build/ + + - name: Compile LaTeX document + uses: docker://texlive/texlive:latest + with: + args: make -C docs/_build/latex + - run: | + cp docs/_build/latex/ontolearn.pdf docs/_build/html/ + + - name: Deploy to netlify + uses: nwtgck/actions-netlify@v1.2 + with: + publish-dir: 'docs/_build/html' + production-branch: develop + github-token: ${{ secrets.GITHUB_TOKEN }} + deploy-message: "Deploy from GitHub Actions ${{ github.sha }}" + alias: ${{ github.head_ref }} + enable-pull-request-comment: false + enable-commit-comment: false + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + timeout-minutes: 5 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 85607ffd..34ce4ce8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,11 +15,6 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - # - name: Set up Conda - # uses: conda-incubator/setup-miniconda@v2 - # with: - # environment-file: environment.yml - # conda run -n test pytest -p no:warnings -x - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.mailmap b/.mailmap deleted file mode 100644 index a9e96e92..00000000 --- a/.mailmap +++ /dev/null @@ -1 +0,0 @@ -Caglar Demir diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 9312c357..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,11 +0,0 @@ -include LICENSE -include tox.ini -include *.conf -recursive-include KGs *.owl -recursive-include KGs *.ttl -recursive-include examples *.py -recursive-include examples *.json -recursive-include examples *.conf -recursive-include tests *.py -prune *.egg-info -prune .tox diff --git a/README.md b/README.md index 71c15d84..9a3bbed7 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ pip install ontolearn or ```shell git clone https://github.com/dice-group/Ontolearn.git -conda create --name onto python=3.9.18 && conda activate onto && pip3 install -e . && python -c "import ontolearn" -# To download knowledge graphs +python -m venv venv && source venv/bin/activate # for Windows use: .\venv\Scripts\activate +pip install -r requirements.txt wget https://files.dice-research.org/projects/Ontolearn/KGs.zip -O ./KGs.zip && unzip KGs.zip ``` @@ -153,10 +153,11 @@ python -c 'import pandas as pd; print(pd.read_csv("carcinogenesis_results.csv", ## Deployment ```shell -pip install gradio +pip install gradio # (check `pip show gradio` first) ``` -To deploy **EvoLearner** on the **Family** knowledge graph. Available models to deploy: **EvoLearner**, **NCES**, **CELOE** and **OCEL**. +Available models to deploy: **EvoLearner**, **NCES**, **CELOE** and **OCEL**. +To deploy **EvoLearner** on the **Family** knowledge graph: ```shell python deploy_cl.py --model evolearner --path_knowledge_base KGs/Family/family-benchmark_rich_background.owl ``` diff --git a/docs/api.rst b/docs/api.rst deleted file mode 100644 index 2f7a5926..00000000 --- a/docs/api.rst +++ /dev/null @@ -1,9 +0,0 @@ -Ontolearn API -============= - -.. autosummary:: - :toctree: source - :recursive: - - ontolearn - owlapy diff --git a/docs/conf.py b/docs/conf.py index a9d7c52d..1362c51a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,10 +10,9 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # -# import os -# import sys -# sys.path.insert(0, os.path.abspath('.')) - +import os +import sys +sys.path.insert(0, os.path.abspath('..')) # -- Project information ----------------------------------------------------- @@ -27,11 +26,8 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinxext_autox', + 'autoapi.extension', 'sphinx.ext.githubpages', - # 'sphinx.ext.intersphinx', - # 'sphinx_automodapi.smart_resolver', - # 'sphinx.ext.inheritance_diagram', 'sphinx.ext.napoleon', 'sphinx.ext.viewcode', 'sphinxcontrib.plantuml', @@ -39,6 +35,16 @@ 'sphinx_rtd_theme', ] +# autoapi for ontolearn and owlapy. for owlapy we need to refer to its path in GitHub Action environment +autoapi_dirs = ['../ontolearn', '/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/site-packages/owlapy'] + +# by default all are included but had to reinitialize this to remove private members from shoing +autoapi_options = ['members', 'undoc-members', 'show-inheritance', 'show-module-summary', 'special-members', + 'imported-members'] +# this is set to false, so we can add it manually in index.rst together with the other .md files of the documentation. +autoapi_add_toctree_entry = False + + inheritance_graph_attrs = dict(rankdir="TB") myst_enable_extensions = [ diff --git a/docs/index.rst b/docs/index.rst index 6d43e799..cfb56ad2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -16,7 +16,8 @@ Ontolearn is an open-source software library for explainable structured machine usage/07_reasoning_details usage/08_model_adapter usage/09_further_resources - api + autoapi/ontolearn/index + autoapi/owlapy/index .. raw:: latex diff --git a/docs/usage/01_introduction.md b/docs/usage/01_introduction.md index 48473609..85b380ff 100644 --- a/docs/usage/01_introduction.md +++ b/docs/usage/01_introduction.md @@ -1,6 +1,6 @@ # Ontolearn -**Version:** ontolearn 0.6.0 +**Version:** ontolearn 0.6.2 **GitHub repository:** [https://github.com/dice-group/Ontolearn](https://github.com/dice-group/Ontolearn) diff --git a/docs/usage/02_installation.md b/docs/usage/02_installation.md index 3abbb048..e1cbb82e 100644 --- a/docs/usage/02_installation.md +++ b/docs/usage/02_installation.md @@ -5,19 +5,15 @@ your system. Python comes in various versions and with different, sometimes conflicting dependencies. Hence, most guides will recommend to set up a "virtual environment" to work in. -One such system for virtual python environments is -[Anaconda](https://www.anaconda.com/). You can download miniconda from -. +One such system for virtual python environments is python +[venv](https://docs.python.org/3/library/venv.html). Since the command comes +together with python, you don't need to install any external tool. -We have good experience with it and make use of conda in the -[Installation from source](#installation-from-source) step. ## Installation via _pip_ Released versions of Ontolearn can be installed using `pip`, the -Package Installer for Python. It comes as part of Python. Please -research externally (or use `conda create` command below) on how to -create virtual environments for Python programs. +Package Installer for Python. `pip` comes as part of Python. ```shell pip install ontolearn @@ -30,39 +26,36 @@ and all its dependencies from . To download the Ontolearn source code, you will also need to have a copy of the [Git](https://git-scm.com/) version control system. -If you haven't, you might also need to install java and curl: + +Install java and curl: ```shell +# for Unix systems (Linux and macOS) sudo apt install openjdk-11-jdk sudo apt install curl +# for Windows please check online for yourself :) ``` +Once you have the done previous step, you can continue setting up a virtual +environment and installing the dependencies. You may as well use your IDE interface +to set up your venv. -Once you have `conda` and `git` installed, the following commands -should be typed in your shell in order to download the Ontolearn -development sources, install the dependencies listened in the -`environment.yml` into a conda environment and create the necessary -installation links to get started with the library. - -* Download (clone) the source code +* ->First download (clone) the source code ```shell git clone https://github.com/dice-group/Ontolearn.git cd Ontolearn ``` -* Create a conda environment using the `environment.yml` file. - ```shell - conda env create -f environment.yml - conda activate ontolearn - ``` -* Install the development links so that Python will find the library +* ->Create a python virtual environment. (We are not using conda anymore) ```shell - python -c 'from setuptools import setup; setup()' develop + python -m venv venv + source venv/bin/activate # --> for Unix systems + # .\venv\Scripts\activate --> for Windows ``` -* Instead of the previous step there is also Possibility B, which is valid temporarily only in your current shell: +* ->Install the dependencies ```shell - export PYTHONPATH=$PWD + pip install -r requirements.txt ``` - + Now you are ready to develop on Ontolearn or use the library! ### Verify installation @@ -82,12 +75,16 @@ to successfully pass all the tests: ```shell pytest ``` +Note: Since Unix and Windows reference files differently, the test are set to work on Linux +but in Widows the filepaths throughout test cases should be changed which is something that +is not very convenient to do. If you really want to run the tests in Windows, you can +make use of the replace all functionality to change them. ## Download External Files Some resources like pre-calculated embeddings or `pre_trained_agents` and datasets (ontologies) are not included in the repository directly. Use the command line command `wget` - to download them from our data server. +to download them from our data server. > **NOTE: Before you run this commands in your terminal, make sure you are in the root directory of the project!** @@ -133,10 +130,11 @@ rm -f NCESData.zip ## Building (sdist and bdist_wheel) -In order to create a *distribution* of the Ontolearn source code, typically when creating a new release, it is necessary to use the `build` tool. It can be invoked with: +In order to create a *distribution* of the Ontolearn source code, typically when creating a new release, +it is necessary to use the `build` tool. It can be invoked with: ```shell -tox -e build +python -m build ``` from the main source code folder. Packages created by `build` can then @@ -149,14 +147,14 @@ be uploaded as releases to the [Python Package Index (PyPI)](https://pypi.org/) The documentation can be built with ```shell -tox -e docs +sphinx-build -M html docs/ docs/_build/ ``` It is also possible to create a PDF manual, but that requires LaTeX to be installed: ```shell -tox -e docs latexpdf +sphinx-build -M latex docs/ docs/_build/ ``` ## Simple Linting diff --git a/docs/usage/03_ontologies.md b/docs/usage/03_ontologies.md index 713c0e1c..b827de77 100644 --- a/docs/usage/03_ontologies.md +++ b/docs/usage/03_ontologies.md @@ -25,7 +25,7 @@ are six persons (individuals), of which four are male and two are female. ## Loading an Ontology To load an ontology as well as to manage it, you will need an -[OWLOntologyManager](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L3245) +[OWLOntologyManager](owlapy.model.OWLOntologyManager) (this is an abstract class, concrete implementation in Ontolearn is mentioned below). An ontology can be loaded using the following Python code: @@ -59,7 +59,7 @@ You can get the object properties in the signature: onto.object_properties_in_signature() ``` -For more methods, see the owlapy abstract class [OWLOntology](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L3064) +For more methods, see the owlapy abstract class [OWLOntology](owlapy.model.OWLOntology) or the concrete implementation in Ontolearn [OWLOntology_Owlready2](ontolearn.base.OWLOntology_Owlready2). ## Modifying an Ontology @@ -73,12 +73,12 @@ allowing the ontology to evolve and adapt as new knowledge is gained. In owlapy we also have different axioms represented by different classes. You can check all the axioms classes [here](https://github.com/dice-group/owlapy/blob/main/owlapy/model/__init__.py). Some frequently used axioms are: -- [OWLDeclarationAxiom](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L2027) -- [OWLObjectPropertyAssertionAxiom](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L2817) -- [OWLDataPropertyAssertionAxiom](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L2835) -- [OWLClassAssertionAxiom](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L2447) -- [OWLSubClassOfAxiom](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L2368) -- [OWLEquivalentClassesAxiom](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L2183) +- [OWLDeclarationAxiom](owlapy.model.OWLDeclarationAxiom) +- [OWLObjectPropertyAssertionAxiom](owlapy.model.OWLObjectPropertyAssertionAxiom) +- [OWLDataPropertyAssertionAxiom](owlapy.model.OWLDataPropertyAssertionAxiom) +- [OWLClassAssertionAxiom](owlapy.model.OWLClassAssertionAxiom) +- [OWLSubClassOfAxiom](owlapy.model.OWLSubClassOfAxiom) +- [OWLEquivalentClassesAxiom](owlapy.model.OWLEquivalentClassesAxiom) #### Add a new Class @@ -99,21 +99,21 @@ child_class_declaration_axiom = OWLDeclarationAxiom(child_class) manager.add_axiom(onto, child_class_declaration_axiom) ``` In this example, we added the class 'child' to the father.owl ontology. -Firstly we create an instance of [OWLClass](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L209) to represent the concept -of 'child' by using an [IRI](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/_iri.py#L47). +Firstly we create an instance of [OWLClass](owlapy.model.OWLClass) to represent the concept +of 'child' by using an [IRI](owlapy.model.IRI). On the other side, an instance of `IRI` is created by passing two arguments which are the namespace of the ontology and the remainder 'child'. To declare this new class we need an axiom of type `OWLDeclarationAxiom`. We simply pass the `child_class` to create an instance of this axiom. The final step is to add this axiom to the ontology using the -[OWLOntologyManager](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L3245). We use the `add_axiom` method +[OWLOntologyManager](owlapy.model.OWLOntologyManager). We use the `add_axiom` method of the `manager` to add into the ontology `onto` the axiom `child_class_declaration_axiom`. #### Add a new Object Property / Data Property The idea is the same as adding a new class. Instead of `OWLClass`, for object properties, -you can use the class [OWLObjectProperty](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L380C7-L380C24) and for data -properties you can use the class [OWLDataProperty](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L356C11-L356C11). +you can use the class [OWLObjectProperty](owlapy.model.OWLObjectProperty) and for data +properties you can use the class [OWLDataProperty](owlapy.model.OWLDataProperty). @@ -132,7 +132,7 @@ hasAge_dp_declaration_axiom = OWLDeclarationAxiom(hasAge_dp) manager.add_axiom(onto, hasAge_dp_declaration_axiom) ``` -See the [owlapy](https://github.com/dice-group/owlapy/blob/main/owlapy/model/__init__.py) repository for more OWL entities that you can add as a declaration axiom. +See the [owlapy](owlapy) for more OWL entities that you can add as a declaration axiom. #### Add an Assertion Axiom @@ -156,7 +156,7 @@ want to assert a class axiom for the individual `heinz`. We have used the class `OWLClassAssertionAxiom` where the first argument is the 'individual' `heinz` and the second argument is the 'class_expression'. As the class expression, we used the previously defined class -`child_Class`. Finally, add the axiom by using `add_axiom` method of the [OWLOntologyManager](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L3245). +`child_Class`. Finally, add the axiom by using `add_axiom` method of the [OWLOntologyManager](owlapy.model.OWLOntologyManager). Let's show one more example using a `OWLDataPropertyAssertionAxiom` to assign the age of 17 to heinz. @@ -173,14 +173,14 @@ dp_assertion_axiom = OWLDataPropertyAssertionAxiom(heinz, hasAge_dp, literal_17) manager.add_axiom(onto, dp_assertion_axiom) ``` -[OWLLiteral](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L1128) is a class that represents the literal values in +[OWLLiteral](owlapy.model.OWLLiteral) is a class that represents the literal values in Owlapy. We have stored the integer literal value of '18' in the variable `literal_17`. Then we construct the `OWLDataPropertyAssertionAxiom` by passing as the first argument, the individual `heinz`, as the second argument the data property `hasAge_dp`, and the third argument the literal value `literal_17`. Finally, add it to the ontology by using `add_axiom` method. -Check the [owlapy](https://github.com/dice-group/owlapy/blob/main/owlapy/model/__init__.py) repository to see all the OWL +Check the [owlapy](owlapy) to see all the OWL assertion axioms that you can use. @@ -199,7 +199,7 @@ argument is the axiom you want to remove. ## Save an Ontology If you modified an ontology, you may want to save it as a new file. To do this -you can use the `save_ontology` method of the [OWLOntologyManager](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L3245). +you can use the `save_ontology` method of the [OWLOntologyManager](owlapy.model.OWLOntologyManager). It requires two arguments, the first is the ontology you want to save and The second is the IRI of the new ontology. diff --git a/docs/usage/04_knowledge_base.md b/docs/usage/04_knowledge_base.md index 94b3474b..fcff1b81 100644 --- a/docs/usage/04_knowledge_base.md +++ b/docs/usage/04_knowledge_base.md @@ -2,8 +2,8 @@ In Ontolearn we represent a knowledge base by the class [KnowledgeBase](ontolearn.knowledge_base.KnowledgeBase) which contains two main class attributes, -an ontology [OWLOntology](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L3064) -and a reasoner [OWLReasoner](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L3322). +an ontology [OWLOntology](owlapy.model.OWLOntology) +and a reasoner [OWLReasoner](owlapy.model.OWLReasoner). It also contains the class and properties hierarchy as well as other Ontology-related attributes required for the Structured Machine Learning library. @@ -19,7 +19,7 @@ differently from the ontology you can use methods that require reasoning. You ca the methods for each in the links below: - [KnowledgeBase](ontolearn.knowledge_base.KnowledgeBase) -- [OWLOntology](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L3064) +- [OWLOntology](owlapy.model.OWLOntology) In summary: @@ -80,7 +80,7 @@ concepts_to_ignore = {father_concept} # you can add more than 1 new_kb = kb.ignore_and_copy(ignored_classes=concepts_to_ignore) ``` -In this example, we have created an instance of [OWLClass](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L209) by using an [IRI](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/_iri.py#L47). +In this example, we have created an instance of [OWLClass](owlapy.model.OWLClass) by using an [IRI](owlapy.model.IRI). On the other side, an instance of `IRI` is created by passing two parameters which are the namespace of the ontology and the remainder 'Father'. @@ -90,7 +90,7 @@ You may need to work with individuals of a knowledge base. We cover different ways of accessing them. Let us give a simple example of how to get the individuals that -are classified by an [OWLClassExpression](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L209Expression). As a class expression, we will simply use the +are classified by an [OWLClassExpression](owlapy.model.OWLClassExpression). As a class expression, we will simply use the concept 'male'. @@ -143,7 +143,7 @@ When using a concept learner, the generated concepts (class expressions) for a c need to be evaluated to see the performance. To do that you can use the method `evaluate_concept` of `KnowledgeBase`. It requires the following arguments: -1. a concept to evaluate: [OWLClassExpression](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L209Expression) +1. a concept to evaluate: [OWLClassExpression](owlapy.model.OWLClassExpression) 2. a quality metric: [AbstractScorer](ontolearn.abstracts.AbstractScorer) 3. the encoded learning problem: [EncodedLearningProblem](ontolearn.learning_problem.EncodedPosNegLPStandard) @@ -209,11 +209,11 @@ concept_to_test = OWLObjectIntersectionOf([not_female, exist_has_child_T]) `kb` has an instance of [ConceptGenerator](ontolearn.concept_generator.ConceptGenerator) which we use in this case to create the negated concept `¬female`. The other classes -[OWLObjectProperty](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L380C7-L380C24), -[OWLObjectSomeValuesFrom](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L554) -and [OWLObjectIntersectionOf](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L650) are classes +[OWLObjectProperty](owlapy.model.OWLObjectProperty), +[OWLObjectSomeValuesFrom](owlapy.model.OWLObjectSomeValuesFrom) +and [OWLObjectIntersectionOf](owlapy.model.OWLObjectIntersectionOf) are classes that represent different kind of axioms in owlapy and can be found in -[owlapy model](https://github.com/dice-group/owlapy/blob/main/owlapy/model/__init__.py) module. There are more kind of axioms there which you +[owlapy model](owlapy.model) module. There are more kind of axioms there which you can use to construct class expressions like we did in the example above. ### Evaluation and results diff --git a/docs/usage/05_reasoner.md b/docs/usage/05_reasoner.md index 85c3b334..e1f288a2 100644 --- a/docs/usage/05_reasoner.md +++ b/docs/usage/05_reasoner.md @@ -31,7 +31,7 @@ from. Currently, there are the following reasoners available: structural_reasoner = OWLReasoner_Owlready2(onto) ``` - The structural reasoner requires an ontology ([OWLOntology](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L3064)). + The structural reasoner requires an ontology ([OWLOntology](owlapy.model.OWLOntology)). The second argument is `isolate` argument which isolates the world (therefore the ontology) where the reasoner is performing the reasoning. More on that on _[Reasoning Details](07_reasoning_details.md#isolated-world)_. The remaining argument, `triplestore_address`, is used in case you want to @@ -90,7 +90,7 @@ from. Currently, there are the following reasoners available: ## Usage of the Reasoner All the reasoners available in the Ontolearn library inherit from the class: [OWLReasonerEx](ontolearn.base.ext.OWLReasonerEx). This class provides some -extra convenient methods compared to its base class [OWLReasoner](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L3322), which is an +extra convenient methods compared to its base class [OWLReasoner](owlapy.model.OWLReasoner), which is an abstract class. Further in this guide, we use [OWLReasoner_Owlready2_ComplexCEInstances](ontolearn.base.OWLReasoner_Owlready2_ComplexCEInstances). @@ -103,7 +103,7 @@ you can find an overview of it [here](03_ontologies.md). ## Class Reasoning -Using an [OWLOntology](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L3064) you can list all the classes in the signature, +Using an [OWLOntology](owlapy.model.OWLOntology) you can list all the classes in the signature, but a reasoner can give you more than that. You can get the subclasses, superclasses or the equivalent classes of a class in the ontology: @@ -121,7 +121,7 @@ male_sub_classes = ccei_reasoner.sub_classes(male) male_equivalent_classes = ccei_reasoner.equivalent_classes(male) ``` -We define the _male_ class by creating an [OWLClass](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L209) object. The +We define the _male_ class by creating an [OWLClass](owlapy.model.OWLClass) object. The methods `super_classes` and `sub_classes` have 2 more boolean arguments: `direct` and `only_named`. If `direct=True` then only the direct classes in the hierarchy will be returned, else it will return every class in the hierarchy depending @@ -179,14 +179,14 @@ are more than 1, and we use the reasoner to get the values for each object property `op` of the individual `anna`. The values are individuals which we store in the variable `object_properties_values` and are printed in the end. The method `object_property_values` requires as the -first argument, an [OWLNamedIndividual](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L917) that is the subject of the object property values and -the second argument an [OWLObjectProperty](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L380C7-L380C24) whose values are to be retrieved for the +first argument, an [OWLNamedIndividual](owlapy.model.OWLNamedIndividual) that is the subject of the object property values and +the second argument an [OWLObjectProperty](owlapy.model.OWLObjectProperty) whose values are to be retrieved for the specified individual. > **NOTE:** You can as well get all the data properties of an individual in the same way by using `ind_data_properties` instead of `ind_object_properties` and `data_property_values` instead of `object_property_values`. Keep in mind that `data_property_values` returns literal values -(type of [OWLLiteral](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L1128)). +(type of [OWLLiteral](owlapy.model.OWLLiteral)). In the same way as with classes, you can also get the sub object properties or equivalent object properties. @@ -218,7 +218,7 @@ hasChild_ranges = ccei_reasoner.object_property_ranges(hasChild) The method `instances` is a very convenient method. It takes only 1 argument that is basically a class expression and returns all the individuals belonging to that class expression. In Owlapy we have implemented a Python class for each type of class expression. -The argument is of type [OWLClassExpression](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L209Expression). +The argument is of type [OWLClassExpression](owlapy.model.OWLClassExpression). Let us now show a simple example by finding the instances of the class _male_ and printing them: diff --git a/docs/usage/06_concept_learners.md b/docs/usage/06_concept_learners.md index 6abee13b..187018f4 100644 --- a/docs/usage/06_concept_learners.md +++ b/docs/usage/06_concept_learners.md @@ -149,8 +149,8 @@ typed_neg = set(map(OWLNamedIndividual, map(IRI.create, n))) lp = PosNegLPStandard(pos=typed_pos, neg=typed_neg) ``` -To construct an [OWLNamedIndividual](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/__init__.py#L917) -object an [IRI](https://github.com/dice-group/owlapy/blob/6a6338665a6df0845e67eda577327ca4c62f446b/owlapy/model/_iri.py#L47) is required as an input. +To construct an [OWLNamedIndividual](owlapy.model.OWLNamedIndividual) +object an [IRI](owlapy.model.IRI) is required as an input. You can simply create an `IRI` object by calling the static method `create` and passing the IRI as a `string`. diff --git a/environment.yml b/environment.yml deleted file mode 100644 index d06b459e..00000000 --- a/environment.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: ontolearn -channels: - - defaults - - conda-forge - - pytorch -dependencies: - - python=3.9.18 - - matplotlib=3.3.4 - - pandas=1.2.3 - - pytorch=1.8.0 - - rdflib=6.0.2 - - scikit-learn=1.0.2 - - sortedcontainers=2.4.0 - - flask=1.1.2 - - deap=1.3.1 - - httpx=0.21.1 - - parsimonious=0.8.1 - - tqdm=4.64.0 - # testing - - tox=3.24.3 - - tox-conda=0.8.3 - - pytest=6.2.4 - - pytest-codeblocks=0.11.2 - # linting - - flake8=3.9.2 - # docs - - sphinx=4.0.2 - - sphinx_rtd_theme=0.5.1 - - myst-parser==0.15.2 - # # building - - build=0.6.0 - # PIP - - pip=21.0.1 - - pip: - - dicee==0.1.2 - - owlready2==0.40 - - owlapy==0.1.0 - - tokenizers==0.12.1 - - transformers==4.19.2 - # testing - - tox-run-before==0.1 - # docs - - sphinxext-autox==0.0.2 - - sphinx-theme==1.0 - - sphinxcontrib-plantuml==0.21 - - plantuml-local-client==1.2021.10 - - jinja2==3.1.2 diff --git a/ontolearn/nces_embeddings/util/experiment.py b/ontolearn/nces_embeddings/util/experiment.py index af61ff64..ef17af6f 100644 --- a/ontolearn/nces_embeddings/util/experiment.py +++ b/ontolearn/nces_embeddings/util/experiment.py @@ -1,10 +1,10 @@ import json - +import os +import numpy as np import torch -from .helper_funcs import * -from .helper_classes import * -from .complex_models import * -from .real_models import * +from ontolearn.nces_embeddings.util.complex_models import ConEx, Complex +from ontolearn.nces_embeddings.util.helper_classes import HeadAndRelationBatchLoader, DatasetTriple +from ontolearn.nces_embeddings.util.real_models import Distmult, Tucker, TransE from torch.optim.lr_scheduler import ExponentialLR from collections import defaultdict from torch.utils.data import DataLoader diff --git a/ontolearn/nces_embeddings/util/helper_classes.py b/ontolearn/nces_embeddings/util/helper_classes.py index 3987a43f..078098b0 100644 --- a/ontolearn/nces_embeddings/util/helper_classes.py +++ b/ontolearn/nces_embeddings/util/helper_classes.py @@ -1,8 +1,8 @@ import json -from .data import Data -from .helper_funcs import * -from .complex_models import Complex, ConEx -from .real_models import Distmult, Tucker +import json +from ontolearn.nces_embeddings.util.data import Data +from ontolearn.nces_embeddings.util.complex_models import Complex, ConEx +from ontolearn.nces_embeddings.util.real_models import Distmult, Tucker from torch.optim.lr_scheduler import ExponentialLR from collections import defaultdict from torch.utils.data import DataLoader diff --git a/requirements.txt b/requirements.txt index 33365eeb..9203c295 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,18 +1,24 @@ -scikit-learn>=0.24.1 +scikit-learn>=1.0.2 matplotlib>=3.3.4 -owlready2>=0.40 torch>=1.7.1 rdflib>=6.0.2 pandas>=1.5.0 sortedcontainers>=2.4.0 flask>=1.1.2 deap>=1.3.1 -httpx>=0.21.1 -parsimonious>=0.8.1 +httpx>=0.25.2 tqdm>=4.64.0 -tokenizers>=0.12.1 -transformers>=4.19.2 -requests>=2.31.0 +transformers>=4.35.0 +owlready2>=0.41 owlapy>=0.1.0 dicee>=0.1.2 -pytest>=7.2.2 \ No newline at end of file +flake8>=6.0.0 +sphinx>=7.2.6 +sphinx-autoapi>=3.0.0 +sphinx_rtd_theme>=2.0.0 +sphinx-theme>=1.0 +sphinxcontrib-plantuml>=0.27 +plantuml-local-client>=1.2022.6 +myst-parser>=2.0.0 +pytest>=7.2.2 +build>=1.0.3 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 01f5a4e7..00000000 --- a/setup.cfg +++ /dev/null @@ -1,65 +0,0 @@ -[metadata] -name = ontolearn -version = attr: ontolearn.__version__ -description = Ontolearn is an open-source software library for structured machine learning in Python. Ontolearn includes modules for processing knowledge bases, inductive logic programming and ontology engineering. -author = Ontolearn team -author_email = onto-learn@lists.uni-paderborn.de -long_description = file: README.md -long_description_content_type = text/markdown -classifiers = - Programming Language :: Python :: 3.8 - License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+) - Topic :: Scientific/Engineering :: Artificial Intelligence - -[options] -python_requires = >=3.8 -include_package_data = True -packages = find: -scripts = - ontolearn/endpoint/simple_drill_endpoint -install_requires = - typing_extensions; python_version < "3.7" - scikit-learn>=0.24.1 - matplotlib>=3.3.4 - owlready2>=0.40 - torch>=1.7.1 - rdflib>=6.0.2 - pandas>=1.5.0 - sortedcontainers>=2.4.0 - flask>=1.1.2 - deap>=1.3.1 - httpx>=0.21.1 - parsimonious>=0.8.1 - tqdm>=4.64.0 - tokenizers>=0.12.1 - transformers>=4.19.2 - dicee>=0.1.2 - -[options.extras_require] -test = - pytest>=6.2.4 - pytest-codeblocks>=0.11.2 - tox>=3.24.3 - tox-run-before>=0.1 -docs = - sphinx>=4.0.2 - sphinxext-autox>=0.0.2 - sphinx-theme>=1.0 - sphinx-rtd-theme>=0.5.1 - sphinxcontrib-plantuml>=0.21 - plantuml-local-client>=1.2021.10 - myst-parser>=0.15.2 -lint = - flake8>=3.9.2 -dev = - build>=0.6.0 - %(test)s - %(docs)s - -[options.packages.find] -exclude = - tests - examples - -[options.package_data] -* = *.pyi, py.typed diff --git a/setup.py b/setup.py index f74d8b13..135dc517 100644 --- a/setup.py +++ b/setup.py @@ -17,11 +17,9 @@ "sortedcontainers>=2.4.0", "flask>=1.1.2", "deap>=1.3.1", - "httpx>=0.21.1", - "parsimonious>=0.8.1", + "httpx>=0.25.2", "tqdm>=4.64.0", - "tokenizers>=0.12.1", - "transformers>=4.19.2", + "transformers>=4.35.0", "pytest>=7.2.2", "owlapy>=0.1.0", "dicee>=0.1.2"], diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 147f6c08..00000000 --- a/tox.ini +++ /dev/null @@ -1,55 +0,0 @@ -[flake8] -max-line-length = 120 - -[tox] -isolated_build = True -# investigate: higher versions of tox-conda break the build -requires = tox-conda==0.9.2 - tox-run-before -envlist = - # py37 - py38 - -[testenv] -conda_env = environment.yml -conda_install_args= - --override-channels -extras = test -description = test Ontolearn -run_before = - ./big_gitext/download_big.sh KGs/Mutagenesis/mutagenesis.owl -commands = - pytest --continue-on-collection-errors --codeblocks {posargs} --ignore=./docs/usage - -[testenv:build] -extras = dev -description = build Ontolearn package -commands = - python -m build - -[testenv:clean] -skip_install = True -description = delete the built package -commands = - python -c 'from shutil import rmtree; rmtree("build", True); rmtree("dist", True)' - -[testenv:docs-clean] -skip_install = True -description = delete the built docs -commands = - python -c 'from shutil import rmtree; rmtree("docs/_build", True);' - -[testenv:docs] -extras = docs -description = build Ontolearn docs -commands = - sphinx-build -M {posargs:html} docs/ docs/_build/ -commands_post = - python -c 'print("documentation can be found in file://{toxinidir}/docs/_build/")' - -[testenv:lint] -extras = lint -skip_install = True -description = lint the source code with flake8 -commands = - flake8 . {posargs}