Example #1
0
 def dict_combine(self, dictionary: Union[DictInterface,
                                          Union[Dict[str, Any], Set[str]]]):
     if dictionary is not None and not isinstance(dictionary,
                                                  DictInterface):
         if all(isinstance(k, str) for k in dictionary):
             dictionary = TrieDict(dictionary)
         else:
             _d = set()
             for k in dictionary:
                 if isinstance(k, str):
                     _d.update(possible_tokenization(k))
                 else:
                     _d.add(k)
             dictionary = TupleTrieDict(_d)
     self.config.dict_combine = dictionary
Example #2
0
 def dict_tags(self, dictionary: Union[DictInterface,
                                       Union[Dict[Union[str, Sequence[str]],
                                                  Union[str,
                                                        Sequence[str]]]]]):
     if dictionary is not None and not isinstance(dictionary,
                                                  DictInterface):
         _d = dict()
         for k, v in dictionary.items():
             if isinstance(k, str):
                 k = (k, )
             if isinstance(v, str):
                 v = (v, ) * len(k)
             _d[k] = v
         dictionary = TupleTrieDict(_d)
     self.config.dict_tags = dictionary
Example #3
0
 def dict_tags(self, dictionary: Union[DictInterface,
                                       Union[Dict[Union[str, Sequence[str]],
                                                  Union[str,
                                                        Sequence[str]]]]]):
     if dictionary is not None and not isinstance(dictionary,
                                                  DictInterface):
         assert isinstance(
             dictionary, dict
         ), f'Expected dictionary to be `dict` but got {type(dictionary)}.'
         _d = dict()
         for k, v in dictionary.items():
             if isinstance(k, str):
                 k = (k, )
             if isinstance(v, str):
                 v = (v, ) * len(k)
             _d[k] = v
         dictionary = TupleTrieDict(_d)
     self.config.dict_tags = dictionary