How to use the alephclient.services.entityextract_pb2_grpc.EntityExtractStub function in alephclient

To help you get started, we’ve selected a few alephclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alephdata / aleph / aleph / analyze / extract_entity.py View on Github external
def extract(self, collector, document):
        DocumentTagCollector(document, 'polyglot').save()
        DocumentTagCollector(document, 'spacy').save()
        try:
            service = EntityExtractStub(self.channel)
            texts = self.text_iterator(document)
            entities = service.Extract(texts)
            for entity in entities.entities:
                type_ = self.TYPES.get(entity.type)
                if type_ is None:
                    continue
                collector.emit(entity.label, type_, weight=entity.weight)
            log.info('Extracted %s entities.', len(collector))
        except self.Error as exc:
            log.exception("gRPC Error: %s", self.SERVICE)
            self.reset_channel()
github alephdata / aleph / aleph / analyze / extract_entity.py View on Github external
def extract(self, collector, document):
        DocumentTagCollector(document, 'polyglot').save()
        DocumentTagCollector(document, 'spacy').save()
        try:
            service = EntityExtractStub(self.channel)
            texts = self.text_iterator(document)
            entities = service.Extract(texts)
            for entity in entities.entities:
                type_ = self.TYPES.get(entity.type)
                if type_ is None:
                    continue
                collector.emit(entity.label, type_, weight=entity.weight)
            log.info('Extracted %s entities.', len(collector))
        except self.Error as e:
            log.warning("gRPC [%s]: %s", e.code(), e.details())
            self.reset_channel()
github alephdata / aleph / services / extract-entities / external_client.py View on Github external
import statistics
import grpc
import time
from alephclient.services.entityextract_pb2_grpc import EntityExtractStub
from alephclient.services.common_pb2 import Text

URL = 'localhost:50000'

channel = grpc.insecure_channel(URL)
service = EntityExtractStub(channel)


def generate():
    with open('tests/fixtures/pace.txt', 'r', encoding='utf-8') as fh:
        for line in fh:
            yield Text(text=line, languages=['en'])


times = []
for i in range(1):
    start = time.time()
    entities = service.Extract(generate())
    for entity in entities.entities:
        print((entity.label, entity.weight, entity.type))
        pass
    end = time.time()