def names_in_chains(stream_item, aligner_data):
chain_selector = aligner_data.get('<STR_LIT>', '<STR_LIT>')<EOL>assert chain_selector in _CHAIN_SELECTORS,'<STR_LIT>' % (chain_selector, list(_CHAIN_SELECTORS.keys()))<EOL>chain_selector = _CHAIN_SELECTORS[chain_selector]<EOL>equiv_ids = make_chains_with_names( stream_item.body.sentences )<EOL>required_annotator_id = aligner_data.get('<STR_LIT>')<EOL>for annotator_id, ratings in list(stream_item.ratings.items()):<EOL><INDENT>if (required_annotator_id is not None) and (annotator_id != required_annotator_id):<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>for rating in ratings:<EOL><INDENT>label = Label(annotator=rating.annotator,<EOL>target=rating.target)<EOL>for eqid, (chain_mentions, chain_tokens) in list(equiv_ids.items()):<EOL><INDENT>if chain_selector(rating.mentions, chain_mentions):<EOL><INDENT>for tok in chain_tokens:<EOL><INDENT>add_annotation(tok, label)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>
Convert doc-level Rating object into a Label, and add that Label
to all Token in all coref chains identified by
aligner_data["chain_selector"]

:param stream_item: document that has a doc-level Rating to translate into token-level Labels.
:param aligner_data: dict containing:
  chain_selector: ALL or ANY
  annotator_id: string to find at stream_item.Ratings[i].annotator.annotator_id

If chain_selector==ALL, then only apply Label to chains in which
all of the Rating.mentions strings appear as substrings within at
least one of the Token.token strings.

If chain_selector==ANY, then apply Label to chains in which any of
the Rating.mentions strings appear as a substring within at least
one of the Token.token strings.

If chain_selector==ANY_MULTI_TOKEN, then apply Label to chains in which all
the names in any of the Rating.mentions strings appear as a substring within at least
one of the Token.token strings.