Skip to content

Commit

Permalink
fixed contextual predicate .test
Browse files Browse the repository at this point in the history
  • Loading branch information
ngupta10 committed Jan 7, 2024
1 parent fc5b99e commit 1238e25
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions tests/kg_tests/contextual_predicate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@
"""

def test_contextual_predicate():
sample_data = [[('eocene', 'In this study, we present evidence of a PaleoceneEocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints.', 'ft', {'entity1_score': 1.0, 'entity2_score': 0.69, 'entity1_label': 'B-GeoMeth, B-GeoTime', 'entity2_label': 'B-GeoMeth', 'entity1_nn_chunk': 'a PaleoceneEocene Thermal Maximum (PETM) record', 'entity2_nn_chunk': 'a 543-m-thick (1780 ft) deep-marine section', 'entity1_attnscore': 0.46, 'entity2_attnscore': 0.21, 'pair_attnscore': 0.13,'entity1_embedding': np.array([ 5.513507 , 6.14687 , 0.56821245, 3.7250893 , 8.519092 ,2.1298776 , 6.7030797 , 8.760443 , -2.4095411 , 14.959248 ],dtype=np.float32), 'entity2_embedding': np.array([ 4.3211513, 5.3283153, 1.2105073, 5.3618913, 8.23375 ,2.951651 , 7.3403625, 10.785665 , -2.5593305, 14.518231 ],
dtype=np.float32), 'sentence_embedding': np.array([ 8.136787 , 12.801951 , 3.1658218 , 7.360018 , 9.823584 ,
0.28562617, 12.840015 , 0.40643066, 9.059556 , 12.759513 ],
dtype=np.float32)}),
('eocene', 'In this study, we present evidence of a PaleoceneEocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints.', 'mexico', {'entity1_score': 1.0, 'entity2_score': 0.92, 'entity1_label': 'B-GeoMeth, B-GeoTime', 'entity2_label': 'B-GeoLoc', 'entity1_nn_chunk': 'a PaleoceneEocene Thermal Maximum (PETM) record', 'entity2_nn_chunk': 'Mexico', 'entity1_attnscore': 0.46, 'entity2_attnscore': 0.17, 'pair_attnscore': 0.13,'entity1_embedding': np.array([ 5.355203 , 6.1266084 , 0.60222036, 3.7390788 , 8.5242195 ,
2.1033056 , 6.6313214 , 8.70998 , -2.432465 , 15.200483 ],
dtype=np.float32), 'entity2_embedding': np.array([ 5.601423 , 6.058842 , 0.33065754, 6.1470265 , 8.568694 ,
3.922125 , 7.0688643 , 11.551212 , -2.5106885 , 14.04761 ],
dtype=np.float32),'sentence_embedding': np.array([ 8.136787 , 12.801951 , 3.1658218 , 7.360018 , 9.823584 ,
0.28562617, 12.840015 , 0.40643066, 9.059556 , 12.759513 ],
dtype=np.float32)})]]
sample_data = [[('temperatures', 'The Paleocene–Eocene Thermal Maximum (PETM) (ca. 56 Ma) was a rapid global warming event characterized by the rise of temperatures to5–9 °C (Kennett and Stott, 1991), which caused substantial environmental changes around the globe.', 'kenn', {'entity1_score': 0.91, 'entity2_score': 0.97, 'entity1_label': 'B-GeoMeth', 'entity2_label': 'B-GeoPetro', 'entity1_nn_chunk': 'temperatures', 'entity2_nn_chunk': 'Kennett', 'entity1_attnscore': 0.86, 'entity2_attnscore': 0.09, 'pair_attnscore': 0.16, 'entity1_embedding': [0.0975915715098381], 'entity2_embedding': [-1.2051959037780762]})]]

result_list = process_data(sample_data, "dummy1.pdf")
result_string = result_list[0][1] if result_list else ""
print(result_string)
expected_string = '{"context": "In this study, we present evidence of a PaleoceneEocene Thermal Maximum (PETM) record within a 543-m-thick (1780 ft) deep-marine section in the Gulf of Mexico (GoM) using organic carbon stable isotopes and biostratigraphic constraints.", "entity1_score": 1.0, "entity2_score": 0.69, "entity1_label": "B-GeoMeth, B-GeoTime", "entity2_label": "B-GeoMeth", "entity1_nn_chunk": "a PaleoceneEocene Thermal Maximum (PETM) record", "entity2_nn_chunk": "a 543-m-thick (1780 ft) deep-marine section", "file_path": "dummy1.pdf", "entity1_attnscore": 0.46, "entity2_attnscore": 0.21, "pair_attnscore": 0.13, "entity1_embedding": [5.513506889343262, 6.146870136260986, 0.5682124495506287, 3.7250893115997314, 8.519091606140137, 2.1298775672912598, 6.703079700469971, 8.760442733764648, -2.409541130065918, 14.959247589111328], "entity2_embedding": [4.321151256561279, 5.328315258026123, 1.2105072736740112, 5.361891269683838, 8.233750343322754, 2.951651096343994, 7.340362548828125, 10.785664558410645, -2.559330463409424, 14.518231391906738]}'
assert result_string == expected_string, f"Expected {expected_string}, but got {result_string}"

# Check if result_list is a list of tuples with three strings each
if result_list and all(isinstance(item, tuple) and len(item) == 3 and all(isinstance(element, str) for element in item) for item in result_list):
# If the condition is True, the assertion passes
assert True
else:
# If the condition is False, the assertion fails
assert False, "result_list is not a list of tuples like List[Tuple[str, str, str]]"

0 comments on commit 1238e25

Please sign in to comment.