Skip to content

Commit

Permalink
use single script for dbpedia concept learning with drill and tdl; up…
Browse files Browse the repository at this point in the history
…date README
  • Loading branch information
Jean-KOUAGOU committed Nov 22, 2024
1 parent 0d135c2 commit 4ae9527
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 40 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ save_owl_class_expressions(expressions=h,path="owl_prediction")
- With one command
1. For TDL
```bash
git clone https://github.com/dice-group/Ontolearn.git && cd Ontolearn && git checkout large_scale_cel && conda create -n venv python=3.10.14 --no-default-packages --y && conda activate venv && pip install -e . && wget https://files.dice-research.org/projects/Ontolearn/LPs.zip -O ./LPs.zip && unzip LPs.zip && python examples/dbpedia_concept_learning_with_tdl_and_triplestore.py
git clone https://github.com/dice-group/Ontolearn.git && cd Ontolearn && git checkout large_scale_cel && conda create -n venv python=3.10.14 --no-default-packages --y && conda activate venv && pip install -e . && wget https://files.dice-research.org/projects/Ontolearn/LPs.zip -O ./LPs.zip && unzip LPs.zip && python examples/dbpedia_concept_learning_with_ontolearn.py tdl
```
2. For Drill
```bash
git clone https://github.com/dice-group/Ontolearn.git && cd Ontolearn && git checkout large_scale_cel && conda create -n venv python=3.10.14 --no-default-packages --y && conda activate venv && pip install -e . && wget https://files.dice-research.org/projects/Ontolearn/LPs.zip -O ./LPs.zip && unzip LPs.zip && python examples/dbpedia_concept_learning_with_drill_and_triplestore.py
git clone https://github.com/dice-group/Ontolearn.git && cd Ontolearn && git checkout large_scale_cel && conda create -n venv python=3.10.14 --no-default-packages --y && conda activate venv && pip install -e . && wget https://files.dice-research.org/projects/Ontolearn/LPs.zip -O ./LPs.zip && unzip LPs.zip && python examples/dbpedia_concept_learning_with_ontolearn.py drill
```
3. For DL-Learner
```bash
git clone https://github.com/dice-group/Ontolearn.git && cd Ontolearn && git checkout large_scale_cel && conda create -n venv python=3.10.14 --no-default-packages --y && conda activate venv && pip install -e . && https://github.com/SmartDataAnalytics/DL-Learner/releases/download/1.4.0/dllearner-1.4.0.zip -O ./dllearner-1.4.0.zip && unzip dllearner-1.4.0.zip && wget https://files.dice-research.org/projects/Ontolearn/LPs.zip -O ./LPs.zip && unzip LPs.zip && python examples/dbpedia_dl_learner_sparql.py
git clone https://github.com/dice-group/Ontolearn.git && cd Ontolearn && git checkout large_scale_cel && conda create -n venv python=3.10.14 --no-default-packages --y && conda activate venv && pip install -e . && wget https://github.com/SmartDataAnalytics/DL-Learner/releases/download/1.4.0/dllearner-1.4.0.zip -O ./dllearner-1.4.0.zip && unzip dllearner-1.4.0.zip && wget https://files.dice-research.org/projects/Ontolearn/LPs.zip -O ./LPs.zip && unzip LPs.zip && python examples/dbpedia_concept_learning_with_dllearner.py
```

Fore more please refer to the [examples](https://github.com/dice-group/Ontolearn/tree/develop/examples) folder.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import json, os
import json, os, sys
from owlapy.owl_individual import OWLNamedIndividual, IRI
from ontolearn.learners import Drill
from ontolearn.learners import Drill, TDL
from ontolearn.learning_problem import PosNegLPStandard
from ontolearn.triple_store import TripleStore
from ontolearn.utils.static_funcs import save_owl_class_expressions
from owlapy.render import DLSyntaxObjectRenderer
# (1) Initialize Triplestore

if len(sys.argv) < 2:
print("You need to provide the model name; either tdl or drill")
sys.exit(1)

model_name = sys.argv[1]
assert model_name.lower() in ["drill", "tdl"], "Currently, only Drill and TDL are supported"

# (1) Initialize knowledge source with TripleStore
kb = TripleStore(url="https://dbpedia.data.dice-research.org/sparql")
# (2) Initialize a DL renderer.
renderer = DLSyntaxObjectRenderer()
# (3) Initialize a learner.
model = Drill(knowledge_base=kb, max_runtime=240)
model = Drill(knowledge_base=kb, max_runtime=240) if model_name.lower() == "drill" else TDL(knowledge_base=kb)
# (4) Solve learning problems
with open("./LPs/DBpedia2022-12/lps.json") as f:
lps = json.load(f)
for i, item in enumerate(lps):
print("\nTarget expression: ", item["target expression"], "\n")
lp = PosNegLPStandard(pos=set(list(map(OWLNamedIndividual,map(IRI.create, item["examples"]["positive examples"])))),
neg=set(list(map(OWLNamedIndividual,map(IRI.create, item["examples"]["negative examples"])))))
# (5) Learn description logic concepts best fitting (4).
# (5) Learn description logic concepts best fitting
h = model.fit(learning_problem=lp).best_hypotheses()
str_concept = renderer.render(h)
print("Concept:", str_concept) # e.g. ∃ predecessor.WikicatPeopleFromBerlin
# (6) Save ∃ predecessor.WikicatPeopleFromBerlin into disk
if not os.path.exists("./learned_owl_expressions_drill"):
os.mkdir("./learned_owl_expressions_drill")
save_owl_class_expressions(expressions=h, path=f"./learned_owl_expressions_drill/owl_prediction_{i}")
# (6) Save e.g., ∃ predecessor.WikicatPeopleFromBerlin into disk
if not os.path.exists(f"./learned_owl_expressions_{model_name}"):
os.mkdir(f"./learned_owl_expressions_{model_name}")
save_owl_class_expressions(expressions=h, path=f"./learned_owl_expressions_{model_name}/owl_prediction_{i}")
28 changes: 0 additions & 28 deletions examples/dbpedia_concept_learning_with_tdl_and_triplestore.py

This file was deleted.

11 changes: 11 additions & 0 deletions examples/generate_lps_dbpedia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ontolearn.lp_generator import LPGen

PATH = 'https://dbpedia.data.dice-research.org/sparql'
STORAGE_DIR = 'DBpedia_LPs'

def generate_lps():
lp_gen = LPGen(kb_path=PATH, storage_dir=STORAGE_DIR, refinement_expressivity=1e-7, use_triple_store=True, sample_fillers_count=1, num_sub_roots=1)
lp_gen.generate()

if __name__ == '__main__':
generate_lps()

0 comments on commit 4ae9527

Please sign in to comment.