Esempio n. 1
0
def result_entities():
    try:
        stdin = click.get_text_stream('stdin')
        stdout = click.get_text_stream('stdout')
        while True:
            result = read_object(stdin)
            if result is None:
                break
            for entity in result.entities:
                write_object(stdout, entity)
    except BrokenPipeError:
        pass
Esempio n. 2
0
def pretty():
    stdin = click.get_text_stream('stdin')
    stdout = click.get_text_stream('stdout')
    try:
        while True:
            entity = read_object(stdin)
            if entity is None:
                break
            data = json.dumps(entity.to_dict(), indent=2)
            stdout.write(data + '\n')
    except BrokenPipeError:
        pass
Esempio n. 3
0
def auto_match(threshold):
    try:
        stdin = click.get_text_stream('stdin')
        stdout = click.get_text_stream('stdout')
        while True:
            result = read_object(stdin)
            if result is None:
                break
            if result.score > threshold:
                recon = Recon(result.subject, result.candidate, Recon.MATCH)
                write_object(stdout, recon)
    except BrokenPipeError:
        pass
Esempio n. 4
0
def apply_recon(recon):
    try:
        linker = EntityLinker()
        for recon in Recon.from_file(recon):
            if recon.judgement == Recon.MATCH:
                linker.add(recon.subject, recon.canonical)
        stdin = click.get_text_stream('stdin')
        stdout = click.get_text_stream('stdout')
        while True:
            entity = read_object(stdin)
            if entity is None:
                break
            entity = linker.apply(entity)
            write_object(stdout, entity)
    except BrokenPipeError:
        pass
Esempio n. 5
0
def expand(enricher):
    enricher = load_enricher(enricher)
    try:
        stdin = click.get_text_stream('stdin')
        stdout = click.get_text_stream('stdout')
        while True:
            entity = read_object(stdin)
            if entity is None:
                break
            result = enricher.expand_entity(entity)
            write_object(stdout, result)
    except BrokenPipeError:
        pass
    except Exception:
        log.exception("Error during enrichment expansion")
    finally:
        enricher.close()
Esempio n. 6
0
def aggregate():
    buffer = {}
    try:
        stdin = click.get_text_stream('stdin')
        while True:
            entity = read_object(stdin)
            if entity is None:
                break
            if entity.id in buffer:
                buffer[entity.id].merge(entity)
            else:
                buffer[entity.id] = entity

        stdout = click.get_text_stream('stdout')
        for entity in buffer.values():
            write_object(stdout, entity)
    except BrokenPipeError:
        pass
Esempio n. 7
0
def export_rdf():
    stdin = click.get_text_stream('stdin')
    stdout = click.get_text_stream('stdout')
    try:
        while True:
            entity = read_object(stdin)
            if entity is None:
                break
            graph = Graph()
            for link in entity.links:
                triple = link.rdf()
                if triple is None:
                    continue
                graph.add(triple)
            nt = graph.serialize(format='nt').strip()
            stdout.write(nt.decode('utf-8') + '\n')
    except BrokenPipeError:
        pass
Esempio n. 8
0
def filter_results(recon):
    try:
        matches = set()
        for recon in Recon.from_file(recon):
            if recon.judgement == Recon.MATCH:
                matches.add(recon.subject)
        stdin = click.get_text_stream('stdin')
        stdout = click.get_text_stream('stdout')
        while True:
            result = read_object(stdin)
            if result is None:
                break
            if result.candidate is None:
                continue
            if result.candidate.id in matches:
                write_object(stdout, result)
    except BrokenPipeError:
        pass