You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2017/05/16 12:15:53 UTC
[tika] 02/02: TIKA-2360 -- require users to turn on SentimentParser;
remove glob detection for .sent; skip unit tests if network call fails.
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 c020e48a263e2b2a29543ccc4a1946be8002c7f3
Author: tballison <ta...@mitre.org>
AuthorDate: Tue May 16 08:15:22 2017 -0400
TIKA-2360 -- require users to turn on SentimentParser; remove glob detection for .sent; skip unit tests if network call fails.
---
.../services/org.apache.tika.parser.Parser | 1 -
.../tika/org/apache/tika/mime/custom-mimetypes.xml | 17 ---------
.../sentiment/analysis/SentimentParserTest.java | 42 +++++++++++++++-------
3 files changed, 29 insertions(+), 31 deletions(-)
diff --git a/tika-parsers/src/main/resources/META-INF/services/org.apache.tika.parser.Parser b/tika-parsers/src/main/resources/META-INF/services/org.apache.tika.parser.Parser
index a8592c3..aa8725e 100644
--- a/tika-parsers/src/main/resources/META-INF/services/org.apache.tika.parser.Parser
+++ b/tika-parsers/src/main/resources/META-INF/services/org.apache.tika.parser.Parser
@@ -80,4 +80,3 @@ org.apache.tika.parser.external.CompositeExternalParser
org.apache.tika.parser.journal.JournalParser
org.apache.tika.parser.image.ICNSParser
org.apache.tika.parser.dbf.DBFParser
-org.apache.tika.parser.sentiment.analysis.SentimentParser
diff --git a/tika-parsers/src/main/tika/org/apache/tika/mime/custom-mimetypes.xml b/tika-parsers/src/main/tika/org/apache/tika/mime/custom-mimetypes.xml
deleted file mode 100644
index 2c87837..0000000
--- a/tika-parsers/src/main/tika/org/apache/tika/mime/custom-mimetypes.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
- license agreements. See the NOTICE file distributed with this work for additional
- information regarding copyright ownership. 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 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. See the License for the specific
- language governing permissions and limitations under the License. -->
-<mime-info>
- <mime-type type="application/sentiment">
- <glob pattern="*.sent" />
- <sub-class-of type="text/plain" />
- </mime-type>
-</mime-info>
\ No newline at end of file
diff --git a/tika-parsers/src/test/java/org/apache/tika/parser/sentiment/analysis/SentimentParserTest.java b/tika-parsers/src/test/java/org/apache/tika/parser/sentiment/analysis/SentimentParserTest.java
index 3a98a87..3540a0b 100644
--- a/tika-parsers/src/test/java/org/apache/tika/parser/sentiment/analysis/SentimentParserTest.java
+++ b/tika-parsers/src/test/java/org/apache/tika/parser/sentiment/analysis/SentimentParserTest.java
@@ -18,10 +18,15 @@ package org.apache.tika.parser.sentiment.analysis;
import org.apache.tika.Tika;
import org.apache.tika.config.TikaConfig;
+import org.apache.tika.exception.TikaConfigException;
+import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.junit.Test;
+import org.xml.sax.SAXException;
import java.io.ByteArrayInputStream;
+import java.io.IOError;
+import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
@@ -35,12 +40,11 @@ public class SentimentParserTest {
@Test
public void endToEndTest() throws Exception {
- Tika tika;
- try (InputStream confStream = getClass().getResourceAsStream("tika-config-sentiment-opennlp.xml")) {
- assert confStream != null;
- TikaConfig config = new TikaConfig(confStream);
- tika = new Tika(config);
+ Tika tika = getTika("tika-config-sentiment-opennlp.xml");
+ if (tika == null) {
+ return;
}
+
String text = "What a wonderful thought it is that" +
" some of the best days of our lives haven't happened yet.";
ByteArrayInputStream stream = new ByteArrayInputStream(text.getBytes(Charset.defaultCharset()));
@@ -54,13 +58,10 @@ public class SentimentParserTest {
@Test
public void testCategorical() throws Exception{
- Tika tika;
- try (InputStream confStream = getClass().getResourceAsStream("tika-config-sentiment-opennlp-cat.xml")) {
- assert confStream != null;
- TikaConfig config = new TikaConfig(confStream);
- tika = new Tika(config);
- }
-
+ Tika tika = getTika("tika-config-sentiment-opennlp-cat.xml");
+ if (tika == null) {
+ return;
+ }
String text = "Whatever, I need some cooling off time!";
ByteArrayInputStream stream = new ByteArrayInputStream(text.getBytes(Charset.defaultCharset()));
Metadata md = new Metadata();
@@ -68,6 +69,21 @@ public class SentimentParserTest {
String sentiment = md.get("Sentiment");
assertNotNull(sentiment);
assertEquals(sentiment, "angry");
- }
+ }
+
+ private Tika getTika(String configXml) throws TikaException, SAXException, IOException {
+
+ try (InputStream confStream = getClass().getResourceAsStream("tika-config-sentiment-opennlp.xml")) {
+ assert confStream != null;
+ TikaConfig config = new TikaConfig(confStream);
+ return new Tika(config);
+ } catch (TikaConfigException e) {
+ //if can't connect to pull sentiment model...ignore test
+ if (e.getCause() != null && e.getCause() instanceof java.net.ConnectException) {
+ return null;
+ }
+ throw e;
+ }
+ }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@tika.apache.org" <co...@tika.apache.org>.