public Tense calculateTense(String clause) {
   final Tree posTree = getPosTree(clause);
   final Tree word = posTree.getLeaves().get(0);
   final String pos = word.parent(posTree).label().value().toLowerCase();
   if (pos.equals("md")) {
     return Tense.FUTURE;
   }
   if (pos.equals("vbd") || pos.equals("vbn")) {
     return Tense.PAST;
   }
   return Tense.PRESENT;
 }
Esempio n. 2
0
  private void collectFreqs(Tree tag, Model model, Type type, double[] freqs) {
    Statistics unsmoothed_statistics = model.getStatistics();
    List<Tree> leaves = new LinkedList<Tree>();
    tag.getLeaves(leaves);

    Arrays.fill(freqs, 0.0);
    for (Tree leaf : leaves) {
      int tag_index = model.getTagTable().toIndex(leaf.getName(), false);
      for (int index = 0; index < freqs.length; index++) {
        freqs[index] += getFreq(unsmoothed_statistics, tag_index, index, type);
      }
    }
  }
  public static ArrayList<ArrayList<TaggedWord>> getPhrases(Tree parse, int phraseSizeLimit) {
    ArrayList<ArrayList<TaggedWord>> newList = new ArrayList<ArrayList<TaggedWord>>();
    List<Tree> leaves = parse.getLeaves();

    if (leaves.size() <= phraseSizeLimit) {
      // ArrayList<TaggedWord> phraseElements = PreprocessPhrase(parse.taggedYield());
      ArrayList<TaggedWord> phraseElements = Preprocess(parse.taggedYield());
      if (phraseElements.size() > 0) newList.add(phraseElements);
    } else {
      Tree[] childrenNodes = parse.children();
      for (int i = 0; i < childrenNodes.length; i++) {
        Tree currentParse = childrenNodes[i];
        newList.addAll(getPhrases(currentParse, phraseSizeLimit));
      }
    }
    return newList;
  }