예제 #1
0
  public FeatureVector classify(Object __example) {
    if (!(__example instanceof Word)) {
      String type = __example == null ? "null" : __example.getClass().getName();
      System.err.println(
          "Classifier 'WordTypeInformation(Word)' defined on line 71 of CommonFeatures.lbj received '"
              + type
              + "' as input.");
      new Exception().printStackTrace();
      System.exit(1);
    }

    if (__example == WordTypeInformation.exampleCache) return WordTypeInformation.cache;

    Word word = (Word) __example;
    FeatureVector __result = new FeatureVector();
    String __id;
    String __value;

    int i;
    Word w = word, last = word;
    for (i = 0; i <= 2 && last != null; ++i) {
      last = (Word) last.next;
    }
    for (i = 0; i > -2 && w.previous != null; --i) {
      w = (Word) w.previous;
    }
    for (; w != last; w = (Word) w.next, ++i) {
      boolean allCapitalized = true, allDigits = true, allNonLetters = true;
      for (int j = 0; j < w.form.length(); ++j) {
        allCapitalized &= Character.isUpperCase(w.form.charAt(j));
        allDigits &= Character.isDigit(w.form.charAt(j));
        allNonLetters &= !Character.isLetter(w.form.charAt(j));
      }
      __id = this.name + ("c" + i);
      __value = "" + (allCapitalized);
      __result.addFeature(
          new DiscreteFeature(
              this.containingPackage, __id, __value, valueIndexOf(__value), (short) 2));
      __id = this.name + ("d" + i);
      __value = "" + (allDigits);
      __result.addFeature(
          new DiscreteFeature(
              this.containingPackage, __id, __value, valueIndexOf(__value), (short) 2));
      __id = this.name + ("p" + i);
      __value = "" + (allNonLetters);
      __result.addFeature(
          new DiscreteFeature(
              this.containingPackage, __id, __value, valueIndexOf(__value), (short) 2));
    }

    WordTypeInformation.exampleCache = __example;
    WordTypeInformation.cache = __result;

    return __result;
  }
예제 #2
0
  public FeatureVector[] classify(Object[] examples) {
    for (int i = 0; i < examples.length; ++i)
      if (!(examples[i] instanceof Word)) {
        System.err.println(
            "Classifier 'WordTypeInformation(Word)' defined on line 71 of CommonFeatures.lbj received '"
                + examples[i].getClass().getName()
                + "' as input.");
        new Exception().printStackTrace();
        System.exit(1);
      }

    return super.classify(examples);
  }