Skip to content

Commit

Permalink
Add test files and testing code for Matcher class
Browse files Browse the repository at this point in the history
  • Loading branch information
lairgiyassir committed Jul 9, 2024
1 parent 684b4ad commit 5ef0bbd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from itext2kg.utils import Matcher
Binary file added tests/current_entities.pkl
Binary file not shown.
Binary file added tests/global_entities.pkl
Binary file not shown.
48 changes: 48 additions & 0 deletions tests/testing_matcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest
import pickle
from itext2kg.utils import Matcher
import os

# Import current_entities.pkl
current_dir = os.path.dirname(os.path.abspath(__file__))
current_ent_path = os.path.join(current_dir, 'current_entities.pkl')
global_ent_path = os.path.join(current_dir, 'global_entities.pkl')

with open(current_ent_path, 'rb') as file:
CURRENT_ENTITIES = pickle.load(file)

# Import global_entities.pkl
with open(global_ent_path, 'rb') as file:
GLOBAL_ENTITIES = pickle.load(file)


GLOBAL_ENTITIES_FINAL_NAMES = ['John Doe',
'Software Engineer',
'XYZ Technologies',
'San Francisco, CA',
'Python',
'Java',
'B.Sc. in Computer Science',
'Stanford University',
'AWS',
'Docker',
'Kubernetes',
'Problem Solving',
'Team Collaboration',
'Agile Practices',
'Machine Learning',
'Google Professional Data Engineer']

matcher = Matcher()

class Testor:
@pytest.mark.parametrize(
"current_entities, global_entities",
[(CURRENT_ENTITIES, GLOBAL_ENTITIES)],
ids=["testing merging concepts"],
)
def test_merging_concepts(self, current_entities, global_entities):
matched_entities, global_entities_final = matcher.process_lists(current_entities, global_entities, for_entity_or_relation='entity', threshold=0.5)
assert(len(matched_entities) == len(current_entities))
assert(len(global_entities_final) == len(GLOBAL_ENTITIES_FINAL_NAMES))
assert([entity['name'] for entity in global_entities_final] == GLOBAL_ENTITIES_FINAL_NAMES)

0 comments on commit 5ef0bbd

Please sign in to comment.