public void initialize()

in RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/Concept_impl.java [149:241]


   public void initialize(Logger logger) throws RegexAnnotatorConfigException {

      // get a list of annotations
      Annotation[] annots = getAnnotations();

      // initialize all rules for this concept
      for (int i = 0; i < this.ruleList.length; i++) {
         ((Rule_impl) this.ruleList[i]).initialize();
      }

      // initialize all annotations for this concept
      for (int i = 0; i < annots.length; i++) {
         ((Annotation_impl) annots[i]).initialize();
      }

      // check duplicate rule IDs within the same concept
      // store ruleIDs for one concept
      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;
         }
         // check if ruleID already exist for this concept
         if (ruleIds.contains(ruleID)) {
            logger.logrb(Level.WARNING, "RegExAnnotator", "initialize",
                  RegExAnnotator.MESSAGE_DIGEST,
                  "regex_annotator_warning_duplicate_rule_id", new Object[] {
                        ruleID, this.name });
         } else {
            // ruleID does not exist for this concept, add it to the ruleID
            // list
            ruleIds.add(ruleID);
         }
      }

      // check if annotation IDs are available in case of reference type
      // features and
      // check if they are unique within the concept
      HashSet<String> referenceIds = new HashSet<String>();
      HashSet<String> annotationIds = new HashSet<String>();
      for (int a = 0; a < annots.length; a++) {
         String annotID = annots[a].getId();
         // check annotation ID if available
         if (annotID != null) {
            // if annotation ID already exists for the current concept
            // throw an exception, annotation IDs must be unique for a
            // concept
            if (annotationIds.contains(annotID)) {
               throw new RegexAnnotatorConfigException(
                     "regex_annotator_error_duplicate_annotation_id",
                     new Object[] { annotID, this.name });
            } else {
               annotationIds.add(annotID);
            }
         }
         Feature[] features = annots[a].getFeatures();
         for (int f = 0; f < features.length; f++) {
            // check if the feature is a reference feature
            if (features[f].getType() == Feature.REFERENCE_FEATURE) {
               // add the annotation ID to the referenceIDs list to check
               // if this annotation ID is available and unique for the
               // concept
               referenceIds.add(features[f].getValue());

               // check annotation ID for the current annotation. Annotations
               // that have a reference type feature must also have a valid
               // annotation ID
               if (annotID == null) {
                  throw new RegexAnnotatorConfigException(
                        "regex_annotator_error_annotation_id_not_available",
                        new Object[] { this.name });
               }
            }
         }
      }

      // check if all referred annotation IDs are available
      Iterator<String> refIterator = referenceIds.iterator();
      while (refIterator.hasNext()) {
         String refID = refIterator.next();

         // check if refID is available in the anntoationIDs list
         // if it is not available, throw an exception
         if (!annotationIds.contains(refID)) {
            throw new RegexAnnotatorConfigException(
                  "regex_annotator_error_referred_annotation_id_not_available",
                  new Object[] { refID, this.name });
         }
      }

   }