Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/nameparser/config/prefixes.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

5 statements  

1from nameparser.config.bound_first_names import BOUND_FIRST_NAMES 

2 

3#: The sub-set of :py:data:`PREFIXES` that are *never* a standalone first name. 

4#: A name that *starts* with one of these has no first name -- the whole thing 

5#: is a surname (e.g. "de Mesnil" -> last name "de Mesnil"). Curated to exclude 

6#: anything that can be a given name in some culture (`al`, `van`, `von`, 

7#: `della`, `di`, `del`, `da`, `vander`, ...) and anything that is also a first 

8#: name prefix (`abu`). When unsure, leave a word out: a missing member just 

9#: means that name is not auto-fixed, whereas a wrong member misparses a real 

10#: person. Must stay a subset of :py:data:`PREFIXES` and disjoint from 

11#: :py:data:`~nameparser.config.bound_first_names.BOUND_FIRST_NAMES`. 

12NON_FIRST_NAME_PREFIXES = { 

13 "'t", 

14 'af', 

15 'auf', 

16 'av', 

17 'bint', 

18 'de', 

19 "de'", 

20 'degli', 

21 'dei', 

22 'delle', 

23 'delli', 

24 'dello', 

25 'dem', 

26 'der', 

27 'dos', 

28 'het', 

29 'ibn', 

30 'op', 

31 'ter', 

32 'vd', 

33 'vom', 

34 'zu', 

35} 

36 

37#: Name pieces that appear before a last name. Prefixes join to the piece 

38#: that follows them to make one new piece. They can be chained together, e.g 

39#: "von der" and "de la". Because they only appear in middle or last names, 

40#: they also signify that all following name pieces should be in the same name 

41#: part, for example, "von" will be joined to all following pieces that are not 

42#: prefixes or suffixes, allowing recognition of double last names when they 

43#: appear after a prefixes. So in "pennie von bergen wessels MD", "von" will 

44#: join with all following name pieces until the suffix "MD", resulting in the 

45#: correct parsing of the last name "von bergen wessels". 

46#: 

47#: Defined as a static union so every :py:data:`NON_FIRST_NAME_PREFIXES` member 

48#: is guaranteed to also be a prefix (and still join forward), with no drift -- 

49#: mirroring ``TITLES = FIRST_NAME_TITLES | {...}`` in 

50#: :py:mod:`nameparser.config.titles`. 

51PREFIXES = NON_FIRST_NAME_PREFIXES | { 

52 'aan', 

53 'aen', 

54 'abu', 

55 'al', 

56 'bar', 

57 'bat', 

58 'bin', 

59 'bon', 

60 'da', 

61 'dal', 

62 'del', 

63 'dela', 

64 'della', 

65 'den', 

66 'di', 

67 'dí', 

68 'do', 

69 'du', 

70 'freiherr', 

71 'freiherrin', 

72 'heer', 

73 'la', 

74 'le', 

75 'mac', 

76 'mc', 

77 'san', 

78 'santa', 

79 'st', 

80 'ste', 

81 'te', 

82 'tho', 

83 'thoe', 

84 'van', 

85 'vande', 

86 'vander', 

87 'vel', 

88 'von', 

89} 

90 

91# Guard the two invariants the docstring above promises, so a future edit that 

92# breaks them fails at import time instead of silently drifting until a test 

93# happens to catch it. 

94assert NON_FIRST_NAME_PREFIXES <= PREFIXES, \ 

95 "NON_FIRST_NAME_PREFIXES must stay a subset of PREFIXES" 

96assert not (NON_FIRST_NAME_PREFIXES & BOUND_FIRST_NAMES), \ 

97 "NON_FIRST_NAME_PREFIXES must stay disjoint from BOUND_FIRST_NAMES"