Beispiel #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')
Beispiel #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
Beispiel #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()

Beispiel #4
0
from pynif import NIFCollection
import sys, os, json, re

d = json.loads(open('test.json').read())

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

for item in d:
    if not item['question']:
        continue
    uid = item['uid']
    context = collection.add_context(uri="http://sda.tech/lcquadv2/%s" % uid,
                                     mention=item['question'])
    entities = re.findall(r'wd:([Q][0-9]*)', item['sparql_wikidata'])
    beg = 0
    for entity in entities:
        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('lcquad2.0.test.nif', 'w')
f.write(generated_nif)
f.close()
Beispiel #5
0
from pynif import NIFCollection
import sys, os, json, re

d = json.loads(open('train.json').read())

collection = NIFCollection(uri="http://lc-quad2.sda.tech")

for item in d:
    if not item['question']:
        continue
    uid = item['uid']
    context = collection.add_context(uri="http://lc-quad2.0.sda.tech/%s" % uid,
                                     mention=item['question'])
    entities = re.findall(r'wd:([Q][0-9]*)', item['sparql_wikidata'])
    for entity in entities:
        context.add_phrase(taIdentRef='http://www.wikidata.org/entity/' +
                           entity,
                           beginIndex=0,
                           endIndex=1)

generated_nif = collection.dumps(format='turtle')
f = open('lcquad2.0.train.nif', 'w')
f.write(generated_nif)
f.close()
Beispiel #6
0
f = open('input/graph.test.entities.json')
d = json.loads(f.read())

for item in d:
    unit = {}
    unit['uid'] = int(item['question_id'])
    unit['question'] = item['utterance']
    unit['entities'] = item['entities']
    gold.append(unit)

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

for item in gold:
    uid = item['uid']
    context = collection.add_context(uri="http://sda.tech/graphquestions/%s" %
                                     uid,
                                     mention=item['question'])
    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('graphquestions.test.nif', 'w')
f.write(generated_nif)
f.close()
Beispiel #7
0
from pynif import NIFCollection
import sys,os,json,re



gold = []
f = open('annotated_wd_data_train.txt')
for line in f.readlines():
    line = line.strip()
    s,p,o,q = line.split('\t')
    gold.append((s,q))

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

for idx,item in enumerate(gold):
    question = item[1]
    entity = item[0]
    uid = idx
    context = collection.add_context(uri="http://sda.tech/simplequestions/%s"%uid, mention=question)
    context.add_phrase(taIdentRef='http://www.wikidata.org/entity/'+entity, beginIndex=0, endIndex=1)

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