def disambiguate(self, instance): output = "" prev = 0 for mention in instance.mentions: output += instance.text[prev:mention.start] output += "[[%s]]" % mention.spot prev = mention.end output += instance.text[prev:] params = self.get_params() url = params.pop('url') params['text'] = output r = requests.post(url, data=params) data = r.json() mentions = [] for ann in filter(lambda x: 'bestEntity' in x, data['mentions']): spot = ann['name'] start = ann['offset'] end = start + ann['length'] title = ann['bestEntity']['name'].decode('unicode-escape') wid = get_wid_from_title(title) score1 = float(ann['bestEntity']['disambiguationScore']) mentions.append( Mention(spot, start, end, title, wid, score1=score1) ) return mentions
def annotate(self, instance): data = self.get_params() url = data.pop('url') data['text'] = instance.text data = requests.post(url, params=self.get_params(), data=data).json() mentions = [] for ann in filter(lambda x: 'bestEntity' in x, data['mentions']): spot = ann['name'] start = ann['offset'] end = start + ann['length'] title = ann['bestEntity']['name'].decode('unicode-escape') wid = get_wid_from_title(title) score1 = float(ann['bestEntity']['disambiguationScore']) mentions.append( Mention(spot, start, end, title, wid, score1=score1) ) return mentions