Package clear.dep

Examples of clear.dep.DepTree


  @Override
  public void process(JCas jCas) throws AnalysisEngineProcessException {
    for (Sentence sentence : JCasUtil.select(jCas, Sentence.class)) {
      List<BaseToken> tokens = JCasUtil.selectCovered(jCas, BaseToken.class, sentence);
      DepTree tree = new DepTree();

      // Build map between CAS dependency node and id for later creation of
      // ClearParser dependency node/tree
      Map<ConllDependencyNode, Integer> depNodeToID = new HashMap<ConllDependencyNode, Integer>();
      int nodeId = 1;
      for (ConllDependencyNode depNode : JCasUtil.selectCovered(jCas, ConllDependencyNode.class, sentence)) {
        //if (depNode instanceof TopDependencyNode) {
      if (depNode.getHead() == null) {
        // A node without the head is the head of the sentence
          depNodeToID.put(depNode, 0);
        } else {
          depNodeToID.put(depNode, nodeId);
          nodeId++;
        }
      }

      // Initialize Token / Sentence info for the ClearParser Semantic Role Labeler
      for (int i = 0; i < tokens.size(); i++) {
        BaseToken token = tokens.get(i);

        // Determine HeadId
        DepNode node = new DepNode();
        ConllDependencyNode casDepNode = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, token).get(0);
        casDepNode.getDeprel();
        String headRelation = casDepNode.getDeprel();
        ConllDependencyNode head = casDepNode.getHead();
       
        // If there is no head, this is the head node, set node to 0
        int headId = (head == null) ? 0 : depNodeToID.get(head);

        // Populate Dependency Node / Tree information
        node.id = i + 1;
        node.form = token.getCoveredText();
        node.pos = token.getPartOfSpeech();
        node.lemma = useLemmatizer ? "" : token.getNormalizedForm();
        node.setHead(headId, headRelation, 0);
        tree.add(node);
      }
      tree.setPredicates(AbstractReader.LANG_EN);

      // Run the SRL
      parser.parse(tree);

      // Convert ClearParser SRL output to CAS types
View Full Code Here


  @Override
  public void process(JCas jCas) throws AnalysisEngineProcessException {
    for (Sentence sentence : JCasUtil.select(jCas, Sentence.class)) {
      List<BaseToken> tokens = JCasUtil.selectCovered(jCas, BaseToken.class, sentence);
      DepTree tree = new DepTree();

      // Convert CAS data into structures usable by ClearParser
      for (int i = 0; i < tokens.size(); i++) {
        BaseToken token = tokens.get(i);
        DepNode node = new DepNode();
        node.id = i + 1;
        node.form = token.getCoveredText();
        node.pos = token.getPartOfSpeech();
        node.lemma = useLemmatizer ? lemmatizer.getLemma(node.form, node.pos) : token.getNormalizedForm();
        tree.add(node);
      }

      // Run parser and convert output back to CAS friendly data types
      parser.parse(tree);
      ArrayList<ConllDependencyNode> nodes = ClearDependencyUtility.convert(jCas, tree, sentence, tokens);
View Full Code Here

TOP

Related Classes of clear.dep.DepTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.