mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-08-19 11:50:16 +08:00
ADD: NER
This commit is contained in:
@@ -14,6 +14,7 @@ from indicoio.text.sentiment import posneg as sentiment
|
||||
from indicoio.text.lang import language
|
||||
from indicoio.text.tagging import text_tags
|
||||
from indicoio.text.keywords import keywords
|
||||
from indicoio.text.ner import named_entities
|
||||
from indicoio.images.fer import fer
|
||||
from indicoio.images.features import facial_features
|
||||
from indicoio.images.features import image_features
|
||||
|
||||
+2
-1
@@ -51,7 +51,8 @@ TEXT_APIS = [
|
||||
'sentiment',
|
||||
'language',
|
||||
'sentiment_hq',
|
||||
'keywords'
|
||||
'keywords',
|
||||
'named_entities'
|
||||
]
|
||||
|
||||
IMAGE_APIS = [
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
from indicoio.utils.api import api_handler
|
||||
import indicoio.config as config
|
||||
|
||||
def named_entities(text, cloud=None, batch=False, api_key=None, **kwargs):
|
||||
"""
|
||||
Given input text, returns named entities (proper nouns) found in the text
|
||||
|
||||
Example usage:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
>>> text = "London Underground's boss Mike Brown warned that the strike ..."
|
||||
>>> entities = indicoio.named_entities(text)
|
||||
{u'London Underground': {u'categories': {u'location': 0.583755654607989,
|
||||
u'organization': 0.07460487821791033,
|
||||
u'person': 0.07304850776658672,
|
||||
u'unknown': 0.2685909594075139},
|
||||
u'confidence': 0.846188063604044},
|
||||
u'Mike Brown': {u'categories': {u'location': 0.025813884950623898,
|
||||
u'organization': 0.06661470013014613,
|
||||
u'person': 0.08723850624560824,
|
||||
u'unknown': 0.8203329086736217},
|
||||
u'confidence': 0.8951793008234012}}
|
||||
|
||||
:param text: The text to be analyzed.
|
||||
:type text: str or unicode
|
||||
:rtype: Dictionary of language probability pairs
|
||||
"""
|
||||
url_params = {"batch": batch, "api_key": api_key}
|
||||
return api_handler(text, cloud=cloud, api="namedentities", url_params=url_params, **kwargs)
|
||||
@@ -137,7 +137,7 @@ def predict_image(image, apis=IMAGE_APIS, **kwargs):
|
||||
|
||||
def parsed_response(api, response):
|
||||
result = response.get('results', False)
|
||||
if result:
|
||||
if result != False:
|
||||
return result
|
||||
raise IndicoError(
|
||||
"Sorry, the %s API returned an unexpected response.\n\t%s"
|
||||
|
||||
Reference in New Issue
Block a user