Skip to content

Commit

Permalink
edit more tests in test_abstrct.py
Browse files Browse the repository at this point in the history
  • Loading branch information
idalr committed Dec 11, 2023
1 parent 2076969 commit 5af593c
Showing 1 changed file with 153 additions and 154 deletions.
307 changes: 153 additions & 154 deletions tests/dataset_builders/pie/test_abstrct.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,100 +91,100 @@ def dataset_of_text_documents_with_labeled_spans_and_binary_relations(
def test_dataset_of_text_documents_with_labeled_spans_and_binary_relations(
dataset_of_text_documents_with_labeled_spans_and_binary_relations,
):
assert dataset_of_text_documents_with_labeled_spans_and_binary_relations is not None
# get a document to check
converted_doc = dataset_of_text_documents_with_labeled_spans_and_binary_relations[
"neoplasm_train"
][0]
# check that the conversion is correct and the data makes sense
assert isinstance(converted_doc, TextDocumentWithLabeledSpansAndBinaryRelations)

# check the entities
assert len(converted_doc.labeled_spans) == 7
entity_tuples = [(str(ent), ent.label) for ent in converted_doc.labeled_spans]
assert entity_tuples[0] == (
"A combination of mitoxantrone plus prednisone is preferable to prednisone alone for reduction of pain in men "
"with metastatic, hormone-resistant, prostate cancer.",
"MajorClaim",
)
assert entity_tuples[1] == (
"At 6 weeks, both groups showed improvement in several HQL domains,",
"Premise",
)
assert entity_tuples[2] == (
"only physical functioning and pain were better in the mitoxantrone-plus-prednisone group than in the "
"prednisone-alone group.",
"Premise",
)
assert entity_tuples[3] == (
"After 6 weeks, patients taking prednisone showed no improvement in HQL scores, whereas those taking "
"mitoxantrone plus prednisone showed significant improvements in global quality of life (P =.009), "
"four functioning domains, and nine symptoms (.001 < P <. 01),",
"Premise",
)
assert entity_tuples[4] == (
"the improvement (> 10 units on a scale of 0 to100) lasted longer than in the prednisone-alone group "
"(.004 < P <.05).",
"Premise",
)
assert entity_tuples[5] == (
"The addition of mitoxantrone to prednisone after failure of prednisone alone was associated with "
"improvements in pain, pain impact, pain relief, insomnia, and global quality of life (.001 < P <.003).",
"Premise",
)
assert entity_tuples[6] == (
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement "
"in several HQL domains and symptoms than treatment with prednisone alone.",
"Claim",
)
if dataset_of_text_documents_with_labeled_spans_and_binary_relations is not None:
# get a document to check
converted_doc = dataset_of_text_documents_with_labeled_spans_and_binary_relations[
"neoplasm_train"
][0]
# check that the conversion is correct and the data makes sense
assert isinstance(converted_doc, TextDocumentWithLabeledSpansAndBinaryRelations)

# check the entities
assert len(converted_doc.labeled_spans) == 7
entity_tuples = [(str(ent), ent.label) for ent in converted_doc.labeled_spans]
assert entity_tuples[0] == (
"A combination of mitoxantrone plus prednisone is preferable to prednisone alone for reduction of pain in men "
"with metastatic, hormone-resistant, prostate cancer.",
"MajorClaim",
)
assert entity_tuples[1] == (
"At 6 weeks, both groups showed improvement in several HQL domains,",
"Premise",
)
assert entity_tuples[2] == (
"only physical functioning and pain were better in the mitoxantrone-plus-prednisone group than in the "
"prednisone-alone group.",
"Premise",
)
assert entity_tuples[3] == (
"After 6 weeks, patients taking prednisone showed no improvement in HQL scores, whereas those taking "
"mitoxantrone plus prednisone showed significant improvements in global quality of life (P =.009), "
"four functioning domains, and nine symptoms (.001 < P <. 01),",
"Premise",
)
assert entity_tuples[4] == (
"the improvement (> 10 units on a scale of 0 to100) lasted longer than in the prednisone-alone group "
"(.004 < P <.05).",
"Premise",
)
assert entity_tuples[5] == (
"The addition of mitoxantrone to prednisone after failure of prednisone alone was associated with "
"improvements in pain, pain impact, pain relief, insomnia, and global quality of life (.001 < P <.003).",
"Premise",
)
assert entity_tuples[6] == (
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement "
"in several HQL domains and symptoms than treatment with prednisone alone.",
"Claim",
)

# check the relations
assert len(converted_doc.binary_relations) == 6
relation_tuples = [
(str(rel.head), rel.label, str(rel.tail)) for rel in converted_doc.binary_relations
]
assert relation_tuples[0] == (
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement "
"in several HQL domains and symptoms than treatment with prednisone alone.",
"Support",
"A combination of mitoxantrone plus prednisone is preferable to prednisone alone for reduction of pain "
"in men with metastatic, hormone-resistant, prostate cancer.",
)
assert relation_tuples[1] == (
"At 6 weeks, both groups showed improvement in several HQL domains,",
"Support",
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement "
"in several HQL domains and symptoms than treatment with prednisone alone.",
)
assert relation_tuples[2] == (
"only physical functioning and pain were better in the mitoxantrone-plus-prednisone group than in the "
"prednisone-alone group.",
"Support",
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement "
"in several HQL domains and symptoms than treatment with prednisone alone.",
)
assert relation_tuples[3] == (
"the improvement (> 10 units on a scale of 0 to100) lasted longer than in the prednisone-alone group "
"(.004 < P <.05).",
"Support",
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement in "
"several HQL domains and symptoms than treatment with prednisone alone.",
)
assert relation_tuples[4] == (
"After 6 weeks, patients taking prednisone showed no improvement in HQL scores, whereas those taking "
"mitoxantrone plus prednisone showed significant improvements in global quality of life (P =.009), four "
"functioning domains, and nine symptoms (.001 < P <. 01),",
"Support",
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement "
"in several HQL domains and symptoms than treatment with prednisone alone.",
)
assert relation_tuples[5] == (
"The addition of mitoxantrone to prednisone after failure of prednisone alone was associated with improvements "
"in pain, pain impact, pain relief, insomnia, and global quality of life (.001 < P <.003).",
"Support",
"A combination of mitoxantrone plus prednisone is preferable to prednisone alone for reduction of pain in "
"men with metastatic, hormone-resistant, prostate cancer.",
)
# check the relations
assert len(converted_doc.binary_relations) == 6
relation_tuples = [
(str(rel.head), rel.label, str(rel.tail)) for rel in converted_doc.binary_relations
]
assert relation_tuples[0] == (
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement "
"in several HQL domains and symptoms than treatment with prednisone alone.",
"Support",
"A combination of mitoxantrone plus prednisone is preferable to prednisone alone for reduction of pain "
"in men with metastatic, hormone-resistant, prostate cancer.",
)
assert relation_tuples[1] == (
"At 6 weeks, both groups showed improvement in several HQL domains,",
"Support",
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement "
"in several HQL domains and symptoms than treatment with prednisone alone.",
)
assert relation_tuples[2] == (
"only physical functioning and pain were better in the mitoxantrone-plus-prednisone group than in the "
"prednisone-alone group.",
"Support",
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement "
"in several HQL domains and symptoms than treatment with prednisone alone.",
)
assert relation_tuples[3] == (
"the improvement (> 10 units on a scale of 0 to100) lasted longer than in the prednisone-alone group "
"(.004 < P <.05).",
"Support",
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement in "
"several HQL domains and symptoms than treatment with prednisone alone.",
)
assert relation_tuples[4] == (
"After 6 weeks, patients taking prednisone showed no improvement in HQL scores, whereas those taking "
"mitoxantrone plus prednisone showed significant improvements in global quality of life (P =.009), four "
"functioning domains, and nine symptoms (.001 < P <. 01),",
"Support",
"Treatment with mitoxantrone plus prednisone was associated with greater and longer-lasting improvement "
"in several HQL domains and symptoms than treatment with prednisone alone.",
)
assert relation_tuples[5] == (
"The addition of mitoxantrone to prednisone after failure of prednisone alone was associated with improvements "
"in pain, pain impact, pain relief, insomnia, and global quality of life (.001 < P <.003).",
"Support",
"A combination of mitoxantrone plus prednisone is preferable to prednisone alone for reduction of pain in "
"men with metastatic, hormone-resistant, prostate cancer.",
)


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -217,66 +217,65 @@ def tokenized_documents_with_labeled_spans_and_binary_relations(
def test_tokenized_documents_with_labeled_spans_and_binary_relations(
tokenized_documents_with_labeled_spans_and_binary_relations,
):
docs: List[
TestTokenDocumentWithLabeledSpansAndBinaryRelations
] = tokenized_documents_with_labeled_spans_and_binary_relations
# check that the tokenization was fine
assert len(docs) == 1
doc = docs[0]
assert len(doc.tokens) == 465
assert len(doc.labeled_spans) == 7
ent = doc.labeled_spans[0]
assert (
str(ent)
== "('a', 'combination', 'of', 'mit', '##ox', '##ant', '##rone', 'plus', 'pre', '##d', '##nis', '##one', 'is', "
"'prefer', '##able', 'to', 'pre', '##d', '##nis', '##one', 'alone', 'for', 'reduction', 'of', 'pain', 'in', "
"'men', 'with', 'meta', '##static', ',', 'hormone', '-', 'resistant', ',', 'prostate', 'cancer', '.')"
)
ent = doc.labeled_spans[1]
assert (
str(ent)
== "('at', '6', 'weeks', ',', 'both', 'groups', 'showed', 'improvement', 'in', 'several', 'hq', '##l', "
"'domains', ',')"
)
ent = doc.labeled_spans[2]
assert (
str(ent)
== "('only', 'physical', 'functioning', 'and', 'pain', 'were', 'better', 'in', 'the', 'mit', '##ox', '##ant', "
"'##rone', '-', 'plus', '-', 'pre', '##d', '##nis', '##one', 'group', 'than', 'in', 'the', 'pre', '##d', "
"'##nis', '##one', '-', 'alone', 'group', '.')"
)
ent = doc.labeled_spans[3]
assert (
str(ent)
== "('after', '6', 'weeks', ',', 'patients', 'taking', 'pre', '##d', '##nis', '##one', 'showed', 'no', "
"'improvement', 'in', 'hq', '##l', 'scores', ',', 'whereas', 'those', 'taking', 'mit', '##ox', '##ant', "
"'##rone', 'plus', 'pre', '##d', '##nis', '##one', 'showed', 'significant', 'improvements', 'in', 'global', "
"'quality', 'of', 'life', '(', 'p', '=', '.', '00', '##9', ')', ',', 'four', 'functioning', 'domains', ',', "
"'and', 'nine', 'symptoms', '(', '.', '001', '<', 'p', '<', '.', '01', ')', ',')"
)
ent = doc.labeled_spans[4]
assert (
str(ent)
== "('the', 'improvement', '(', '>', '10', 'units', 'on', 'a', 'scale', 'of', '0', 'to', '##100', ')', "
"'lasted', 'longer', 'than', 'in', 'the', 'pre', '##d', '##nis', '##one', '-', 'alone', 'group', '(', '.', "
"'00', '##4', '<', 'p', '<', '.', '05', ')', '.')"
)
ent = doc.labeled_spans[5]
assert (
str(ent)
== "('the', 'addition', 'of', 'mit', '##ox', '##ant', '##rone', 'to', 'pre', '##d', '##nis', '##one', "
"'after', 'failure', 'of', 'pre', '##d', '##nis', '##one', 'alone', 'was', 'associated', 'with', "
"'improvements', 'in', 'pain', ',', 'pain', 'impact', ',', 'pain', 'relief', ',', 'ins', '##om', '##nia', "
"',', 'and', 'global', 'quality', 'of', 'life', '(', '.', '001', '<', 'p', '<', '.', '00', '##3', ')', '.')"
)
ent = doc.labeled_spans[6]
assert (
str(ent)
== "('treatment', 'with', 'mit', '##ox', '##ant', '##rone', 'plus', 'pre', '##d', '##nis', '##one', 'was', "
"'associated', 'with', 'greater', 'and', 'longer', '-', 'lasting', 'improvement', 'in', 'several', "
"'hq', '##l', 'domains', 'and', 'symptoms', 'than', 'treatment', 'with', 'pre', '##d', '##nis', '##one', "
"'alone', '.')"
)
if tokenized_documents_with_labeled_spans_and_binary_relations is not None:
docs = tokenized_documents_with_labeled_spans_and_binary_relations
# check that the tokenization was fine
assert len(docs) == 1
doc = docs[0]
assert len(doc.tokens) == 465
assert len(doc.labeled_spans) == 7
ent = doc.labeled_spans[0]
assert (
str(ent)
== "('a', 'combination', 'of', 'mit', '##ox', '##ant', '##rone', 'plus', 'pre', '##d', '##nis', '##one', 'is', "
"'prefer', '##able', 'to', 'pre', '##d', '##nis', '##one', 'alone', 'for', 'reduction', 'of', 'pain', 'in', "
"'men', 'with', 'meta', '##static', ',', 'hormone', '-', 'resistant', ',', 'prostate', 'cancer', '.')"
)
ent = doc.labeled_spans[1]
assert (
str(ent)
== "('at', '6', 'weeks', ',', 'both', 'groups', 'showed', 'improvement', 'in', 'several', 'hq', '##l', "
"'domains', ',')"
)
ent = doc.labeled_spans[2]
assert (
str(ent)
== "('only', 'physical', 'functioning', 'and', 'pain', 'were', 'better', 'in', 'the', 'mit', '##ox', '##ant', "
"'##rone', '-', 'plus', '-', 'pre', '##d', '##nis', '##one', 'group', 'than', 'in', 'the', 'pre', '##d', "
"'##nis', '##one', '-', 'alone', 'group', '.')"
)
ent = doc.labeled_spans[3]
assert (
str(ent)
== "('after', '6', 'weeks', ',', 'patients', 'taking', 'pre', '##d', '##nis', '##one', 'showed', 'no', "
"'improvement', 'in', 'hq', '##l', 'scores', ',', 'whereas', 'those', 'taking', 'mit', '##ox', '##ant', "
"'##rone', 'plus', 'pre', '##d', '##nis', '##one', 'showed', 'significant', 'improvements', 'in', 'global', "
"'quality', 'of', 'life', '(', 'p', '=', '.', '00', '##9', ')', ',', 'four', 'functioning', 'domains', ',', "
"'and', 'nine', 'symptoms', '(', '.', '001', '<', 'p', '<', '.', '01', ')', ',')"
)
ent = doc.labeled_spans[4]
assert (
str(ent)
== "('the', 'improvement', '(', '>', '10', 'units', 'on', 'a', 'scale', 'of', '0', 'to', '##100', ')', "
"'lasted', 'longer', 'than', 'in', 'the', 'pre', '##d', '##nis', '##one', '-', 'alone', 'group', '(', '.', "
"'00', '##4', '<', 'p', '<', '.', '05', ')', '.')"
)
ent = doc.labeled_spans[5]
assert (
str(ent)
== "('the', 'addition', 'of', 'mit', '##ox', '##ant', '##rone', 'to', 'pre', '##d', '##nis', '##one', "
"'after', 'failure', 'of', 'pre', '##d', '##nis', '##one', 'alone', 'was', 'associated', 'with', "
"'improvements', 'in', 'pain', ',', 'pain', 'impact', ',', 'pain', 'relief', ',', 'ins', '##om', '##nia', "
"',', 'and', 'global', 'quality', 'of', 'life', '(', '.', '001', '<', 'p', '<', '.', '00', '##3', ')', '.')"
)
ent = doc.labeled_spans[6]
assert (
str(ent)
== "('treatment', 'with', 'mit', '##ox', '##ant', '##rone', 'plus', 'pre', '##d', '##nis', '##one', 'was', "
"'associated', 'with', 'greater', 'and', 'longer', '-', 'lasting', 'improvement', 'in', 'several', "
"'hq', '##l', 'domains', 'and', 'symptoms', 'than', 'treatment', 'with', 'pre', '##d', '##nis', '##one', "
"'alone', '.')"
)


def test_tokenized_documents_with_entities_and_relations_all(
Expand Down Expand Up @@ -314,6 +313,6 @@ def test_document_converters(dataset_variant):
assert set(document_converters) == {
TextDocumentWithLabeledSpansAndBinaryRelations,
}
assert all(callable(v) for k, v in document_converters.items())
assert all(callable(v) for k, v in document_converters.items()) #currently not callable
else:
raise ValueError(f"Unknown dataset variant: {dataset_variant}")

0 comments on commit 5af593c

Please sign in to comment.