Example #1
0
def greedy_process(text, _, allcase=False, topn=1, **kwargs):
    entities = []
    mentions = mention.greedy_detector(erd_db, text, allcase=allcase)
    for m in mentions:
        if stopped(m[0]):
            continue

        mid = None
        score = 0.9
        for title in erd_db.gen_texts(m[0], allcase):
            mid, score = erd_db.freebase_text(title, topn=topn)
            if mid is not None:
                break
        if mid is None:
            continue
        entities.append((m[1], m[2], mid, second_id(mid), m[0], score, 0.99))
    # filter less popular texts
    mentioned = set()
    for e in entities:
        if e[-2] >= 0.9:
            mentioned.add(e[2])
    filtered = []
    for e in entities:
        if e[2] in mentioned:
            filtered.append(e)
    return filter_over(filtered), []
Example #2
0
def greedy_process(text, _, allcase=False, topn=1, **kwargs):
    entities = []
    mentions = mention.greedy_detector(erd_db, text, allcase=allcase)
    for m in mentions:
        if stopped(m[0]):
            continue

        mid = None
        score = 0.9
        for title in erd_db.gen_texts(m[0], allcase):
            mid, score = erd_db.freebase_text(title, topn=topn)
            if mid is not None:
                break
        if mid is None:
            continue
        entities.append((m[1], m[2], mid, second_id(mid), m[0], score, 0.99))
    # filter less popular texts
    mentioned = set()
    for e in entities:
        if e[-2] >= 0.9:
            mentioned.add(e[2])
    filtered = []
    for e in entities:
        if e[2] in mentioned:
            filtered.append(e)
    return filter_over(filtered), []
Example #3
0
"""test
test.py DB-PATH QUERY_TEXT
"""
import sys
import mention
import db

erd_db = db.Database()
erd_db.open(sys.argv[1])

print('start testing')
with open(sys.argv[2], 'r') as f:
    print(mention.greedy_detector(erd_db, f.read()))

while True:
    get = input()
    if len(get) == 0:
        break
    else:
        print(mention.greedy_detector(erd_db, get))