package annotators;

import java.util.ArrayList;
import java.util.List;

import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
import org.apache.uima.fit.descriptor.ExternalResource;
import org.apache.uima.jcas.JCas;

import resources.AnnotatedCollection;
import resources.Candidate;
import resources.FeaturesList;
import resources.FeaturesMap;

public class FeaturesAnnotator extends JCasAnnotator_ImplBase {
  public final static String CANDIDATE_KEY = "candidateKey";
  @ExternalResource(key = CANDIDATE_KEY)
  private AnnotatedCollection collection;
  
  public final static String FEATURES_KEY = "featuresKey";
  @ExternalResource(key = FEATURES_KEY)
  private FeaturesList featuresList_;

  @Override
  public void process(JCas jCas) throws AnalysisEngineProcessException {
    for (List<Candidate> candidates : collection.getDocuments()) {
      ArrayList<FeaturesMap> lf = new ArrayList<FeaturesMap>();
      for (Candidate c : candidates) {
        int tf = c.getTerm_frequency(); // 1
        int df = c.getDocument_frequency(); // 2
        double idf = c.getInverse_document_frequency(); // 3
        double tfidf = tf * idf;
        int firstOccurrence = c.getFirst_occurrence(); // 4
        int lastOccurrence = c.getLast_occurrence(); // 5
        int spread = lastOccurrence - firstOccurrence; // 6
        lf.add(new FeaturesMap(tf, df, idf, tfidf, firstOccurrence, lastOccurrence, spread));
        //System.out.println(c.getName() + " - Tf-idf : " + tfidf);
      }
      featuresList_.getFeaturesList().add(lf);
      //System.out.println(lf);
    }

  }

}

@@ -18,60 +18,8 @@
 s;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 impo
@@ -173,48 +173,27 @@
 ima.
-fit.descriptor.ExternalResource;
+jcas.JCas;%0A
 %0Aimport 
 org.
@@ -180,32 +180,39 @@
 s.JCas;%0A%0Aimport 
+static 
 org.apache.uima.
@@ -215,65 +215,42 @@
 ima.
-jcas.JCas;%0A%0Aimport resources.AnnotatedCollection;
+fit.util.JCasUtil.select;%0A
 %0Aimport 
 reso
@@ -245,23 +245,19 @@
 %0Aimport 
-resourc
+typ
 es.Candi
@@ -273,46 +273,11 @@
 ort 
-resources.FeaturesList;%0Aimport resourc
+typ
 es.F
@@ -283,19 +283,16 @@
 Features
-Map
 ;%0A%0Apubli
@@ -353,292 +353,8 @@
 se %7B
-%0A  public final static String CANDIDATE_KEY = %22candidateKey%22;%0A  @ExternalResource(key = CANDIDATE_KEY)%0A  private AnnotatedCollection collection;%0A  %0A  public final static String FEATURES_KEY = %22featuresKey%22;%0A  @ExternalResource(key = FEATURES_KEY)%0A  private FeaturesList featuresList_;
 %0A%0A  
@@ -440,22 +440,17 @@
 n %7B%0A
-  
+%0A%09
   for (
-List%3C
 Cand
@@ -458,200 +458,130 @@
 date
-%3E
  c
-andidates : collection.getDocuments()) %7B%0A      ArrayList%3CFeaturesMap%3E lf = new ArrayList%3CFeaturesMap%3E();%0A      for (Candidate c : candidates) %7B%0A        int tf = c.getTerm_frequency(
+ : select(jCas, Candidate.class)) %0A%09  %7B %0A%09%09Features features = new Features(jCas);%0A%09%09%0A%09%09features.setTf(c.getTf()
 ); // 1%0A
     
@@ -580,118 +580,84 @@
 / 1%0A
+%09
     
-    int df = c.getDocument_frequency(); // 2%0A        double idf = c.getInverse_document_frequency(
+features.setDf(c.getDf()); // 2%0A%09    features.setIdf(c.getIdf()
 ); // 3%0A
     
@@ -656,59 +656,94 @@
 / 3%0A
+%09
     
-    double tfidf = tf * idf
+features.setTfidf(features.getTf() * features.getIdf())
 ;%0A
+%09
     
-    int f
+features.setF
 irst
-O
+_o
 ccur
@@ -743,27 +743,25 @@
 t_occurrence
- = 
+(
 c.getFirst_o
@@ -766,24 +766,18 @@
 _occ
-urrence
 (
+)
 ); // 4%0A
     
@@ -776,25 +776,31 @@
 / 4%0A
+%09
     
-    int lastO
+features.setLast_o
 ccur
@@ -804,19 +804,17 @@
 currence
- = 
+(
 c.getLas
@@ -822,24 +822,18 @@
 _occ
-urrence
 (
+)
 ); // 5%0A
     
@@ -832,34 +832,50 @@
 / 5%0A
+%09
     
-    int spread = lastO
+features.setSpread(features.getLast_o
 ccur
@@ -883,17 +883,32 @@
 ence
+()
  - f
+eatures.getF
 irst
-O
+_o
 ccur
@@ -916,266 +916,120 @@
 ence
+())
 ; // 6%0A
+%09
     
+%0A%09
     
-lf.add(new FeaturesMap(tf, df, idf, tfidf, firstOccurrence, lastOccurrence, spread));%0A        //System.out.println(c.getName() + %22 - Tf-idf : %22 + tfidf);%0A      %7D%0A      featuresList_.getFeaturesList().add(lf);%0A      //System.out.println(lf);%0A  
+features.addToIndexes();%0A%09    //System.out.println(c.getName() + %22 - Tf-idf : %22 + tfidf);%0A%09
   %7D%0A
@@ -1033,11 +1033,13 @@
  %7D%0A%0A  %7D%0A
+  
 %0A%7D%0A

Use the jcas in the FeaturesAnnotator