Return a list of mapping of {value:string, count:int} given a list of holders strings or Text() objects.
(texts)
| 223 | |
| 224 | |
| 225 | def tally_persons(texts): |
| 226 | """ |
| 227 | Return a list of mapping of {value:string, count:int} given a |
| 228 | list of holders strings or Text() objects. |
| 229 | """ |
| 230 | texts_to_tally = [] |
| 231 | no_detection_counter = 0 |
| 232 | for text in texts: |
| 233 | if not text: |
| 234 | no_detection_counter += 1 |
| 235 | continue |
| 236 | # Keep Text objects as-is |
| 237 | if isinstance(text, Text): |
| 238 | texts_to_tally.append(text) |
| 239 | else: |
| 240 | cano = canonical_holder(text) |
| 241 | texts_to_tally.append(Text(cano, cano)) |
| 242 | |
| 243 | counter = tally(texts_to_tally) |
| 244 | |
| 245 | if no_detection_counter: |
| 246 | counter[None] = no_detection_counter |
| 247 | |
| 248 | return counter |
| 249 | |
| 250 | |
| 251 | def tally(summary_texts): |