package readers;

import java.io.IOException;
import java.util.List;

import org.apache.uima.UimaContext;
import org.apache.uima.collection.CollectionException;
import org.apache.uima.fit.component.JCasCollectionReader_ImplBase;
import org.apache.uima.fit.descriptor.ConfigurationParameter;
import org.apache.uima.fit.descriptor.ExternalResource;
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.util.Progress;
import org.apache.uima.util.ProgressImpl;

import resources.AnnotatedCollection;
import resources.Candidate;


public class CandidateReader extends JCasCollectionReader_ImplBase {
	

	/*public static final String PARAM_SELECTOR = "SELECTOR";
	@ConfigurationParameter(name = PARAM_SELECTOR,
			description = "css element to analyse",
			mandatory = false, defaultValue = "body")
	private String cssSelector;
	*/
	
	public static final String CANDIDATE_KEY = "candidateKey";
	 @ExternalResource(key = CANDIDATE_KEY)
	 private AnnotatedCollection collection;
	 
	 public static final String PARAM_LANGUAGE = "LANGUAGE";
		@ConfigurationParameter(name = PARAM_LANGUAGE,
				description = "default language for the text",
				mandatory = false, defaultValue = "en")
		private String language;
	
	public static final String PARAM_DIRECTORY = "key_directory";
	@ConfigurationParameter(
	name = PARAM_DIRECTORY,
	description = "The directory containing the key files",
	mandatory = true)
	private String directory_dir;
	
	int i = 0;
	int size = 0;

	@Override
	public void initialize(UimaContext context)
			throws ResourceInitializationException {
		super.initialize(context);
		size = collection.getDocuments().size();
	}

	public Progress[] getProgress() {
		return new Progress[] { new ProgressImpl(i, size, Progress.ENTITIES) };
	}

	public boolean hasNext() throws IOException, CollectionException {
		return i < size;
	}

	@Override
	public void getNext(JCas jcas) throws IOException, CollectionException {
		jcas.setDocumentLanguage(language);
		
		List<Candidate> document = collection.getDocuments().get(i);
		
		for(resources.Candidate c : document)
		{
			types.Candidate candidate = new types.Candidate(jcas);
			candidate.setName(c.getName());
			candidate.setEffective_full_form(c.getEffectiveFullForm());
			candidate.setTf(c.getTerm_frequency());
			candidate.setDf(c.getDocument_frequency());
			candidate.setIdf(c.getInverse_document_frequency());
			candidate.setFirst_occ(c.getFirst_occurrence());
			candidate.setLast_occ(c.getLast_occurrence());
			
			candidate.addToIndexes();
		}
		
		i++;
	}

}
@@ -11,16 +11,74 @@
 aders;%0A%0A
+import java.io.BufferedReader;%0Aimport java.io.FileReader;%0A
 import j
@@ -1954,16 +1954,601 @@
 size;%0A%09%7D
+%0A%09%0A%09public int computeClass(resources.Candidate candidate, String documentName)%0A%09%7B%0A%09%09try%0A%09%09%7B%0A%09%09%09BufferedReader readerFile = new BufferedReader(new FileReader(directory_dir+documentName.replaceAll(%22.txt%22, %22.keys%22)));%0A%09%09%09String line;%0A%09%09%09 while((line = readerFile.readLine()) != null)%7B%0A%09%09%09%09 String%5B%5D splits = line.split(%22%5Ct%22);%0A%09%09%09%09 %0A%09%09%09%09 System.out.println(candidate.getFullForms());%0A%09%09%09%09 if(candidate.getFullForms().containsKey(splits%5B0%5D))%0A%09%09%09%09 %7B%0A%09%09%09%09%09 return 1;%0A%09%09%09%09 %7D%0A%09%09%09 %7D%0A%09%09%7D%0A%09%09catch (Exception e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09%0A%09%09return 0;%0A%09%7D
 %0A%0A%09@Over
@@ -2730,16 +2730,67 @@
 get(i);%0A
+%09%09String documentName = collection.getFilename(i);%0A
 %09%09%0A%09%09for
@@ -3178,24 +3178,24 @@
 urrence());%0A
-
 %09%09%09candidate
@@ -3232,16 +3232,165 @@
 nce());%0A
+%09%09%09System.out.println(c.getName() + %22 : %22 + Integer.toString(computeClass(c, documentName)));%0A%09%09%09candidate.setClass_(computeClass(c, documentName));%0A
 %09%09%09%0A%09%09%09c

Add class in the Candidate Reader