Ejemplo n.º 1
0
import logging
from os.path import realpath

from utils.html import check_json_response, post_request
from utils.text import int2utf8, remove_illegal_chars
from utils.store import get_wiki_store

db_dir = realpath(__file__).rsplit(
    "/annotators")[0] + "/resources/wiki_title_to_id"

logger = logging.getLogger("entivaluator")

wiki_id_db = get_wiki_store()


def get_entities(endpoint, text, conf=0.5, support=5):
    payload = {
        "text": remove_illegal_chars(text),
        "confidence": conf,
        "support": support
    }
    spotlight_headers = {
        'accept': 'application/json',
        'content-type': 'application/x-www-form-urlencoded'
    }

    response = post_request(endpoint, payload, spotlight_headers)
    return check_json_response(response)


def format_data(json_response):
Ejemplo n.º 2
0
from annotators.conf import TITLE_TO_ID, ENDPOINTS
from utils.html import check_json_response, post_request
from utils.text import remove_illegal_chars
from utils.store import get_wiki_store
from utils.logger import get_logger


logger = get_logger()
wiki_id_db = get_wiki_store(TITLE_TO_ID["spotlight"])


def get_entities(text, conf=0.45):
    """
    A function to get annotations.
    :param text: str: text to annotate
    :param conf: float: confidence
    :return: list
    """

    payload = {"text": remove_illegal_chars(text), "confidence": conf}
    spotlight_headers = {'accept': 'application/json',
                         'content-type': 'application/x-www-form-urlencoded'}

    response = post_request(ENDPOINTS["spotlight"], payload, spotlight_headers)
    return check_json_response(response)


def format_data(json_response):
    """
    A function for formatting output data in a dexter-eval format.
    :param text: str: text to annotate
Ejemplo n.º 3
0
import logging
from os.path import realpath

from utils.html import check_json_response, post_request
from utils.text import int2utf8, remove_illegal_chars
from utils.store import get_wiki_store

db_dir = realpath(__file__).rsplit("/annotators")[0] + "/resources/wiki_title_to_id"

logger = logging.getLogger("entivaluator")

wiki_id_db = get_wiki_store()

def get_entities(endpoint, text, conf=0.5, support=5):
    payload = {"text": remove_illegal_chars(text), "confidence": conf, "support": support}
    spotlight_headers = {'accept': 'application/json',
                         'content-type': 'application/x-www-form-urlencoded'}

    response = post_request(endpoint, payload, spotlight_headers)
    return check_json_response(response)


def format_data(json_response):
    output = []
    key = "Resources"
    if json_response and key in json_response and json_response[key]:
        entities = json_response["Resources"]
        for ent in entities:
            try:
                surface_form = ent["@surfaceForm"]
                title = ent["@URI"].rsplit("resource/", 1)[1]