Package org.dbpedia.spotlight.exceptions

Examples of org.dbpedia.spotlight.exceptions.AnnotationException


        String query = String.format(ONTOS_QUERY_ENTITY, eid);
        try {
            query = URLEncoder.encode(query, "utf-8");
        } catch (UnsupportedEncodingException e) {
            LOG.error(e.getMessage());
            throw new AnnotationException(e);
        }
        JSONObject json = request(path+query);
        JSONObject entity = new JSONObject();
        try {
             entity = json.getJSONObject("result");
View Full Code Here


       String response = request(method);
       JSONObject json = new JSONObject();
       try {
           json = new JSONObject(response);
           if (!(json.getBoolean("success")))
               throw new AnnotationException("Could not execute dereference query to Ontos. "+url);
       } catch (JSONException e) {
           LOG.error(e.getMessage());
       }
        return json;
    }
View Full Code Here

    protected String process(String text) throws AnnotationException {
        String url = "";
        try {
            url = String.format(url_pattern, URLEncoder.encode(text, "UTF8"));
        } catch (UnsupportedEncodingException e) {
            throw new AnnotationException(e);
        }
        GetMethod method = new GetMethod(url);
        String response = request(method);
        //System.out.println(response);
        return response;
View Full Code Here

        //LOG.trace(response);
        Element root = null;
        try {
            root = XmlParser.parse(response);
        } catch (Exception e) { //IOException, ParseException, ParserConfigurationException
            throw new AnnotationException("Could not parse XML response.",e);
        }
        NodeList list = XmlParser.getNodes("//WikipediaMinerResponse/WikifierResponse/DetectedTopicList/DetectedTopic", root);

        for(int i=0; i<list.getLength(); i++) {
            Node node = list.item(i);
View Full Code Here

            InputStream is = new ByteArrayInputStream(html.getBytes("UTF-8"));
            parser = new Source(is);
            parser.fullSequentialParse();
            parser.getElementById("div");
        } catch (IOException e) {
            throw new AnnotationException("Error reading output from WikiMachine ",e);
        }
        List<Element>KeywordElements=parser.getAllElementsByClass("keywords");

        if (KeywordElements!=null && !KeywordElements.isEmpty()){
            Element keywordElement= KeywordElements.get(0);
View Full Code Here

          + "&text=" + URLEncoder.encode(text.text(), "utf-8"));
      getMethod.addRequestHeader(new Header("Accept", "application/json"));

      spotlightResponse = request(getMethod);
    } catch (UnsupportedEncodingException e) {
      throw new AnnotationException("Could not encode text.", e);
    }

    assert spotlightResponse != null;

    JSONObject resultJSON = null;
    JSONArray entities = null;

    try {
      resultJSON = new JSONObject(spotlightResponse);
      entities = resultJSON.getJSONArray("Resources");
    } catch (JSONException e) {
      throw new AnnotationException("Received invalid response from DBpedia Spotlight API.");
    }

    LinkedList<DBpediaResource> resources = new LinkedList<DBpediaResource>();
    for(int i = 0; i < entities.length(); i++) {
      try {
View Full Code Here

    final URI extractivServerURI;
    try {
      extractivServerURI = new URI(API_URL);
    } catch (URISyntaxException e) {
      throw new AnnotationException(e);
    }

    final HttpMethodBase extractivRequest;

    File tmp = null;
    try {
      tmp = File.createTempFile("tmpText", ".txt");
      FileWriter fileWriter = new FileWriter(tmp);
      fileWriter.write(text.text());
      fileWriter.close();
      extractivRequest = getExtractivProcessFileRequest(extractivServerURI, tmp);
    } catch (IOException e) {
      throw new AnnotationException("Could not create request for Extractiv API.");
    }

    final String extractivResults = request(extractivRequest);
    JSONObject resultsJSON = null;
    JSONArray entities = null;

    try {
      resultsJSON = new JSONObject(extractivResults);
      entities = resultsJSON.getJSONArray("entities");
    } catch (JSONException e) {
      throw new AnnotationException("Received invalid response from Extractiv API.");
    }

    for (int i = 0; i < entities.length(); i++) {
      try {
        JSONObject entity = (JSONObject) entities.get(i);
View Full Code Here

            // Use caution: ensure correct character encoding and is not binary data
            response = new String(responseBody);

        } catch (HttpException e) {
            LOG.error("Fatal protocol violation: " + e.getMessage());
            throw new AnnotationException("Protocol error executing HTTP request.",e);
        } catch (IOException e) {
            LOG.error("Fatal transport error: " + e.getMessage());
            LOG.error(method.getQueryString());
            throw new AnnotationException("Transport error executing HTTP request.",e);
        } finally {
            // Release the connection.
            method.releaseConnection();
        }
        return response;
View Full Code Here

    JSONArray requestData;
    try {
      requestData = request(buildURL(text));
    } catch (JSONException e) {
      throw new AnnotationException("Could not read API response.",e);
    } catch (UnsupportedEncodingException e) {
      throw new AnnotationException("Could not build API request URL.",e);
    }

    if(requestData.length() == 0)
      return dbpediaResources;
View Full Code Here

TOP

Related Classes of org.dbpedia.spotlight.exceptions.AnnotationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.