You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2010/08/06 21:23:02 UTC

svn commit: r983099 - in /uima/uimaj/trunk/uimaj-examples/src/main/java/org/apache/uima: examples/cas/PersonTitleAnnotator.java tutorial/ex3/TutorialDateTime.java

Author: schor
Date: Fri Aug  6 19:23:02 2010
New Revision: 983099

URL: http://svn.apache.org/viewvc?rev=983099&view=rev
Log:
[UIMA-1852] add msg when no output is produced due to result spec language issues.

Modified:
    uima/uimaj/trunk/uimaj-examples/src/main/java/org/apache/uima/examples/cas/PersonTitleAnnotator.java
    uima/uimaj/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex3/TutorialDateTime.java

Modified: uima/uimaj/trunk/uimaj-examples/src/main/java/org/apache/uima/examples/cas/PersonTitleAnnotator.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-examples/src/main/java/org/apache/uima/examples/cas/PersonTitleAnnotator.java?rev=983099&r1=983098&r2=983099&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-examples/src/main/java/org/apache/uima/examples/cas/PersonTitleAnnotator.java (original)
+++ uima/uimaj/trunk/uimaj-examples/src/main/java/org/apache/uima/examples/cas/PersonTitleAnnotator.java Fri Aug  6 19:23:02 2010
@@ -80,6 +80,13 @@ public class PersonTitleAnnotator extend
    * The list of government titles, read from the GovernmentTitles configuration parameter.
    */
   private String[] mGovernmentTitles;
+  
+  /**
+   * Show warning message just once
+   */
+  private boolean warningMsgShown = false;
+
+  private Logger logger;
 
   /**
    * Performs initialization logic. This implementation just reads values for the configuration
@@ -96,7 +103,7 @@ public class PersonTitleAnnotator extend
     mGovernmentTitles = (String[]) getContext().getConfigParameterValue("GovernmentTitles");
 
     // write log messages
-    Logger logger = getContext().getLogger();
+    logger = getContext().getLogger();
     logger.log(Level.CONFIG, "PersonTitleAnnotator initialized");
     logger.log(Level.CONFIG, "CivilianTitles = " + Arrays.asList(mCivilianTitles));
     logger.log(Level.CONFIG, "MilitaryTitles = " + Arrays.asList(mMilitaryTitles));
@@ -149,6 +156,16 @@ public class PersonTitleAnnotator extend
       // If the ResultSpec doesn't include the PersonTitle type, we have
       // nothing to do.
       if (!getResultSpecification().containsType("example.PersonTitle",aCAS.getDocumentLanguage())) {
+        if (!warningMsgShown) {
+          String m = String.format(
+              "No output is being produced by the PersonTitleAnnotator because the Result Specification did not contain" +
+              " a request for the type example.PersonTitle with the language '%s'%n" +
+              "  (Note: this message will only be shown once.)%n", 
+              aCAS.getDocumentLanguage());               
+          System.err.println(m);
+          logger.log(Level.WARNING, m);
+          warningMsgShown = true;
+        }
         return;
       }
 
@@ -261,5 +278,4 @@ public class PersonTitleAnnotator extend
     // Add the annotation to the index.
     aCAS.getIndexRepository().addFS(title);
   }
-
 }

Modified: uima/uimaj/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex3/TutorialDateTime.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex3/TutorialDateTime.java?rev=983099&r1=983098&r2=983099&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex3/TutorialDateTime.java (original)
+++ uima/uimaj/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex3/TutorialDateTime.java Fri Aug  6 19:23:02 2010
@@ -35,6 +35,7 @@ import org.apache.uima.jcas.tcas.Annotat
 import org.apache.uima.tutorial.DateAnnot;
 import org.apache.uima.tutorial.DateTimeAnnot;
 import org.apache.uima.tutorial.TimeAnnot;
+import org.apache.uima.util.Level;
 
 /**
  * Simple Date/Time annotator.
@@ -118,6 +119,8 @@ public class TutorialDateTime extends JC
   };
 
   static final String defaultYear = "2003";
+  
+  private static boolean warningMessageShown = false;
 
   // PROCESS
   /**
@@ -130,14 +133,31 @@ public class TutorialDateTime extends JC
 
     // Create Annotations
     ResultSpecification resultSpec = getResultSpecification();
-    if (resultSpec.containsType("org.apache.uima.tutorial.TimeAnnot",aJCas.getDocumentLanguage()))
+    boolean timeWanted = resultSpec.containsType("org.apache.uima.tutorial.TimeAnnot", aJCas.getDocumentLanguage());
+    boolean dateWanted = resultSpec.containsType("org.apache.uima.tutorial.DateAnnot", aJCas.getDocumentLanguage());
+
+    if (timeWanted)
       makeAnnotations(timeAnnotationMaker, hoursMinutesPattern, dfTimeShort);
-    if (resultSpec.containsType("org.apache.uima.tutorial.DateAnnot",aJCas.getDocumentLanguage()))
+    
+    if (dateWanted) {    
       makeAnnotations(dateAnnotationMaker, numericDatePattern, dfDateShort);
-    if (resultSpec.containsType("org.apache.uima.tutorial.DateAnnot",aJCas.getDocumentLanguage()))
       makeAnnotations(dateAnnotationMaker, mediumDatePattern, dfDateMedium);
-    if (resultSpec.containsType("org.apache.uima.tutorial.DateAnnot",aJCas.getDocumentLanguage()))
       makeAnnotations(dateAnnotationMaker, longDatePattern, dfDateLong);
+    }
+    
+    if (!timeWanted && !dateWanted && !warningMessageShown) {
+      String m = String.format(
+        "No output is being produced by the TutorialDateTime annotator because the Result Specification did not contain" +
+        " a request for the type%n" +
+        "  org.apache.uima.tutorial.TimeAnnot nor%n" +
+        "  org.apache.uima.tutorial.DateAnnot" +
+        " with the language '%s'%n" +
+              "  (Note: this message will only be shown once.)%n", 
+              aJCas.getDocumentLanguage());              
+      System.err.println(m);
+      getContext().getLogger().log(Level.WARNING, m);
+      warningMessageShown = true;
+    }
   }
 
   // HELPER METHODS