Skip to content

Commit 197b6b5

Browse files
committed
modify knowledge base path to instance
1 parent 09f59ca commit 197b6b5

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ontolearn/concept_abstract_syntax_tree.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ def to_dict(self):
120120
}
121121

122122
class ConceptAbstractSyntaxTreeBuilder:
123-
def __init__(self, knowledge_base_path: str, max_length: Optional[int] = None):
124-
assert isinstance(knowledge_base_path, str) and knowledge_base_path.strip(), "Knowledge base path is required"
123+
def __init__(self, knowledge_base:KnowledgeBase, max_length: Optional[int] = None):
124+
assert isinstance(knowledge_base, KnowledgeBase) and "A knowledge base instance is required"
125125

126-
self.knowledge_base = KnowledgeBase(path=knowledge_base_path)
126+
self.knowledge_base = knowledge_base
127127
self.max_length = max_length
128128

129129
ontology = self.knowledge_base.ontology
@@ -971,7 +971,7 @@ def _enforce(self, max_length:Optional[int]=None, replace_with_negation:bool=Fal
971971
indx +=1
972972
return corrected_tokens
973973

974-
def generate_class_expression(kb_path:str, leaners_prediction = None, save_as_json: bool=False, relax_parentheses=False):
974+
def generate_class_expression(kb:KnowledgeBase, leaners_prediction = None, save_as_json: bool=False, relax_parentheses=False):
975975
if not leaners_prediction:
976976
# token_sequence = ['¬', 'hasSibling', '.', '(', 'Thing', '⊓', '∃', 'hasChild', '.', 'Female', '⊓', 'Grandfather']
977977
# token_sequence =['¬', ' Brother ', ' ) ']
@@ -996,11 +996,11 @@ def generate_class_expression(kb_path:str, leaners_prediction = None, save_as_js
996996
# token_sequence = ['Person', '⊓', '(', 'Grandmother', '⊔', '(', '∃', 'married', '.', 'Grandfather', ')', ')', ')', ')', ')']
997997
# token_sequence = ['Grandparent', '⊔', '(', '∃', 'married', '.', '(', ')', ')']
998998
# token_sequence = ['(', '⊓', '(', '∀', 'married', '.', '(', '(', ')', ')', '(', '¬', ')', '(', ')', ')', ')']
999-
token_sequence = ['Person', '⊓', '(', '(', '⊔', '(', '∀', 'hasChild', '.', 'Grandfather', ')', ')', '⊓', '(', ')', ')', ')', ')']
1000-
#['∀', 'married', '.', '(', 'Brother', '⊔', 'Sister']
999+
# token_sequence = ['Person', '⊓', '(', '(', '⊔', '(', '∀', 'hasChild', '.', 'Grandfather', ')', ')', '⊓', '(', ')', ')', ')', ')']
1000+
token_sequence = ['∀', 'married', '.', '(', 'Brother', '⊔', 'Sister']
10011001

10021002
try:
1003-
builder = ConceptAbstractSyntaxTreeBuilder(knowledge_base_path=kb_path)
1003+
builder = ConceptAbstractSyntaxTreeBuilder(knowledge_base=kb)
10041004
concept, result = builder.parse(token_sequence=token_sequence, relax_parentheses=relax_parentheses, enforce_validity=True, replace_with_negation=False)
10051005

10061006
if concept is not None:
@@ -1019,7 +1019,8 @@ def generate_class_expression(kb_path:str, leaners_prediction = None, save_as_js
10191019

10201020
if __name__ == "__main__":
10211021
knowledge_base_path = pathlib.Path(__file__).parent.parent.parent.resolve()._str + "/data/KGs/Family/family-benchmark_rich_background.owl"
1022-
generate_class_expression(knowledge_base_path)
1022+
kb = KnowledgeBase(path=knowledge_base_path)
1023+
generate_class_expression(kb)
10231024

10241025

10251026
'''

0 commit comments

Comments
 (0)