Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _load_model(self, filename):
"""
Loads pre-trained truecasing file.
:returns: A dictionary of the best, known objects as values from `_casing_to_model()`
:rtype: {'best': dict, 'known': Counter}
"""
casing = defaultdict(Counter)
with open(filename, encoding=self.encoding) as fin:
for line in fin:
line = line.strip().split()
for token, count in grouper(line, 2):
count = count.split("/")[0].strip("()")
casing[token.lower()][token] = int(count)
# Returns the best and known object from `_casing_to_model()`
return self._casing_to_model(casing)