|
18 | 18 | get_index, |
19 | 19 | get_many_to_many, |
20 | 20 | keep_prefixes, |
| 21 | + prioritize, |
21 | 22 | prioritize_df, |
22 | 23 | project, |
23 | 24 | ) |
@@ -485,6 +486,69 @@ def test_prioritize_df(self) -> None: |
485 | 486 | list(df["curie_prioritized"]), |
486 | 487 | ) |
487 | 488 |
|
| 489 | + def test_prioritize(self) -> None: |
| 490 | + """Test prioritize.""" |
| 491 | + a1 = Reference(prefix=PREFIX_A, identifier="0000001") |
| 492 | + b1 = Reference(prefix=PREFIX_B, identifier="0000002") |
| 493 | + c1 = Reference(prefix=PREFIX_C, identifier="0000003") |
| 494 | + ev = SimpleEvidence(confidence=0.95, mapping_set=MS) |
| 495 | + m1 = Mapping(subject=a1, predicate=EXACT_MATCH, object=b1, evidence=[ev]) |
| 496 | + m1_rev = Mapping(subject=b1, predicate=EXACT_MATCH, object=a1, evidence=[ev]) |
| 497 | + m2 = Mapping(subject=b1, predicate=EXACT_MATCH, object=c1, evidence=[ev]) |
| 498 | + m2_rev = Mapping(subject=c1, predicate=EXACT_MATCH, object=b1, evidence=[ev]) |
| 499 | + m3 = Mapping(subject=a1, predicate=EXACT_MATCH, object=c1, evidence=[ev]) |
| 500 | + m3_rev = Mapping(subject=c1, predicate=EXACT_MATCH, object=a1, evidence=[ev]) |
| 501 | + |
| 502 | + # can't address priority |
| 503 | + self.assert_same_triples( |
| 504 | + [], |
| 505 | + prioritize([m1, m1_rev, m2, m2_rev, m3, m3_rev], [PREFIX_D], progress=False), |
| 506 | + ) |
| 507 | + |
| 508 | + # has unusable priority first, but then defaults |
| 509 | + self.assert_same_triples( |
| 510 | + [m1_rev, m3_rev], |
| 511 | + prioritize([m1, m1_rev, m2, m2_rev, m3, m3_rev], [PREFIX_D, PREFIX_A], progress=False), |
| 512 | + ) |
| 513 | + |
| 514 | + self.assert_same_triples( |
| 515 | + [m1_rev, m3_rev], |
| 516 | + prioritize([m1, m1_rev, m2, m2_rev, m3, m3_rev], [PREFIX_A], progress=False), |
| 517 | + ) |
| 518 | + self.assert_same_triples( |
| 519 | + [m1, m2_rev], |
| 520 | + prioritize([m1, m1_rev, m2, m2_rev, m3, m3_rev], [PREFIX_B], progress=False), |
| 521 | + ) |
| 522 | + self.assert_same_triples( |
| 523 | + [m2, m3], |
| 524 | + prioritize([m1, m1_rev, m2, m2_rev, m3, m3_rev], [PREFIX_C], progress=False), |
| 525 | + ) |
| 526 | + |
| 527 | + # test on component with only 1 |
| 528 | + self.assert_same_triples( |
| 529 | + [m1_rev], |
| 530 | + prioritize([m1, m1_rev], [PREFIX_A], progress=False), |
| 531 | + ) |
| 532 | + self.assert_same_triples( |
| 533 | + [m1], |
| 534 | + prioritize([m1, m1_rev], [PREFIX_B], progress=False), |
| 535 | + ) |
| 536 | + self.assert_same_triples( |
| 537 | + [], |
| 538 | + prioritize([m1, m1_rev], [PREFIX_C], progress=False), |
| 539 | + ) |
| 540 | + |
| 541 | + # the following three tests reflect that the prioritize() function |
| 542 | + # is not implemented in cases when inference hasn't been fully done |
| 543 | + with self.assertRaises(NotImplementedError): |
| 544 | + prioritize([m1, m2], [PREFIX_A], progress=False) |
| 545 | + with self.assertRaises(NotImplementedError): |
| 546 | + prioritize([m1, m2], [PREFIX_C], progress=False) |
| 547 | + |
| 548 | + # this one is able to complete, by chance, but it's not part of |
| 549 | + # the contract, so just left here for later |
| 550 | + # self.assertEqual([m1, m2_rev], prioritize([m1, m2], [PREFIX_B], progress=False)) |
| 551 | + |
488 | 552 |
|
489 | 553 | class TestUpgrades(unittest.TestCase): |
490 | 554 | """Test inferring mutations.""" |
|
0 commit comments