Package edu.stanford.nlp.semgraph.semgrex.ssurgeon

Source Code of edu.stanford.nlp.semgraph.semgrex.ssurgeon.AddNode

package edu.stanford.nlp.semgraph.semgrex.ssurgeon;

import java.io.*;

import edu.stanford.nlp.ling.IndexedWord;
import edu.stanford.nlp.semgraph.semgrex.SemgrexMatcher;
import edu.stanford.nlp.semgraph.SemanticGraph;

public class AddNode extends SsurgeonEdit {
  public static final String LABEL="addNode";
  String nodeString = null;
  String nodeName = null;
 
  public AddNode(String nodeString, String nodeName) {
    this.nodeString = nodeString;
    this.nodeName = nodeName;
  }
 
  public static AddNode createAddNode(String nodeString, String nodeName) {
    return new AddNode(nodeString, nodeName);
  }
 
public static AddNode createAddNode(IndexedWord node, String nodeName) {
  String nodeString = AddDep.cheapWordToString(node);
  return new AddNode(nodeString, nodeName);
}

  @Override
  public void evaluate(SemanticGraph sg, SemgrexMatcher sm) {
    IndexedWord newNode = AddDep.fromCheapString(nodeString);
    sg.addVertex(newNode);
    addNamedNode(newNode, nodeName);
  }

 
  @Override
  public String toEditString() {
    StringWriter buf = new StringWriter();
    buf.write(LABEL); buf.write("\t");
    buf.write(Ssurgeon.NODE_PROTO_ARG);buf.write(" ");
    buf.write("\"");
    buf.write(nodeString);
    buf.write("\"\t");
    buf.write(Ssurgeon.NAME_ARG); buf.write("\t");
    buf.write(nodeName);
    return buf.toString();
  }

}
TOP

Related Classes of edu.stanford.nlp.semgraph.semgrex.ssurgeon.AddNode

TOP
Copyright © 2018 www.massapi.com. 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.