Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reasoner adjustments #269

Merged
merged 10 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 51 additions & 24 deletions KGs/test_ontology.owl
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11"/>



<!--

<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r1 -->

<owl:ObjectProperty rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r1">
<rdfs:domain rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#H"/>
<!-- <rdfs:domain rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#AB"/> -->
<rdfs:range rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#G"/>
</owl:ObjectProperty>

Expand All @@ -35,6 +35,13 @@
<rdfs:subPropertyOf rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r1"/>
</owl:ObjectProperty>

<owl:DatatypeProperty rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#dp1"/>

<owl:DatatypeProperty rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#dp2">
<rdfs:subPropertyOf rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#dp1"/>
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#dp3"/>

<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r3 -->

Expand All @@ -44,10 +51,22 @@


<owl:ObjectProperty rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r4">
<rdfs:subPropertyOf rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r3"/>
<!-- <rdfs:subPropertyOf rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r3"/> -->
</owl:ObjectProperty>

<owl:AllDisjointProperties>
<owl:members rdf:parseType="Collection">
<rdf:Description rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r5"/>
<rdf:Description rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r1"/>
</owl:members>
</owl:AllDisjointProperties>

<owl:AllDisjointProperties>
<owl:members rdf:parseType="Collection">
<rdf:Description rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#dp1"/>
<rdf:Description rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#dp3"/>
</owl:members>
</owl:AllDisjointProperties>

<owl:ObjectProperty rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r5"/>

Expand All @@ -56,7 +75,7 @@
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r7"/>


<!--
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
Expand All @@ -70,7 +89,7 @@
<owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#A"/>





<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#AB -->
Expand All @@ -88,19 +107,19 @@
<owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#C"/>
</rdfs:subClassOf>
</owl:Class>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#B -->

<owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#B"/>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#C -->

<owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#C"/>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#D -->
Expand All @@ -118,13 +137,13 @@
</owl:Class>
</rdfs:subClassOf>
</owl:Class>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#E -->

<owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#E"/>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#F -->
Expand All @@ -144,14 +163,14 @@
<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#G -->

<owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#G"/>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#H -->

<owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#H">
</owl:Class>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#I -->
Expand Down Expand Up @@ -211,9 +230,9 @@
</owl:Class>

<owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#P">
<rdfs:subClassOf>
<owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#O"/>
</rdfs:subClassOf>
<!-- <rdfs:subClassOf> -->
<!-- <owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#O"/> -->
<!-- </rdfs:subClassOf> -->
</owl:Class>

<owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#Q"/>
Expand Down Expand Up @@ -247,7 +266,7 @@

<!-- <owl:Class rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#Z"/>-->

<!--
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Individuals
Expand All @@ -262,7 +281,6 @@
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#p">
<rdf:type rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#P"/>
</owl:NamedIndividual>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#a -->
Expand All @@ -272,7 +290,7 @@
<rdf:type rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#B"/>

</owl:NamedIndividual>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#b -->
Expand All @@ -282,23 +300,23 @@

<r7 rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#f"/>
</owl:NamedIndividual>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#c -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#c">
<rdf:type rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#I"/>
</owl:NamedIndividual>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#d -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#d">
<rdf:type rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#D"/>
</owl:NamedIndividual>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#e -->
Expand All @@ -307,7 +325,7 @@
<rdf:type rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#AB"/>

</owl:NamedIndividual>



<!-- http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#f -->
Expand All @@ -334,6 +352,7 @@
<r3 rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#q"/>
<r4 rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#l"/>
<r6 rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#s"/>
<r5 rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#q"/>
</owl:NamedIndividual>

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#m">
Expand All @@ -351,16 +370,24 @@
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#ind1">
<r5 rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#q"/>
<r2 rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#g"/>
<r6 rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#s"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#r">
<rdf:type rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#R"/>
<!-- <owl:sameAs rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#s"/> -->
</owl:NamedIndividual>

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#s">
<rdf:type rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#S"/>
<rdf:type rdf:resource="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#T"/>
</owl:NamedIndividual>

<owl:AllDifferent>
<owl:distinctMembers rdf:parseType="Collection">
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#l"/>
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/stefan/ontologies/2023/1/untitled-ontology-11#m"/>
</owl:distinctMembers>
</owl:AllDifferent>
</rdf:RDF>


Expand Down
5 changes: 3 additions & 2 deletions docs/usage/04_reasoner.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ from. Currently, there are the following reasoners available for you to choose f
To load any reasoner, use the following code:

<!--pytest-codeblocks:cont-->

```python
from owlapy.owlready2 import OWLReasoner_Owlready2
from owlapy.owlready2.temp_classes import OWLReasoner_Owlready2_TempClasses
from owlapy.owlready2.complex_ce_instances import OWLReasoner_Owlready2_ComplexCEInstances
from owlapy.fast_instance_checker import OWLReasoner_FastInstanceChecker

structural_reasoner = OWLReasoner_Owlready2(onto)
temp_classes_reasoner = OWLReasoner_Owlready2_TempClasses(onto)
temp_classes_reasoner = OWLReasoner_Owlready2_ComplexCEInstances(onto)
fast_instance_checker = OWLReasoner_FastInstanceChecker(onto, temp_classes_reasoner)
```

Expand Down
8 changes: 4 additions & 4 deletions docs/usage/09_model_adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ from owlapy.fast_instance_checker import OWLReasoner_FastInstanceChecker
from owlapy.model import OWLOntology, OWLNamedIndividual, IRI
from owlapy.namespaces import Namespaces
from owlapy.owlready2 import OWLOntology_Owlready2, OWLOntologyManager_Owlready2
from owlapy.owlready2.temp_classes import OWLReasoner_Owlready2_TempClasses
from owlapy.owlready2.complex_ce_instances import OWLReasoner_Owlready2_ComplexCEInstances
from owlapy.render import DLSyntaxObjectRenderer


def my_reasoner_factory(onto: OWLOntology):
assert isinstance(onto, OWLOntology_Owlready2)
temp_classes_reasoner = OWLReasoner_Owlready2_TempClasses(onto)
temp_classes_reasoner = OWLReasoner_Owlready2_ComplexCEInstances(onto)
fast_instance_checker = OWLReasoner_FastInstanceChecker(
onto,
temp_classes_reasoner)
Expand All @@ -46,12 +46,12 @@ model = ModelAdapter(learner_type=CELOE,
expansionPenaltyFactor=0.05,
startNodeBonus=1.0,
nodeRefinementPenalty=0.01,
)
)

# no need to construct the IRI here ourselves
model.fit(pos=positive_examples,
neg=negative_examples,
)
)

dlsr = DLSyntaxObjectRenderer()

Expand Down
4 changes: 2 additions & 2 deletions examples/concept_learning_drill_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

def ClosedWorld_ReasonerFactory(onto: OWLOntology) -> OWLReasoner:
from owlapy.owlready2 import OWLOntology_Owlready2
from owlapy.owlready2.temp_classes import OWLReasoner_Owlready2_TempClasses
from owlapy.owlready2.complex_ce_instances import OWLReasoner_Owlready2_ComplexCEInstances
from owlapy.fast_instance_checker import OWLReasoner_FastInstanceChecker
assert isinstance(onto, OWLOntology_Owlready2)
base_reasoner = OWLReasoner_Owlready2_TempClasses(ontology=onto)
base_reasoner = OWLReasoner_Owlready2_ComplexCEInstances(ontology=onto)
reasoner = OWLReasoner_FastInstanceChecker(ontology=onto,
base_reasoner=base_reasoner,
negation_default=True)
Expand Down
17 changes: 14 additions & 3 deletions examples/concept_learning_with_celoe_heuristic_ma.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
import os
import random

from ontolearn.concept_learner import CELOE
from ontolearn.knowledge_base import KnowledgeBase
from ontolearn.model_adapter import ModelAdapter
from owlapy.model import OWLClass, OWLNamedIndividual, IRI
from ontolearn.utils import setup_logging

from owlapy.owlready2 import BaseReasoner_Owlready2, OWLOntology_Owlready2
from owlapy.owlready2.complex_ce_instances import OWLReasoner_Owlready2_ComplexCEInstances
from typing import cast
setup_logging()

try:
Expand All @@ -25,7 +29,7 @@
print('Target concept: ', str_target_concept)

concepts_to_ignore = None
# lets inject more background info
# let's inject more background info
if str_target_concept in ['Granddaughter', 'Aunt', 'Sister']:
NS = 'http://www.benchmark.org/family#'
concepts_to_ignore = {
Expand All @@ -48,9 +52,16 @@

typed_pos = set(map(OWLNamedIndividual, map(IRI.create, p)))
typed_neg = set(map(OWLNamedIndividual, map(IRI.create, n)))

kb = KnowledgeBase(path=settings['data_path'])
reasoner = OWLReasoner_Owlready2_ComplexCEInstances(cast(OWLOntology_Owlready2, kb.ontology()),
BaseReasoner_Owlready2.HERMIT)

model = ModelAdapter(path=settings['data_path'],
ignore=concepts_to_ignore,
max_runtime=600,
reasoner=reasoner,
learner_type=CELOE,
max_runtime=60,
max_num_of_concepts_tested=10_000_000_000,
iter_bound=10_000_000_000,
expansionPenaltyFactor=0.01)
Expand Down
Loading
Loading