"""Strict span+label scoring on fixed fictional examples; no NLP model executed."""
import json
DATA={'example_is_fictional': True, 'offset_unit': 'Python Unicode code point; start inclusive, end exclusive; unchanged original text', 'text': 'مینا از شرکت سپید در شیراز با مینا دیدار کرد.', 'gold': [{'start': 0, 'end': 4, 'label': 'PER', 'text': 'مینا'}, {'start': 8, 'end': 17, 'label': 'ORG', 'text': 'شرکت سپید'}, {'start': 21, 'end': 26, 'label': 'LOC', 'text': 'شیراز'}, {'start': 30, 'end': 34, 'label': 'PER', 'text': 'مینا'}], 'constructed_predictions_not_model_output': [{'start': 0, 'end': 4, 'label': 'PER', 'text': 'مینا'}, {'start': 13, 'end': 17, 'label': 'ORG', 'text': 'سپید'}, {'start': 21, 'end': 26, 'label': 'ORG', 'text': 'شیراز'}]}
def key(x): return x["start"],x["end"],x["label"]
if __name__=="__main__":
    text=DATA["text"]
    for x in DATA["gold"]+DATA["constructed_predictions_not_model_output"]:
        assert text[x["start"]:x["end"]]==x["text"]
    gold={key(x) for x in DATA["gold"]}; pred={key(x) for x in DATA["constructed_predictions_not_model_output"]}
    tp=len(gold&pred);fp=len(pred-gold);fn=len(gold-pred)
    assert (tp,fp,fn)==(1,2,3)
    print(json.dumps({"TP":tp,"FP":fp,"FN":fn,"precision":tp/(tp+fp),"recall":tp/(tp+fn),"F1":2*tp/(2*tp+fp+fn)},indent=2))
