Esempio n. 1
0
  public Sentence processSentence(String sentence) {
    if (!_is_inited) init();
    starttime = System.currentTimeMillis();

    Sentence sntc = null;
    try {
      if (verbosity > 0) starttime = System.currentTimeMillis();
      sntc = parseSentence(sentence);
      if (verbosity > 0) reportTime("Link-parsing: ");

      for (ParsedSentence parse : sntc.getParses()) {
        if (do_expand_preps) {
          parse.getLeft().set("expand-preps", new FeatureNode("T"));
        }

        // The actual relation extraction is done here.
        if (do_apply_algs) sentenceAlgorithmApplier.applyAlgs(parse, context);
        if (do_stanford) sentenceAlgorithmApplier.extractStanford(parse, context);
        if (do_penn_tagging) sentenceAlgorithmApplier.pennTag(parse, context);

        // Also do a Penn tree-bank style phrase structure markup.
        if (do_tree_markup) {
          phraseMarkup.markup(parse);

          // Repair the entity-mangled tree-bank string.
          PhraseTree pt = new PhraseTree(parse.getLeft());
          parse.setPhraseString(pt.toString());
        }
      }

      // Assign a simple parse-ranking score, based on LinkGrammar data.
      sntc.simpleParseRank();

      // Perform anaphora resolution
      if (do_anaphora_resolution) {
        hobbs.addParse(sntc);
        hobbs.resolve(sntc);
      }
    } catch (Exception e) {
      System.err.println("Error: Failed to process sentence: " + sentence);
      e.printStackTrace();
    }
    if (verbosity > 0) reportTime("RelEx processing: ");
    return sntc;
  }
Esempio n. 2
0
    public Boolean PMCallback(String pattern, PhraseTree pt) {
      if (0 < debug)
        System.out.println(
            "=== >"
                + pattern
                + "< == >"
                + PhraseTree.toString(pt.getCursor())
                + "< phr="
                + pt.toString());

      // "a" means "accept"
      if (pattern.equals("a")) {
        chunkWords(pt.getCursor(), curr_chunk);
      }

      // "a2" means "accept, if two words or more"
      // Terminate search if its less than two words.
      else if (pattern.equals("a2")) {
        if (1 >= pt.getBreadth()) return true;
        chunkWords(pt.getCursor(), curr_chunk);
      }

      // "p" means "accept only if its a pronoun".
      else if (pattern.equals("p")) {
        // Must have only one word in the phrase ...
        if (1 != pt.getBreadth()) return false;

        // ... and that word must be a pronoun.
        FeatureNode word = pt.getFirstWord();
        if (false == WordFeature.isPronoun(word)) return false;
        chunkWords(pt.getCursor(), curr_chunk);
      }

      // Reject if its a copula (is, was, ...) and keep otherwise.
      else if (pattern.equals("notcop")) {
        FeatureNode word = pt.getFirstWord();
        if (WordFeature.isCopula(word)) {
          saw_copula = true;
          return false;
        }
        chunkWords(pt.getCursor(), curr_chunk);
      }

      // Accept only if copula seen previously
      else if (pattern.equals("postcop")) {
        if (!saw_copula) return false;
        chunkWords(pt.getCursor(), curr_chunk);
      }
      return false;
    }
Esempio n. 3
0
 public void findChunks(ParsedSentence parse) {
   PhraseTree pt = parse.getPhraseTree();
   SubPhrase sb = new SubPhrase();
   pt.foreach(sb);
 }
Esempio n. 4
0
    public void FoundCallback(String pattern, PhraseTree pt) {
      if (0 < debug) System.out.println("========== match! " + pattern + " == " + pt.toString());

      curr_chunk = new LexChunk();
      saw_copula = false;
    }