# Path: parserbot/calais.py
# class CalaisAPI(object):
#     def __init__(self, api_key=None, endpoint=None):
#     def call_api(self, payload):
#     def process_results(self, results):
#     def extract_entities(self, payload):
# 
# Path: parserbot/dbpedia.py
# class DbpediaAPI(object):
#     DBPEDIA_ENDPOINT = "http://lookup.dbpedia.org/api/search.asmx/"
#     SPOTLIGHT_ENDPOINT = "http://spotlight.dbpedia.org/rest/"
#     def get_json(self, url, params):
#     def spotlight_annotate(self, payload):
#     def extract_entities(self, payload):
#     def keyword_search(self, keyword):
#     def prefix_search(self, prefix):
#     def wikify_stanford(self, stanford_results):
# 
# Path: parserbot/stanford.py
# class StanfordNER(object):
#     def __init__(self, classifier=None, jarfile=None):
#     def run_tagger(self, payload):
#     def process_sentences(self, sentences):
#     def extract_entities(self, payload):
# 
# Path: parserbot/zemanta.py
# class ZemantaAPI(object):
#     def __init__(self, api_key=None, endpoint=None):
#     def _access_api(self, params):
#     def suggest(self, text, **kwargs):
#     def suggest_markup(self, text, emphasis=None,
#             return_rdf_links=False, markup_limit=None):
#     def preferences(self):
#     def extract_entities(self, payload):


from flask import current_app, Blueprint, jsonify, request, abort
from parserbot import calais, dbpedia, stanford, zemanta
import hashlib


@bp.route('/stanford', methods=['POST'])
def run_stanford():
    """
    Used for the ``/stanford`` endpoint. Runs methods in two stages:

    - Calls :py:meth:`parserbot.stanford.StanfordNER.extract_entities` and
        dedupes the results
    - Runs the results through :py:meth:`dbpedia.DbpediaAPI.wikify_stanford`
        to link the entities to Wikipedia

    :return: JSON response object with matching entities.
    """
    stanford_results = _handle(stanford.StanfordNER().extract_entities)
    # dedupe the lists so that we aren't calling dbpedia repeatedly
    stanford_results = {k: list(set(v)) for k,v in stanford_results.items()}
    # now get dbpedia URLs for them
    dbp_results = dbpedia.DbpediaAPI().wikify_stanford(stanford_results)
    return _respond(dbp_results)


@bp.route('/dbpedia', methods=['POST'])
def run_dbpedia():
    """
    Used for the ``/dbpedia`` endpoint.
    Calls :py:meth:`parserbot.dbpedia.DbpediaAPI.get_entities`

    :return: JSON response object with matching entities.
    """

# Path: parserbot/calais.py
# class CalaisAPI(object):
#     def __init__(self, api_key=None, endpoint=None):
#     def call_api(self, payload):
#     def process_results(self, results):
#     def extract_entities(self, payload):
# 
# Path: parserbot/dbpedia.py
# class DbpediaAPI(object):
#     DBPEDIA_ENDPOINT = "http://lookup.dbpedia.org/api/search.asmx/"
#     SPOTLIGHT_ENDPOINT = "http://spotlight.dbpedia.org/rest/"
#     def get_json(self, url, params):
#     def spotlight_annotate(self, payload):
#     def extract_entities(self, payload):
#     def keyword_search(self, keyword):
#     def prefix_search(self, prefix):
#     def wikify_stanford(self, stanford_results):
# 
# Path: parserbot/stanford.py
# class StanfordNER(object):
#     def __init__(self, classifier=None, jarfile=None):
#     def run_tagger(self, payload):
#     def process_sentences(self, sentences):
#     def extract_entities(self, payload):
# 
# Path: parserbot/zemanta.py
# class ZemantaAPI(object):
#     def __init__(self, api_key=None, endpoint=None):
#     def _access_api(self, params):
#     def suggest(self, text, **kwargs):
#     def suggest_markup(self, text, emphasis=None,
#             return_rdf_links=False, markup_limit=None):
#     def preferences(self):
#     def extract_entities(self, payload):


# Path: parserbot/api.py
from flask import current_app, Blueprint, jsonify, request, abort
from parserbot import calais, dbpedia, stanford, zemanta
import hashlib



@bp.route('/stanford', methods=['POST'])
def run_stanford():
    """
    Used for the ``/stanford`` endpoint. Runs methods in two stages:

    - Calls :py:meth:`parserbot.stanford.StanfordNER.extract_entities` and
        dedupes the results
    - Runs the results through :py:meth:`dbpedia.DbpediaAPI.wikify_stanford`
        to link the entities to Wikipedia

    :return: JSON response object with matching entities.
    """
    stanford_results = _handle(stanford.StanfordNER().extract_entities)
    # dedupe the lists so that we aren't calling dbpedia repeatedly
    stanford_results = {k: list(set(v)) for k,v in stanford_results.items()}
    # now get dbpedia URLs for them
    dbp_results = dbpedia.DbpediaAPI().wikify_stanford(stanford_results)
    return _respond(dbp_results)


@bp.route('/dbpedia', methods=['POST'])
def run_dbpedia():
    """
    Used for the ``/dbpedia`` endpoint.
    Calls :py:meth:`parserbot.dbpedia.DbpediaAPI.get_entities`

    :return: JSON response object with matching entities.
    """

    results = _handle(dbpedia.DbpediaAPI().extract_entities)