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

DRILL cannot access class hierarchy if we use a TripleStoreKnowledgeBase #446

Open
MichaelRoeder opened this issue Oct 8, 2024 · 1 comment
Labels
wontfix This will not be worked on

Comments

@MichaelRoeder
Copy link
Member

Problem

DRILL crashes with the following stack trace:

Traceback (most recent call last):
  File "/local/upb/users/q/quannian/profiles/unix/cs/Pycharm_Project/Ontolearn-0.7.3/Ontolearn/examples/concept_learning_drill_[train.py](http://train.py/)", line 125, in <module>
    start(parser.parse_args())
  File "/local/upb/users/q/quannian/profiles/unix/cs/Pycharm_Project/Ontolearn-0.7.3/Ontolearn/examples/concept_learning_drill_[train.py](http://train.py/)", line 50, in start
    drill.train(num_of_target_concepts=args.num_of_target_concepts,
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/learners/[drill.py](http://drill.py/)", line 263, in train
    sum_of_rewards_per_actions = self.rl_learning_loop(pos_uri=frozenset(positives),   
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/learners/[drill.py](http://drill.py/)", line 224, in rl_learning_loop
    sequence_of_states, rewards = self.sequence_of_actions(root_rl_state)
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/learners/[drill.py](http://drill.py/)", line 464, in sequence_of_actions
    next_rl_states = list(self.apply_refinement(current_state))
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/learners/[drill.py](http://drill.py/)", line 444, in apply_refinement
    for i in self.operator.refine(rl_state.concept):  # O(N)
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/refinement_[operators.py](http://operators.py/)", line 249, in refine
    for i in self.refine_top():
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/refinement_[operators.py](http://operators.py/)", line 111, in refine_top
    most_general_concepts = [i for i in self.kb.get_most_general_classes()]
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/refinement_[operators.py](http://operators.py/)", line 111, in <listcomp>
    most_general_concepts = [i for i in self.kb.get_most_general_classes()]
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/knowledge_[base.py](http://base.py/)", line 795, in get_most_general_classes
    yield from self.class_hierarchy.roots()
AttributeError: 'TripleStoreKnowledgeBase' object has no attribute 'class_hierarchy'

Recreate problem

Adapt the example script of DRILL in the following way:

def start(args):
-    kb = KnowledgeBase(path=args.path_knowledge_base)
+    kb = TripleStoreKnowledgeBase('http://dice-quan.cs.uni-paderborn.de:9080/sparql')
     drill = Drill(knowledge_base=kb,
                   path_embeddings=args.path_embeddings,
                   refinement_operator=LengthBasedRefinement(knowledge_base=kb),
                   quality_func=F1(),
                   reward_func=CeloeBasedReward(),
                   epsilon_decay=args.epsilon_decay,
                   learning_rate=args.learning_rate,
                   num_of_sequential_actions=args.num_of_sequential_actions,
                   num_episode=args.num_episode,
                   iter_bound=args.iter_bound,
                   max_runtime=args.max_runtime)

Possible source

It seems like the class_hierarchy attribute is never created because the TripleStoreKnowledgeBase initializes its superclass KnowledgeBase with load_class_hierarchy=False (see here).

@Demirrr Demirrr added the bug Something isn't working label Oct 9, 2024
@Demirrr Demirrr added the wontfix This will not be worked on label Oct 18, 2024
@Demirrr
Copy link
Member

Demirrr commented Oct 18, 2024

Currently, we do not support TripleStoreKnowledgeBasefor the time being.
So, please use TripleStore()
DRILL is not designed to acces class hiearahrcy :)

@Demirrr Demirrr removed the bug Something isn't working label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants