You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by mb...@apache.org on 2008/01/23 17:15:27 UTC

svn commit: r614578 - in /incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl: Annotation_impl.java Concept_impl.java Feature_impl.java RegExAnnotator.java

Author: mbaessler
Date: Wed Jan 23 08:15:25 2008
New Revision: 614578

URL: http://svn.apache.org/viewvc?rev=614578&view=rev
Log:
UIMA-717

minor performance improvements

https://issues.apache.org/jira/browse/UIMA-717

Modified:
    incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Annotation_impl.java
    incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Concept_impl.java
    incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Feature_impl.java
    incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/RegExAnnotator.java

Modified: incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Annotation_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Annotation_impl.java?rev=614578&r1=614577&r2=614578&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Annotation_impl.java (original)
+++ incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Annotation_impl.java Wed Jan 23 08:15:25 2008
@@ -46,6 +46,8 @@
    private final String validationClass;
 
    private Validation validator;
+   
+   private boolean hasValidator;
 
    private ArrayList<Feature> features;
 
@@ -66,6 +68,7 @@
       this.features = new ArrayList<Feature>();
       this.validationClass = validationClass;
       this.validator = null;
+      this.hasValidator = false;
    }
 
    /*
@@ -119,7 +122,6 @@
     * @see org.apache.uima.annotator.regex.Annotation#getFeatures()
     */
    public Feature[] getFeatures() {
-
       return this.features.toArray(new Feature[0]);
    }
 
@@ -143,10 +145,7 @@
     * @see org.apache.uima.annotator.regex.Annotation#hasValidator()
     */
    public boolean hasValidator() {
-      if (this.validator != null) {
-         return true;
-      }
-      return false;
+      return this.hasValidator;
    }
 
    /**
@@ -193,6 +192,7 @@
             Object obj = validatorClass.newInstance();
             if (obj instanceof Validation) {
                this.validator = (Validation) obj;
+               this.hasValidator = true;
             } else {
                throw new RegexAnnotatorConfigException(
                      "regex_annotator_error_custom_validator_wrong_interface",

Modified: incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Concept_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Concept_impl.java?rev=614578&r1=614577&r2=614578&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Concept_impl.java (original)
+++ incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Concept_impl.java Wed Jan 23 08:15:25 2008
@@ -38,12 +38,16 @@
 public class Concept_impl implements Concept {
 
    private ArrayList<Annotation> annotations;
+   
+   private Annotation[] annotArray;
 
    private String name;
 
    private ArrayList<Rule> rules;
 
    private boolean processAllRules;
+   
+   private Rule[] ruleList;
 
    /**
     * @param name
@@ -53,6 +57,8 @@
       this.processAllRules = processAllRules;
       this.annotations = new ArrayList<Annotation>();
       this.rules = new ArrayList<Rule>();
+      this.ruleList = null;
+      this.annotArray = null;
    }
 
    /*
@@ -62,6 +68,7 @@
     */
    public void addAnnotation(Annotation aAnnotation) {
       this.annotations.add(aAnnotation);
+      this.annotArray = this.annotations.toArray(new Annotation[0]);
    }
 
    /*
@@ -70,7 +77,7 @@
     * @see org.apache.uima.annotator.regex.Rule#getInstructions()
     */
    public Annotation[] getAnnotations() {
-      return this.annotations.toArray(new Annotation[0]);
+      return this.annotArray;
    }
 
    /*
@@ -80,6 +87,11 @@
     */
    public void addRule(Rule aRule) {
       this.rules.add(aRule);
+      
+      //create ruleList array
+      this.ruleList = this.rules.toArray(new Rule[0]);
+      // sort rules array by confidence
+      Arrays.sort(this.ruleList, new RuleComparator());
    }
 
    /*
@@ -97,11 +109,7 @@
     * @see org.apache.uima.annotator.regex.Concept#getRules()
     */
    public Rule[] getRules() {
-      // get rules array
-      Rule[] ruleList = this.rules.toArray(new Rule[0]);
-      // sort rules array by confidence
-      Arrays.sort(ruleList, new RuleComparator());
-      return ruleList;
+      return this.ruleList;
    }
 
    /*
@@ -120,9 +128,8 @@
    public void typeInit(TypeSystem ts) throws ResourceInitializationException {
 
       // initialize all rules for this concept
-      Rule[] ruleList = getRules();
-      for (int i = 0; i < ruleList.length; i++) {
-         ((Rule_impl) ruleList[i]).typeInit(ts);
+      for (int i = 0; i < this.ruleList.length; i++) {
+         ((Rule_impl) this.ruleList[i]).typeInit(ts);
       }
 
       // initialize all annotations for this concept
@@ -141,13 +148,12 @@
     */
    public void initialize(Logger logger) throws RegexAnnotatorConfigException {
 
-      // get a list of rules and annotations
-      Rule[] ruleList = this.getRules();
+      // get a list of annotations
       Annotation[] annots = getAnnotations();
 
       // initialize all rules for this concept
-      for (int i = 0; i < ruleList.length; i++) {
-         ((Rule_impl) ruleList[i]).initialize();
+      for (int i = 0; i < this.ruleList.length; i++) {
+         ((Rule_impl) this.ruleList[i]).initialize();
       }
 
       // initialize all annotations for this concept
@@ -157,9 +163,9 @@
 
       // check duplicate rule IDs within the same concept
       // store ruleIDs for one concept
-      HashSet<String> ruleIds = new HashSet<String>(ruleList.length);
-      for (int x = 0; x < ruleList.length; x++) {
-         String ruleID = ruleList[x].getId();
+      HashSet<String> ruleIds = new HashSet<String>(this.ruleList.length);
+      for (int x = 0; x < this.ruleList.length; x++) {
+         String ruleID = this.ruleList[x].getId();
          // if no ruleID was specified, skip rule
          if (ruleID == null) {
             continue;
@@ -248,12 +254,11 @@
       }
       buffer.append("\nProcessAllConceptRules: " + this.processAllRules + "\n");
       
-      Rule[] ruleList = getRules();
-      if (ruleList.length > 0) {
+      if (this.ruleList.length > 0) {
          buffer.append("\nConcept rules: \n");
       }
-      for (int i = 0; i < ruleList.length; i++) {
-         buffer.append(ruleList[i].toString());
+      for (int i = 0; i < this.ruleList.length; i++) {
+         buffer.append(this.ruleList[i].toString());
       }
 
       Annotation[] annots = getAnnotations();

Modified: incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Feature_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Feature_impl.java?rev=614578&r1=614577&r2=614578&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Feature_impl.java (original)
+++ incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Feature_impl.java Wed Jan 23 08:15:25 2008
@@ -34,6 +34,8 @@
 
    private final int normalizationType;
 
+   private final boolean hasNormalizer;
+
    private final String name;
 
    private final String value;
@@ -53,6 +55,12 @@
       this.normalizationType = normalizationType;
       this.implClass = implClass;
       this.normalizer = null;
+
+      if (this.normalizationType > 0) {
+         this.hasNormalizer = true;
+      } else {
+         this.hasNormalizer = false;
+      }
    }
 
    /*
@@ -91,20 +99,24 @@
       return this.feature;
    }
 
-   /* (non-Javadoc)
-    * @see org.apache.uima.annotator.regex.Feature#normalize(java.lang.String, java.lang.String)
+   /*
+    * (non-Javadoc)
+    * 
+    * @see org.apache.uima.annotator.regex.Feature#normalize(java.lang.String,
+    *      java.lang.String)
     */
    public String normalize(String input, String ruleId) throws Exception {
-      // check normalizer type
-      if (this.normalizationType == Feature.CUSTOM_NORMALIZATION) {
-         return this.normalizer.normalize(input, ruleId);
-      } else if (this.normalizationType == Feature.TO_LOWER_NORMALIZATION) {
-         return input.toLowerCase();
-      } else if (this.normalizationType == Feature.TO_UPPER_NORMALIZATION) {
-         return input.toUpperCase();
-      } else {
-         return input;
+      if (this.hasNormalizer) {
+         // check normalizer type
+         if (this.normalizationType == Feature.CUSTOM_NORMALIZATION) {
+            return this.normalizer.normalize(input, ruleId);
+         } else if (this.normalizationType == Feature.TO_LOWER_NORMALIZATION) {
+            return input.toLowerCase();
+         } else if (this.normalizationType == Feature.TO_UPPER_NORMALIZATION) {
+            return input.toUpperCase();
+         }
       }
+      return input;
    }
 
    /**
@@ -186,16 +198,17 @@
       }
       buffer.append("\n  Value: ");
       buffer.append(this.value);
-      if(this.normalizationType > 0) {
+      if (this.normalizationType > 0) {
          if (this.normalizationType == Feature.TO_LOWER_NORMALIZATION) {
             buffer.append("\n  Normalization: ToLowerCase");
          } else if (this.normalizationType == Feature.TO_UPPER_NORMALIZATION) {
             buffer.append("\n  Normalization: ToUpperCase");
-         } if (this.normalizationType == Feature.CUSTOM_NORMALIZATION) {
+         }
+         if (this.normalizationType == Feature.CUSTOM_NORMALIZATION) {
             buffer.append("\n  Normalization: " + this.implClass);
          }
       }
-             
+
       buffer.append("\n");
 
       return buffer.toString();

Modified: incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/RegExAnnotator.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/RegExAnnotator.java?rev=614578&r1=614577&r2=614578&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/RegExAnnotator.java (original)
+++ incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/RegExAnnotator.java Wed Jan 23 08:15:25 2008
@@ -620,7 +620,7 @@
             continue;
          }
 
-         // set default validation value to true, of by default all annotations
+         // set default validation value to true, by default all annotations
          // are created
          boolean validation = true;