def serialize_para(self, document, tok_to_char_offset, span, mentions, doc_id,
                     para_id):
    """Create JSON object for input paragraph."""
    context = " ".join([tt.word for tt in document.tokens[span[0]:span[1]]])
    my_offsets = {}
    begin = tok_to_char_offset[span[0]]
    for ix in range(span[0], span[1]):
      my_offsets[ix] = tok_to_char_offset[ix] - begin
    mention_objs = []
    for m, ent in mentions:
      mention_objs.append({
          "wikidata_id": ent,
          "name": self.get_name(ent),
          "aliases": self.get_aliases(ent),
          "start": my_offsets[m.begin],
          "text": " ".join(tt.word for tt in document.tokens[m.begin:m.end]),
      })
    return json.dumps({
        "id": para_id,
        "wikidata_id": doc_id,
        "context": context,
        "mentions": mention_objs,
    })
Create JSON object for input paragraph.
language/labs/drkit/wikidata/preprocessing/distantly_supervise.py