Revision: 18308
          http://sourceforge.net/p/gate/code/18308
Author:   markagreenwood
Date:     2014-09-11 09:27:18 +0000 (Thu, 11 Sep 2014)
Log Message:
-----------
added code to handle 4 digit years; the parser doesn't touch these as it can't 
know if they are a date or not without context, but as we know the text is 
under a date annotation we can added the appropriate features in the PR by hand

Modified Paths:
--------------
    
gate/trunk/plugins/Tagger_DateNormalizer/src/gate/creole/dates/DateAnnotationNormalizer.java

Modified: 
gate/trunk/plugins/Tagger_DateNormalizer/src/gate/creole/dates/DateAnnotationNormalizer.java
===================================================================
--- 
gate/trunk/plugins/Tagger_DateNormalizer/src/gate/creole/dates/DateAnnotationNormalizer.java
        2014-09-11 01:20:00 UTC (rev 18307)
+++ 
gate/trunk/plugins/Tagger_DateNormalizer/src/gate/creole/dates/DateAnnotationNormalizer.java
        2014-09-11 09:27:18 UTC (rev 18308)
@@ -23,8 +23,8 @@
 import gate.creole.metadata.RunTime;
 
 import java.text.DateFormat;
+import java.util.Calendar;
 import java.util.Date;
-import java.util.regex.Pattern;
 
 import mark.util.DateParser;
 import mark.util.ParsePositionEx;
@@ -56,6 +56,7 @@
     return wholeMatchOnly;
   }
       
+  @SuppressWarnings("deprecation")
   @Override
   protected void annotate(Date documentDate, DateParser dp, DateFormat df) 
throws ExecutionException {    
     AnnotationSet dates = 
document.getAnnotations(getInputASName()).get(getAnnotationName());
@@ -84,8 +85,28 @@
         
         if(d == null) {
           //if the text didn't parse skip on to the next character and try 
again
-          //start++;
-          continue;
+          if (text.matches("[0-9]{4}")) {
+            d = new Date(Integer.parseInt(text)-1900,0,1);
+            
+            pp.setIndex(4);
+            pp.getFeatures().put("inferred", DateParser.MONTH | 
DateParser.DAY);
+            
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(documentDate != null ? documentDate : new Date());
+            
+            Calendar parsed = Calendar.getInstance();
+            cal.setTime(d);
+            
+            String relative = "present";
+            if (parsed.before(cal)) relative = "past";
+            if (parsed.after(cal)) relative = "future";
+   
+            pp.getFeatures().put("relative", relative);          
+            
+          }
+          else {
+            continue;            
+          }
         }
         
         if (wholeMatchOnly && pp.getIndex() != text.length()) {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
GATE-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to