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

Function build_tallies

src/summarycode/copyright_tallies.py:82–152  ·  view source on GitHub ↗

Update the ``resource`` Resource with a tally of scan fields from itself and its ``children``. Resources and this for the `attributes_list` values list key (such as copyrights, etc) and the ``attribute_value`` details key (such as copyright). - `attributes_list` is the name o

(
    resource,
    children,
    attributes_list,
    attribute_value,
    tallier,
    keep_details=False,
)

Source from the content-addressed store, hash-verified

80
81
82def build_tallies(
83 resource,
84 children,
85 attributes_list,
86 attribute_value,
87 tallier,
88 keep_details=False,
89):
90 """
91 Update the ``resource`` Resource with a tally of scan fields from itself and its
92 ``children``.
93
94 Resources and this for the `attributes_list` values list key (such as
95 copyrights, etc) and the ``attribute_value`` details key (such as copyright).
96
97 - `attributes_list` is the name of the attribute values list
98 ('copyrights', 'holders' etc.)
99
100 - `attribute_value` is the name of the attribute value key in this list
101 ('copyright', 'holder' etc.)
102
103 - `tallier` is a function that takes a list of texts and returns
104 texts with counts
105 """
106 # Collect current data
107 values = getattr(resource, attributes_list, [])
108
109 no_detection_counter = 0
110
111 if values:
112 # keep current data as plain strings
113 candidate_texts = [entry.get(attribute_value) for entry in values]
114 else:
115 candidate_texts = []
116 if resource.is_file:
117 no_detection_counter += 1
118
119 # Collect direct children existing summaries
120 for child in children:
121 child_summaries = get_resource_tallies(
122 child,
123 key=attributes_list,
124 as_attribute=keep_details
125 ) or []
126
127 for child_summary in child_summaries:
128 count = child_summary['count']
129 value = child_summary['value']
130 if value:
131 candidate_texts.append(Text(value, value, count))
132 else:
133 no_detection_counter += count
134
135 # summarize proper using the provided function
136 tallied = tallier(candidate_texts)
137
138 # add back the counter of things without detection
139 if no_detection_counter:

Callers 3

copyright_talliesFunction · 0.85
holder_talliesFunction · 0.85
author_talliesFunction · 0.85

Calls 8

get_resource_talliesFunction · 0.90
sorted_counterFunction · 0.90
set_resource_talliesFunction · 0.90
TextClass · 0.85
logger_debugFunction · 0.70
getMethod · 0.65
appendMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected