Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 import java.util.List;
 import java.util.Map;
Given a token, check if this token is inside any identified annotation if so check if the identifiled annotion is a known event. If yes, get the weight.

Chen Lin 2/28/2013
 public class IdentifiedAnnotationFeatureExtractor implements FeatureExtractor1 {
   private String name;
   private Map<Stringdouble[]> textDoublesMap;
   private double[] meanValues;
   public static Map<Stringdouble[]> parseTextDoublesMap(File fileCharset charsetthrows IOException {
     return Files.readLines(filecharsetnew StringToDoublesProcessor());
   static class StringToDoublesProcessor implements LineProcessor<Map<Stringdouble[]>> {
     private Logger logger = Logger.getLogger(this.getClass().getName());
     private Map<Stringdouble[]> result = new HashMap<Stringdouble[]>();
     private int length = -1;
     public Map<Stringdouble[]> getResult() {
       return this.;
     public boolean processLine(String linethrows IOException {
       String[] parts = line.trim().split(",");
       String key = parts[0];
       int partsOffset = 0;
       if (this. == -1) {
         this. = parts.length;
       } else if (parts.length != this.) {
         String message = "expected %d parts, found %d, skipping line '%s'";
         return true;
       double[] values = new double[parts.length - 1];
       for (int i = 0; i < values.length; ++i) {
         values[i] = Double.parseDouble(parts[i + 1 + partsOffset]);
       return true;
   public IdentifiedAnnotationFeatureExtractor(String nameMap<Stringdouble[]> textDoublesMap) {
     this. = name;
     this. = textDoublesMap;
     int nMapEntries = this..size();
    if (nMapEntries == 0) {
      throw new IllegalArgumentException("textDoublesMap cannot be empty");
    int nValues = textDoublesMap.entrySet().iterator().next().getValue().length;
    this. = new double[nValues];
    for (double[] values : textDoublesMap.values()) {
      for (int i = 0; i < values.length; ++i) {
        this.[i] += values[i];
    for (int i = 0; i < this..length; ++i) {
    	this.[i] /= nMapEntries;
  public List<Feature> extract(JCas viewAnnotation annotationthrows CleartkExtractorException {
	  BaseToken targetTokenAnnotation = (BaseToken)annotation;
	  Collection<IdentifiedAnnotationidannoList = coveringMap.get(targetTokenAnnotation);
	  ArrayList<Feature> features = new ArrayList<Feature>();
	  if (idannoList != null && !idannoList.isEmpty())
		  features.add(new Feature("TokenInside","A_IdentifiedAnnotation"));
		  for (IdentifiedAnnotation ida : idannoList){
			  //check if the ida is a know event:
			  double[] values = this..get(ida.getCoveredText().toLowerCase());
			  if(values != null){
				  features.add(new Feature(this."is_A_KnownEvent"));
	  return features;
New to GrepCode? Check out our FAQ X