Return a list of mapping of {value:string, count:int} given a list of copyright strings or Text() objects.
(texts, _detector=CopyrightDetector())
| 188 | |
| 189 | |
| 190 | def tally_copyrights(texts, _detector=CopyrightDetector()): |
| 191 | """ |
| 192 | Return a list of mapping of {value:string, count:int} given a |
| 193 | list of copyright strings or Text() objects. |
| 194 | """ |
| 195 | texts_to_tally = [] |
| 196 | no_detection_counter = 0 |
| 197 | for text in texts: |
| 198 | if not text: |
| 199 | no_detection_counter += 1 |
| 200 | continue |
| 201 | # Keep Text objects as-is |
| 202 | if isinstance(text, Text): |
| 203 | texts_to_tally.append(text) |
| 204 | else: |
| 205 | # FIXME: redetect to strip year should not be needed!! |
| 206 | statements_without_years = _detector.detect( |
| 207 | [(1, text)], |
| 208 | include_copyrights=True, |
| 209 | include_holders=False, |
| 210 | include_authors=False, |
| 211 | include_copyright_years=False, |
| 212 | ) |
| 213 | |
| 214 | for detection in statements_without_years: |
| 215 | copyr = detection.copyright |
| 216 | texts_to_tally.append(Text(copyr, copyr)) |
| 217 | |
| 218 | counter = tally(texts_to_tally) |
| 219 | if no_detection_counter: |
| 220 | counter[None] = no_detection_counter |
| 221 | |
| 222 | return counter |
| 223 | |
| 224 | |
| 225 | def tally_persons(texts): |