Update stix2/equivalence/object/__init__.py

update variable names

Co-authored-by: Chris Lenk <clenk@users.noreply.github.com>
pull/1/head
Emmanuelle Vargas-Gonzalez 2021-02-18 09:14:34 -05:00 committed by GitHub
parent 52c5f3ad29
commit 154fc4e236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 9 deletions

View File

@ -434,27 +434,29 @@ def list_reference_check(refs1, refs2, ds1, ds2, **weights):
return result
def _bucket_per_type(g, mode="type"):
def _bucket_per_type(graph, mode="type"):
"""Given a list of objects or references, bucket them by type.
Depending on the list type: extract from 'type' property or using
the 'id'"""
the 'id'.
"""
buckets = collections.defaultdict(list)
if mode == "type":
[buckets[obj["type"]].append(obj) for obj in g]
[buckets[obj["type"]].append(obj) for obj in graph]
elif mode == "id-split":
[buckets[obj.split("--")[0]].append(obj) for obj in g]
[buckets[obj.split("--")[0]].append(obj) for obj in graph]
return buckets
def _object_pairs(g1, g2, w):
def _object_pairs(graph1, graph2, weights):
"""Returns a generator with the product of the comparable
objects for the graph similarity process. It determines
objects in common between graphs and objects with weights."""
types_in_common = set(g1.keys()).intersection(g2.keys())
testable_types = types_in_common.intersection(w.keys())
objects in common between graphs and objects with weights.
"""
types_in_common = set(graph1.keys()).intersection(graph2.keys())
testable_types = types_in_common.intersection(weights.keys())
return itertools.chain.from_iterable(
itertools.product(g1[stix_type], g2[stix_type])
itertools.product(graph1[stix_type], graph2[stix_type])
for stix_type in testable_types
)