"""Offer an earlier phrase only after the writer selects a pronoun that refers back."""
from research.token_readout.app import source_html
STYLE = """
.writing-review .ref-review { color:#23352f!important; border-top:1px solid #cbd7cf; padding-top:.8rem; }
.writing-review .ref-review h3 { font-size:1.08rem; color:#23352f!important; }
.writing-review .ref-review details { margin:.35rem 0; }
.writing-review .ref-review summary { cursor:pointer; padding:.25rem 0; color:#273d36!important; }
.writing-review .ref-review p { color:#273d36!important; }
.writing-review .ref-answer { border-left:3px solid #356591; padding-left:.65rem; }
"""
def result(text, record):
if record.get('scope')!='given_prior_reference':
raise ValueError('This reference tool requires a writer-selected backward reference.')
candidates=list(map(tuple,record['pronouns']))
if candidates!=sorted(set(candidates)):
raise ValueError('Reference choices must follow their original positions.')
by_pronoun={}
for link in record['links']:
q=link['pronoun_start'],link['pronoun_end'];a,b=link['phrase_start'],link['phrase_end']
if (link['scope']!='given_prior_reference' or q not in candidates or q in by_pronoun
or not 0<=a<=link['antecedent_start']'+source_html(text[a:b])+''+source_html(text[b:end])+('…' if end“{source_html(text[x:y])}”'
else:answer='The model has too little evidence to choose one earlier phrase.'
chunks.append(f'{display}
{answer}
')
explain=('Choose a pronoun you intend to point back. Opening it marks that pronoun and the suggested earlier phrase in your draft.'
if chunks else 'This draft has no supported English pronoun with earlier text to inspect.')
return spans,('' if rules else '')+('