This is an automated email from the ASF dual-hosted git repository. tallison pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tika.git
commit ac1791af88e55fea8b1ff65987e32af93f528359 Author: tballison <[email protected]> AuthorDate: Tue May 16 08:35:23 2017 -0400 clean up indentation --- .../tika/parser/journal/GrobidRESTParser.java | 132 ++++++++++----------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/journal/GrobidRESTParser.java b/tika-parsers/src/main/java/org/apache/tika/parser/journal/GrobidRESTParser.java index 05b09fc..22526ff 100644 --- a/tika-parsers/src/main/java/org/apache/tika/parser/journal/GrobidRESTParser.java +++ b/tika-parsers/src/main/java/org/apache/tika/parser/journal/GrobidRESTParser.java @@ -5,9 +5,9 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -36,77 +36,77 @@ import org.xml.sax.ContentHandler; public class GrobidRESTParser { - private static final String GROBID_REST_HOST = "http://localhost:8080"; + private static final String GROBID_REST_HOST = "http://localhost:8080"; - private static final String GROBID_ISALIVE_PATH = "/grobid"; // isalive - // doesn't work - // nfc why + private static final String GROBID_ISALIVE_PATH = "/grobid"; // isalive + // doesn't work + // nfc why - private static final String GROBID_PROCESSHEADER_PATH = "/processHeaderDocument"; + private static final String GROBID_PROCESSHEADER_PATH = "/processHeaderDocument"; - private String restHostUrlStr; + private String restHostUrlStr; - public GrobidRESTParser() { - String restHostUrlStr = null; - try { - restHostUrlStr = readRestUrl(); - } catch (IOException e) { - e.printStackTrace(); + public GrobidRESTParser() { + String restHostUrlStr = null; + try { + restHostUrlStr = readRestUrl(); + } catch (IOException e) { + e.printStackTrace(); + } + + if (restHostUrlStr == null + || (restHostUrlStr != null && restHostUrlStr.equals(""))) { + this.restHostUrlStr = GROBID_REST_HOST; + } else { + this.restHostUrlStr = restHostUrlStr; + } } - if (restHostUrlStr == null - || (restHostUrlStr != null && restHostUrlStr.equals(""))) { - this.restHostUrlStr = GROBID_REST_HOST; - } else { - this.restHostUrlStr = restHostUrlStr; + public void parse(String filePath, ContentHandler handler, Metadata metadata, + ParseContext context) throws FileNotFoundException { + + File pdfFile = new File(filePath); + ContentDisposition cd = new ContentDisposition( + "form-data; name=\"input\"; filename=\"" + pdfFile.getName() + "\""); + Attachment att = new Attachment("input", new FileInputStream(pdfFile), cd); + MultipartBody body = new MultipartBody(att); + + Response response = WebClient + .create(restHostUrlStr + GROBID_PROCESSHEADER_PATH) + .accept(MediaType.APPLICATION_XML).type(MediaType.MULTIPART_FORM_DATA) + .post(body); + + try { + String resp = response.readEntity(String.class); + Metadata teiMet = new TEIParser().parse(resp); + for (String key : teiMet.names()) { + metadata.add("grobid:header_" + key, teiMet.get(key)); + } + } catch (Exception e) { + e.printStackTrace(); + } } - } - - public void parse(String filePath, ContentHandler handler, Metadata metadata, - ParseContext context) throws FileNotFoundException { - - File pdfFile = new File(filePath); - ContentDisposition cd = new ContentDisposition( - "form-data; name=\"input\"; filename=\"" + pdfFile.getName() + "\""); - Attachment att = new Attachment("input", new FileInputStream(pdfFile), cd); - MultipartBody body = new MultipartBody(att); - - Response response = WebClient - .create(restHostUrlStr + GROBID_PROCESSHEADER_PATH) - .accept(MediaType.APPLICATION_XML).type(MediaType.MULTIPART_FORM_DATA) - .post(body); - - try { - String resp = response.readEntity(String.class); - Metadata teiMet = new TEIParser().parse(resp); - for (String key : teiMet.names()) { - metadata.add("grobid:header_" + key, teiMet.get(key)); - } - } catch (Exception e) { - e.printStackTrace(); + + private static String readRestUrl() throws IOException { + Properties grobidProperties = new Properties(); + grobidProperties.load(GrobidRESTParser.class + .getResourceAsStream("GrobidExtractor.properties")); + + return grobidProperties.getProperty("grobid.server.url"); } - } - - private static String readRestUrl() throws IOException { - Properties grobidProperties = new Properties(); - grobidProperties.load(GrobidRESTParser.class - .getResourceAsStream("GrobidExtractor.properties")); - - return grobidProperties.getProperty("grobid.server.url"); - } - - protected static boolean canRun() { - Response response = null; - - try { - response = WebClient.create(readRestUrl() + GROBID_ISALIVE_PATH) - .accept(MediaType.TEXT_HTML).get(); - String resp = response.readEntity(String.class); - return resp != null && !resp.equals("") && resp.startsWith("<h4>"); - } catch (Exception e) { - e.printStackTrace(); - return false; + + protected static boolean canRun() { + Response response = null; + + try { + response = WebClient.create(readRestUrl() + GROBID_ISALIVE_PATH) + .accept(MediaType.TEXT_HTML).get(); + String resp = response.readEntity(String.class); + return resp != null && !resp.equals("") && resp.startsWith("<h4>"); + } catch (Exception e) { + e.printStackTrace(); + return false; + } } - } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
