Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

same_if_same_name_ends.py 1012 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  1. from typing import Optional, Tuple
  2. from bohrapi.artifacts.identity import Identity
  3. from bohrapi.core import Heuristic
  4. from bohrlabels.core import OneOrManyLabels
  5. from bohrlabels.labels import MatchLabel
  6. @Heuristic(Identity, Identity)
  7. def same_if_same_name_ends(
  8. identities: Tuple[Identity, Identity]
  9. ) -> Optional[OneOrManyLabels]:
  10. """
  11. >>> not_same_if_only_first_names_match((Identity({"names": ["Hlib Mr Babii"]}), Identity({"names": ["Hlib Babii"]})))
  12. MatchLabel.Match
  13. >>> not_same_if_only_first_names_match((Identity({"names": ["Hlib Babii Mr"]}), Identity({"names": ["Hlib Babii"]}))) is None
  14. True
  15. >>> not_same_if_only_first_names_match((Identity({}), Identity({}))) is None
  16. True
  17. """
  18. name1 = identities[0].name
  19. name2 = identities[1].name
  20. if name1 is not None and name2 is not None:
  21. if len(spl1 := name1.split(" ")) != len(spl2 := name2.split(" ")):
  22. if spl1[0] == spl2[0] and spl1[-1] == spl2[-1]:
  23. return MatchLabel.Match
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...