MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / tally_copyrights

Function tally_copyrights

src/summarycode/copyright_tallies.py:190–222  ·  view source on GitHub ↗

Return a list of mapping of {value:string, count:int} given a list of copyright strings or Text() objects.

(texts, _detector=CopyrightDetector())

Source from the content-addressed store, hash-verified

188
189
190def 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
225def tally_persons(texts):

Callers 1

closure_test_functionFunction · 0.90

Calls 5

CopyrightDetectorClass · 0.90
TextClass · 0.85
tallyFunction · 0.85
appendMethod · 0.45
detectMethod · 0.45

Tested by 1

closure_test_functionFunction · 0.72