Package com.googlecode.clearnlp.dependency

Examples of com.googlecode.clearnlp.dependency.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();

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

      // Run parser and convert output back to CAS friendly data types
      parser.process(tree);
      ArrayList<ConllDependencyNode> nodes = ClearDependencyUtility.convert(jCas, tree, sentence, tokens);
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();

      // Build map between CAS dependency node and id for later creation of
      // ClearNLP 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++;
        }
      }
     
      int[] headIDs = new int[tokens.size()];
      String[] deprels = new String[tokens.size()];

      // Initialize Token / Sentence info for the ClearNLP Semantic Role Labeler
      // we are filtering out newline tokens
      // use idIter as the non-newline token index counter
      int idIter = 0;
      for (int i = 0; i < tokens.size(); i++) {
        BaseToken token = tokens.get(i);
        // ignore newline tokens within a sentence - newline = whitespace = non-token
        if(!(token instanceof NewlineToken)) {
          // Determine HeadId
          List<ConllDependencyNode> casDepNodes = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, token);
         
          ConllDependencyNode casDepNode = casDepNodes.get(0);
          if(casDepNode.getId() == 0) casDepNode = casDepNodes.get(1);
 
          deprels[i] = casDepNode.getDeprel();
          ConllDependencyNode head = casDepNode.getHead();
 
          // If there is no head, this is the head node, set node to 0
          headIDs[i] = (head == null) ? 0 : depNodeToID.get(head);
 
          // Populate Dependency Node / Tree information
          int id = idIter + 1;
          String form = casDepNode.getForm();
          String pos = casDepNode.getPostag();
          String lemma = casDepNode.getLemma();
         
          DEPNode node = new DEPNode(id, form, lemma, pos, new DEPFeat());
          tree.add(node);
          idIter++;
        }
      }

      for (int i=1; i<tree.size(); i++)
      {
        DEPNode node = tree.get(i);
        DEPNode head = tree.get(headIDs[i-1]);
        String  label = deprels[i-1];
        node.setHead(head, label);
      }
     
      tree.initSHeads();
     
      // Run the SRL
      identifier.process(tree);
      classifier.process(tree);
      srlabeler.process(tree);
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 ClearNLP
      for (int i = 0; i < tokens.size(); i++) {
        BaseToken token = tokens.get(i);
        DEPNode node = new DEPNode(i+1, token.getCoveredText());
        tree.add(node);
      }

      // Run parser and convert output back to CAS friendly data types
      postagger.process(tree);
     
      for (int i = 0; i < tokens.size(); i++) {
        BaseToken token = tokens.get(i);
        DEPNode node = tree.get(i+1);
        token.setPartOfSpeech(node.pos);
      }
     
    }
   
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 ClearNLP
      for (int i = 0; i < tokens.size(); i++) {
        BaseToken token = tokens.get(i);
        String lemma = useLemmatizer ? lemmatizer.getLemma(token.getCoveredText(), token.getPartOfSpeech()) : token.getNormalizedForm();
        DEPNode node = new DEPNode(i+1, token.getCoveredText(), lemma, token.getPartOfSpeech(), new DEPFeat());
        tree.add(node);
      }

      // Run parser and convert output back to CAS friendly data types
      parser.process(tree);
      ArrayList<ConllDependencyNode> nodes = ClearDependencyUtility.convert(jCas, tree, sentence, tokens);
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();

      // Build map between CAS dependency node and id for later creation of
      // ClearNLP 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++;
        }
      }
     
      int[] headIDs = new int[tokens.size()];
      String[] deprels = new String[tokens.size()];

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

        // Determine HeadId
        List<ConllDependencyNode> casDepNodes = JCasUtil.selectCovered(jCas, ConllDependencyNode.class, token);
       
        ConllDependencyNode casDepNode = casDepNodes.get(0);
        if(casDepNode.getId() == 0) casDepNode = casDepNodes.get(1);

        deprels[i] = casDepNode.getDeprel();
        ConllDependencyNode head = casDepNode.getHead();

        // If there is no head, this is the head node, set node to 0
        headIDs[i] = (head == null) ? 0 : depNodeToID.get(head);

        // Populate Dependency Node / Tree information
        int id = i + 1;
        String form = casDepNode.getForm();
        String pos = casDepNode.getPostag();
        String lemma = casDepNode.getLemma();
       
        DEPNode node = new DEPNode(id, form, lemma, pos, new DEPFeat());
        tree.add(node);
      }

      for (int i=1; i<tree.size(); i++)
      {
        DEPNode node = tree.get(i);
        DEPNode head = tree.get(headIDs[i-1]);
        String  label = deprels[i-1];
        node.setHead(head, label);
      }
     
      tree.initSHeads();
     
      // Run the SRL
      identifier.process(tree);
      classifier.process(tree);
      srlabeler.process(tree);
View Full Code Here

TOP

Related Classes of com.googlecode.clearnlp.dependency.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.