Exemple #1
0
    def _grab_junior(self, clusters: Clusters) -> Clusters:
        """
        Extract "junior" as suffix unless
        - there is already a generational suffix
        - junior is the first word of the only cluster (e.g. 'junior x. smith')
        - junior is the first word of a multi-token multi-cluster
            e.g. leave as first 'smith, junior x'
                 leave as first 'barnes-smith, junior james'
                 take as suffix 'jake smith, junior'
        """

        if self._has_generational:
            return clusters

        if "junior" not in flatten_once(clusters):
            return clusters

        first_word_only_cluster = len(
            clusters) == 1 and clusters[0][0] == "junior"
        if first_word_only_cluster:
            return clusters

        first_word_in_likely_first_name = (len(clusters) == 2
                                           and len(clusters[1]) > 1
                                           and clusters[1][0] == "junior")
        if first_word_in_likely_first_name:
            return clusters

        self.detail["suffix"].append("jr")
        return self._remove_from_clusters(clusters, "junior")
Exemple #2
0
 def wrapper_bouncer(obj: T.Any,
                     countable: WordContainer) -> WordContainer:
     checklist: T.List[T.Any]
     if not countable:
         return countable
     if isinstance(countable, str):
         checklist = countable.split()
     elif isinstance(countable[0], str):
         checklist = countable
     else:
         checklist = flatten_once(countable)
     wordlist = [s for s in checklist if re.search("[a-z]", s)]
     if len(wordlist) < minimum:
         return countable
     return func(obj, countable)
Exemple #3
0
 def t_only_flatten_onces_one_level(self):
     assert flatten_once([["too", ["many"]], "nests"
                          ]) != ["too", "many", "nests"]
Exemple #4
0
 def t_flatten_onces(self, example):
     assert flatten_once(example["in"]) == example["out"]
Exemple #5
0
 def t_nothing_from_nothing_leaves_nothing(self, incoming):
     assert flatten_once(incoming) == []
Exemple #6
0
 def _extract_last_first_middle(self, clusters: Clusters) -> None:
     """Sequentially remove last name, first name, and collapse to middles"""
     clusters = self._extract_last(remove_falsy(clusters))
     clusters = self._extract_first(remove_falsy(clusters))
     self.detail["middle"] = flatten_once(clusters)