summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorreger <reger18@arcor.de>2016-10-06 23:37:12 +0200
committerreger <reger18@arcor.de>2016-10-06 23:37:12 +0200
commitb752bcfecba1b541f69d3ecb1129c66a2213e2a4 (patch)
tree45491679fa74ab07313f68dd3362b563ddfc08d1
parentb017e9742122c23646531934bcfd2b5b07e00da0 (diff)
adjust date in text detection to ignore some program version strings
like "3.1.2.0102" see http://mantis.tokeek.de/view.php?id=650 + expand test case
-rw-r--r--source/net/yacy/document/DateDetection.java2
-rw-r--r--test/java/net/yacy/document/DateDetectionTest.java22
2 files changed, 23 insertions, 1 deletions
diff --git a/source/net/yacy/document/DateDetection.java b/source/net/yacy/document/DateDetection.java
index 781101665..c5ecb0a1c 100644
--- a/source/net/yacy/document/DateDetection.java
+++ b/source/net/yacy/document/DateDetection.java
@@ -127,7 +127,7 @@ public class DateDetection {
private final static Date TODAY = new Date();
private final static int CURRENT_YEAR = Integer.parseInt(CONFORM.format(TODAY).substring(0, 4)); // we need that to parse dates without given years, see the ShortStyle class
- private final static String BODNCG = "(?:\\b|^)"; // begin of date non-capturing group
+ private final static String BODNCG = "(?:\\s|^)"; // begin of date non-capturing group
private final static String EODNCG = "(?:[).:;! ]|$)"; // end of date non-capturing group
private final static String SEPARATORNCG = "(?:/|-| - |\\.\\s|,\\s|\\.|,|\\s)"; // separator non-capturing group
private final static String DAYCAPTURE = "(\\d{1,2})";
diff --git a/test/java/net/yacy/document/DateDetectionTest.java b/test/java/net/yacy/document/DateDetectionTest.java
index cedcea6de..eba322d7a 100644
--- a/test/java/net/yacy/document/DateDetectionTest.java
+++ b/test/java/net/yacy/document/DateDetectionTest.java
@@ -28,6 +28,9 @@ public class DateDetectionTest {
testtext.add("1.1.2016");
testtext.add("1. Januar 2016");
testtext.add("2016, January 1.");
+
+ testtext.add("beginning text 1.1.2016");
+ testtext.add("line break\n1.1.2016");
for (String text : testtext) {
Date d = DateDetection.parseLine(text, 0);
@@ -82,4 +85,23 @@ public class DateDetectionTest {
}
}
+ /**
+ * Negative test of parseLine method, of class DateDetection
+ * with cases that represent NOT a date
+ */
+ @Test
+ public void testParseLineNoDate() {
+
+ // test input representations
+ Set<String> testtext = new LinkedHashSet();
+ testtext.add("3.1.2.0102"); // example of a program version string
+ // testtext.add("3.1.20.0102"); // date end-capture not working (on modification conflict with YMD parser)
+ testtext.add("v3.1.21");
+ testtext.add("v3.1.22.");
+
+ for (String text : testtext) {
+ Date d = DateDetection.parseLine(text, 0);
+ assertNull("not a date: " + text, d);
+ }
+ }
}