| 155 | # keep track of an original text value and the corresponding clustering "key" |
| 156 | @attr.attributes(slots=True) |
| 157 | class Text(object): |
| 158 | # cleaned, normalized, clustering text for a copyright holder |
| 159 | key = attr.attrib() |
| 160 | # original text for a copyright holder |
| 161 | original = attr.attrib() |
| 162 | # count of occurences of a text |
| 163 | count = attr.attrib(default=1) |
| 164 | |
| 165 | def normalize(self): |
| 166 | if TRACE_TEXT: |
| 167 | logger_debug('Text.normalize:', self) |
| 168 | key = self.key.lower() |
| 169 | key = ' '.join(key.split()) |
| 170 | key = key.strip('.,').strip() |
| 171 | key = clean(key) |
| 172 | self.key = key.strip('.,').strip() |
| 173 | |
| 174 | def transliterate(self): |
| 175 | self.key = toascii(self.key, translit=True) |
| 176 | |
| 177 | def fingerprint(self): |
| 178 | key = self.key |
| 179 | if not isinstance(key, str): |
| 180 | key = unidecode(key) |
| 181 | fp = fingerprints.generate(key) |
| 182 | |
| 183 | if TRACE_TEXT or TRACE_FP: |
| 184 | logger_debug('Text.fingerprint:key: ', repr(self.key)) |
| 185 | logger_debug('Text.fingerprint:fp : ', fingerprints.generate(unidecode(self.key))) |
| 186 | |
| 187 | self.key = fp |
| 188 | |
| 189 | |
| 190 | def tally_copyrights(texts, _detector=CopyrightDetector()): |
no outgoing calls
no test coverage detected