private List<String> getFeatureValues(Instance<String> instance) {
   List<String> values = new ArrayList<String>();
   for (Feature feature : instance.getFeatures()) {
     Object value = feature == null ? null : feature.getValue();
     values.add(value == null ? null : value.toString());
   }
   return values;
 }
示例#2
0
  public boolean encodes(Feature feature) {
    if (!(feature.getValue() instanceof Counts)) return false;

    Counts counts = (Counts) feature.getValue();

    if (identifier == null) return true;

    if (identifier.equals(counts.getIdentifier())) return true;

    return false;
  }
示例#3
0
  public List<NameNumber> encode(Feature feature) {
    List<NameNumber> fves = new ArrayList<NameNumber>();
    Counts frequencies = (Counts) feature.getValue();

    String prefix = frequencies.getFeatureName();
    for (Object key : frequencies.getValues()) {
      String name = Feature.createName(prefix, key.toString());
      NameNumber fve = new NameNumber(name, frequencies.getCount(key));
      fves.add(fve);
    }

    normalizer.normalize(fves);

    return fves;
  }
  @Override
  public List<Feature> apply(Feature feature) {

    if (i == 0) {
      BufferedReader br;
      try {
        NERReader reader = new NERReader();
        br = (BufferedReader) reader.getReader("topicCluster50.txt");
        String input;
        while ((input = br.readLine()) != null) {
          String[] sep = input.split("\\t");
          topicClass1.put(sep[0], sep[1]);
        }
        br.close();
      } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      // System.out.println("Size:"+simWord1.size());

      i++;
    }

    Object featureValue = feature.getValue();

    if (featureValue == null) {
      return Collections.singletonList(new Feature("TopicClass50", "NA"));
    }
    String value = featureValue.toString();
    if (value == null || value.length() == 0) {
      return Collections.singletonList(new Feature("TopicClass50", "NA"));
    }

    String output;
    output = topicClass1.get(value);
    // System.out.println("Size:"+i);
    if (output != null) {
      return Collections.singletonList(new Feature("TopicClass50", output));
    }
    return Collections.singletonList(new Feature("TopicClass50", "NA"));
  }