Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from aleph import settings
from aleph.services import ServiceClientMixin
from aleph.analyze.analyzer import EntityAnalyzer, TextIterator
from aleph.model import DocumentTag, DocumentTagCollector
log = logging.getLogger(__name__)
TYPE = ExtractedEntity.Type.Value
class EntityExtractor(EntityAnalyzer, TextIterator, ServiceClientMixin):
SERVICE = settings.ENTITIES_SERVICE
ORIGIN = 'ner'
TYPES = {
ExtractedEntity.PERSON: DocumentTag.TYPE_PERSON,
ExtractedEntity.ORGANIZATION: DocumentTag.TYPE_ORGANIZATION,
ExtractedEntity.COMPANY: DocumentTag.TYPE_ORGANIZATION,
}
def __init__(self):
self.active = self.has_channel()
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
from aleph import settings
from aleph.services import ServiceClientMixin
from aleph.analyze.analyzer import EntityAnalyzer, TextIterator
from aleph.model import DocumentTag, DocumentTagCollector
log = logging.getLogger(__name__)
TYPE = ExtractedEntity.Type.Value
class EntityExtractor(EntityAnalyzer, TextIterator, ServiceClientMixin):
SERVICE = settings.ENTITIES_SERVICE
ORIGIN = 'ner'
TYPES = {
ExtractedEntity.PERSON: DocumentTag.TYPE_PERSON,
ExtractedEntity.ORGANIZATION: DocumentTag.TYPE_ORGANIZATION,
ExtractedEntity.COMPANY: DocumentTag.TYPE_ORGANIZATION,
}
def __init__(self):
self.active = self.has_channel()
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