yield candidate.id, FEATURE_PREFIX + feature, value
// Binary candidates
elif len(args) == 2:
span1, span2 = args
if span1.sentence.is_structural() or span2.sentence.is_structural():
for span, prefix in [(span1, "e1_"), (span2, "e2_")]:
if span.stable_id not in unary_strlib_feats:
unary_strlib_feats[span.stable_id] = set()
for feature, value in _strlib_unary_features(span):
unary_strlib_feats[span.stable_id].add((feature, value))
for feature, value in unary_strlib_feats[span.stable_id]:
yield candidate.id, FEATURE_PREFIX + prefix + feature, value
if candidate.id not in binary_strlib_feats:
binary_strlib_feats[candidate.id] = set()
for feature, value in _strlib_binary_features(span1, span2):
binary_strlib_feats[candidate.id].add((feature, value))
for feature, value in binary_strlib_feats[candidate.id]:
yield candidate.id, FEATURE_PREFIX + feature, value
else:
raise NotImplementedError(
"Only handles unary and binary candidates currently"
)
def _strlib_unary_features(span: SpanMention) -> Iterator[Tuple[str, int]]:
Structural-related features for a single span.