Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.valid = False
class PersonResult(NamedResult):
category = ExtractedEntity.PERSON
def __init__(self, ctx, label, start, end):
super(PersonResult, self).__init__(ctx, label, start, end)
if self.valid and ' ' not in self.label:
self.valid = False
class LocationResult(NamedResult):
"""Locations are being mapped to countries."""
resolver = LocationResolver()
category = ExtractedEntity.LOCATION
def __init__(self, ctx, label, start, end):
super(LocationResult, self).__init__(ctx, label, start, end)
self.countries = self.resolver.get_countries(label)
class LanguageResult(Result):
category = ExtractedEntity.LANGUAGE
def __init__(self, ctx, label, start, end):
label = label.strip().lower()
super(LanguageResult, self).__init__(ctx, label, start, end)
class IPAddressResult(Result):
"""Pull IPv4, IPv6 - and validate using on-board Python tools."""
POLYGLOT_PATH = os.environ.get('POLYGLOT_DATA_PATH')
POLYGLOT_NER_PATH = os.path.join(POLYGLOT_PATH, 'polyglot_data/ner2')
POLYGLOT_LANGUAGES = os.listdir(POLYGLOT_NER_PATH)
POLYGLOT_TYPES = {
'I-PER': ExtractedEntity.PERSON,
'I-ORG': ExtractedEntity.ORGANIZATION,
'I-LOC': ExtractedEntity.LOCATION
}
# https://spacy.io/api/annotation#named-entities
SPACY_TYPES = {
'PER': ExtractedEntity.PERSON,
'PERSON': ExtractedEntity.PERSON,
'ORG': ExtractedEntity.ORGANIZATION,
'LOC': ExtractedEntity.LOCATION,
'GPE': ExtractedEntity.LOCATION
}
class EntityServicer(EntityExtractServicer):
def __init__(self):
log.info("Loading spaCy model xx...")
self.spacy = spacy.load('xx')
def extract_polyglot(self, text):
try:
parsed = Text(text)
lang = parsed.language
if lang.confidence > 90:
yield self.make_entity(lang.code,
# POLYGLOT_PATH = os.environ.get('POLYGLOT_DATA_PATH')
# POLYGLOT_NER_PATH = os.path.join(POLYGLOT_PATH, 'polyglot_data/ner2')
# POLYGLOT_LANGUAGES = os.listdir(POLYGLOT_NER_PATH)
# POLYGLOT_TYPES = {
# 'I-PER': ExtractedEntity.PERSON,
# 'I-ORG': ExtractedEntity.ORGANIZATION,
# 'I-LOC': ExtractedEntity.LOCATION
# }
# https://spacy.io/api/annotation#named-entities
SPACY_TYPES = {
'PER': ExtractedEntity.PERSON,
'PERSON': ExtractedEntity.PERSON,
'ORG': ExtractedEntity.ORGANIZATION,
'LOC': ExtractedEntity.LOCATION,
'GPE': ExtractedEntity.LOCATION
}
class EntityServicer(EntityExtractServicer):
def __init__(self):
log.info("Loading spaCy model xx...")
self.spacy = spacy.load('xx')
# def extract_polyglot(self, text):
# try:
# parsed = Text(text)
# lang = parsed.language
# if lang.confidence > 90:
# yield self.make_entity(lang.code,
# ExtractedEntity.LANGUAGE,