Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# We want to find the tag set(s) who has the fewest tags over what was
# provided
min_difference = min(map(lambda x: len(x[1].difference(s)),
candidates))
most_likely = list(filter(lambda x:
len(x[1].difference(s)) == min_difference,
candidates))
leftover = s.difference(most_likely[0][1])
most_likely_classes = [list(x[0])[0] for x in most_likely]
# return most likely classes (list) and leftover tags
# (what of 'orig_s' wasn't used)
return most_likely_classes, leftover
class HaystackInferenceSession(TagInferenceSession):
"""
Wraps TagInferenceSession to provide inference of a Brick model
from a Haystack model. The haystack model is expected to be encoded
as a dictionary with the keys "cols" and "rows"; I believe this is
a standard Haystack JSON export.
TODO: double check this
"""
def __init__(self, namespace):
"""
Creates a new HaystackInferenceSession that infers entities into
the given namespace
Args:
namespace (str): namespace into which the inferred Brick entities
are deposited. Should be a valid URI