Пример #1
0
class GerbilNIFCollection:
    def __init__(self, context: str, mention: str):
        self.collection = NIFCollection()
        self.context = context
        self.mention = mention
        self.phrases = self.collection.add_context(self.context, self.mention)

    @property
    def turtle(self) -> str:
        return self.collection.dumps(format='turtle')
Пример #2
0
def annotation2nif(collection_name, tweet):
    collection = NIFCollection(uri=collection_name)
    context_name = collection_name + str(tweet.idTweet)
    context = collection.add_context(uri=context_name, mention=tweet.text)
    if len(tweet.mentions) > 0:
        for i, mention in enumerate(tweet.mentions):
            if tweet.entities[i] != 'NIL':
                entity = tweet.entities[i].replace(
                    'dbr:', 'http://dbpedia.org/resource/')
            else:
                entity = 'http://optic.ufsc.br/resource/NIL/'
            context.add_phrase(beginIndex=int(mention[2]),
                               endIndex=int(mention[3]),
                               annotator='http://optic.ufsc.br',
                               taIdentRef=entity)
    nif = collection.dumps(format='turtle')
    return nif
Пример #3
0
from pynif import NIFCollection
import sys,os,json,re


d = json.loads(open('input/webqsp.test.entities.with_classes.json').read())

collection = NIFCollection(uri="http://sda.tech/webquestions")

for item in d:
    if not item['utterance']:
        continue
    uid = item['question_id']
    context = collection.add_context(uri="http://sda.tech/webquestions/%s"%uid,
    mention=item['utterance'])
    beg = 0
    for entity in item['entities']:
        if entity is None:
            continue
        context.add_phrase(taIdentRef='http://www.wikidata.org/entity/'+entity, beginIndex=beg, endIndex=beg+1)
        beg+=1

generated_nif = collection.dumps(format='turtle')
f = open('webqsp.test.nif','w')
f.write(generated_nif)
f.close()