-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extended lc path parsing and error reporting, fix graph test and adde…
…d new
- Loading branch information
Andrzej Uszok
committed
Oct 1, 2023
1 parent
df8e6eb
commit 3959954
Showing
10 changed files
with
225 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from domiknows.graph import Graph, Concept, Relation | ||
from domiknows.graph.logicalConstrain import ifL, andL, nandL, atMostL, existsL | ||
|
||
def setup_graph(fix_constraint=False): | ||
Graph.clear() | ||
Concept.clear() | ||
Relation.clear() | ||
|
||
with Graph('global') as graph: | ||
with Graph('linguistic') as ling_graph: | ||
text_document = Concept(name='text_document') | ||
|
||
with Graph('application', auto_constraint=False) as app_graph: | ||
entity = Concept(name='entity') | ||
person = entity(name='person', auto_constraint=False) | ||
organization = entity(name='organization', auto_constraint=False) | ||
location = entity(name='location', auto_constraint=False) | ||
date = entity(name='date') | ||
other_entity_types = entity(name='other_entity_types') | ||
|
||
relation = Concept(name='relation') | ||
employment = relation(name='employment') | ||
located = relation(name='located') | ||
part_whole = relation(name='part-whole') | ||
personal_social = relation(name='personal-social') | ||
other_relation = relation(name='other') | ||
|
||
pair = Concept(name='pair') | ||
(rel_pair_entity1, rel_pair_entity2) = pair.has_a(arg1=entity, arg2=entity) | ||
|
||
if fix_constraint: | ||
ifL( | ||
entity('x'), | ||
atMostL( | ||
person(path=('x')), | ||
organization(path=('x')), | ||
location(path=('x')), | ||
date(path=('x')), | ||
other_entity_types(path=('x')), | ||
1 | ||
), | ||
name="constraint_only_one_entity_fixed" | ||
) | ||
else: | ||
ifL( | ||
entity('x'), | ||
atMostL( | ||
person(path=('x', entity)), | ||
organization(path=('x', entity)), | ||
location(path=('x', entity)), | ||
date(path=('x', entity)), | ||
other_entity_types(path=('x', entity)), | ||
1 | ||
), | ||
name="constraint_only_one_entity" | ||
) | ||
|
||
return graph |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from graph_concept_in_path import setup_graph | ||
import re | ||
|
||
def test_setup_graph_exception(): | ||
try: | ||
setup_graph() | ||
except Exception as e: | ||
sanitized_error_message = re.sub(r'[^\x20-\x7E]', '', str(e)).replace(" ", "") | ||
sanitized_pattern = re.sub(r'[^\x20-\x7E]', '', | ||
"The Path 'entity' from the variable x, defined in constraint_only_one_entity is not valid." | ||
"The used variable entity is a concept, path element can be only relation or eqL logical constraint used to filter candidates in the path.").replace(" ", "") | ||
|
||
print(repr(sanitized_error_message)) | ||
print(repr(sanitized_pattern)) | ||
|
||
assert sanitized_error_message == sanitized_pattern, f"Exception message did not match: got {sanitized_error_message}" | ||
else: | ||
pytest.fail("Expected an exception but none was raised.") | ||
|
||
def test_setup_graph_no_exception(): | ||
try: | ||
setup_graph(fix_constraint=True) | ||
except Exception as e: | ||
pytest.fail(f"Unexpected Exception raised: {e}") |
Oops, something went wrong.