List of usage examples for edu.stanford.nlp.ling StringLabelFactory StringLabelFactory
StringLabelFactory
From source file:Ceist.CeistView.java
License:Open Source License
@Action public void showTreeView() { if (treeViewBox == null) { JFrame mainFrame = CeistApp.getApplication().getMainFrame(); treeViewBox = new dlgTreeView(mainFrame, false); treeViewBox.setLocationRelativeTo(mainFrame); String ptbTreeString = "(ROOT (S (NP (DT This)) (VP (VBZ is) (NP (DT a) (NN test))) (. .)))"; try {//from w w w. j a v a 2 s.c o m Tree tree = (new PennTreeReader(new StringReader(ptbTreeString), new LabeledScoredTreeFactory(new StringLabelFactory()))).readTree(); treeViewBox.mainPanel.setTree(tree); } catch (Exception e) { System.out.println(e.toString()); } } }
From source file:elkfed.expletives.EF_Tree.java
License:Apache License
public static Tree tagged_word(String word, String tag) { LabelFactory lf = new StringLabelFactory(); Tree result = new LabeledScoredTreeNode(); result.setLabel(lf.newLabel(tag));/*from w w w .j av a 2 s . com*/ Tree[] dtrs = new Tree[1]; dtrs[0] = new LabeledScoredTreeNode(lf.newLabel(word)); result.setChildren(dtrs); return result; }
From source file:elkfed.expletives.EF_Tree.java
License:Apache License
public static Tree tree_pred(Tree node) { LabelFactory lf = new StringLabelFactory(); Tree result = new LabeledScoredTreeNode(); result.setLabel(lf.newLabel(node.value() + "-PRD")); if (node.value().equals("PP") && node.children().length == 2 && node.children()[0].value().equals("IN")) { Tree[] dtrs = new Tree[2]; dtrs[0] = node.children()[0];/* w w w . j a va 2s. c o m*/ dtrs[1] = node.children()[1].headPreTerminal(new ModCollinsHeadFinder()); result.setChildren(dtrs); } Tree[] dtrs = new Tree[1]; dtrs[0] = node.headPreTerminal(new ModCollinsHeadFinder()); result.setChildren(dtrs); return result; }
From source file:elkfed.expletives.EF_Tree.java
License:Apache License
/** constructs a marked subtree for a subclause * outside the path to the pronoun//from w w w .j av a 2s. c om * @param node the starting point * @return a marked subtree for the tree starting with node */ public static Tree tree_pruned(Tree node) { LabelFactory lf = new StringLabelFactory(); Tree result = new LabeledScoredTreeNode(); result.setLabel(lf.newLabel(node.value() + "-X")); List<Tree> dtrs = new ArrayList<Tree>(); boolean cpl_seen = false; if (node.value().matches("S|SBAR|VP")) { for (Tree t : node.children()) { // modals are copied verbatim String cat = t.value(); if (cat.matches("TO|MD|IN")) { dtrs.add(t); cpl_seen = true; } else if (cat.startsWith("WH")) { Tree dtr = tagged_word(cat, "WH"); cpl_seen = true; } else if (t.value().startsWith("VB")) { break; } else if (t.value().matches("S|SBAR|VP")) { if (cpl_seen) { //ignore } else { dtrs.add(tree_pruned(t)); } } } } result.setChildren(dtrs); return result; }
From source file:elkfed.expletives.EF_Tree.java
License:Apache License
/** constructs a marked subtree for parts which are * outside the path to the pronoun//from w w w .j a v a 2s .com * @param node the starting point * @return a marked subtree for the tree starting with node */ public static Tree tree_outside(Tree node) { LabelFactory lf = new StringLabelFactory(); // verbs and modals are copied verbatim if (node.value().matches("VB[DZPNG]?")) { return tagged_word(Morphology.stemStatic(node.children()[0].value(), node.value()).value(), "VBX"); //return node; } else if (node.value().matches("TO|MD|IN|RB")) { return node; } Tree result = new LabeledScoredTreeNode(); result.setLabel(lf.newLabel(node.value())); if (node.value().matches("VP")) { List<Tree> dtrs = new ArrayList<Tree>(); dtrs_inside(node, dtrs); result.setChildren(dtrs); } else { List<Tree> dtrs = null; result.setChildren(dtrs); } return result; }
From source file:elkfed.expletives.EF_Tree.java
License:Apache License
/** * constructs a marked subtree for the part where the * pronoun is <i>inside</i> the subtree * @param node the starting point// w ww .ja va2 s . co m * @param pron our pronoun * @return a marked subtree for the tree starting with node */ public static Tree tree_inside(Tree node, Tree pron) { LabelFactory lf = new StringLabelFactory(); int pron_left = pron.leftCharEdge(node); int pron_right = pron.rightCharEdge(node); List<Tree> dtrs = new ArrayList<Tree>(node.children().length); boolean node_seen = false; for (Tree t : node.children()) { if (t == pron) { dtrs.add(t); node_seen = true; } else if (t.dominates(pron)) { dtrs.add(tree_inside(t, pron)); node_seen = true; } else { String cat = t.value(); if (cat.matches("S|SBAR")) { dtrs.add(tree_pruned(t)); } else { dtrs.add(tree_outside(t)); } } } Tree result = new LabeledScoredTreeNode(); result.setLabel(lf.newLabel(node.value() + "-I")); result.setChildren(dtrs); return result; }
From source file:elkfed.expletives.EF_Tree.java
License:Apache License
public static Tree tree_markonly(Tree node, Tree pron) { LabelFactory lf = new StringLabelFactory(); List<Tree> dtrs = new ArrayList<Tree>(node.children().length); for (Tree t : node.children()) { if (t == pron) { dtrs.add(t);//ww w. ja v a 2s . c om } else if (t.dominates(pron)) { dtrs.add(tree_markonly(t, pron)); } else { dtrs.add(t); } } Tree result = new LabeledScoredTreeNode(); result.setLabel(lf.newLabel(node.value() + "-I")); result.setChildren(dtrs); return result; }
From source file:GUI.ParseTreeCorrector.java
/** * * @param parsedSentence// w w w .j a va 2 s. c o m * @param modifications */ public void TreeParseDisplay(String parsedSentence, Boolean modifications) { //====================================================================== parseTree.removeAll(); expression.setText(sentences.get(sentenceOrder - 1)); sentenceNumber.setText(String.valueOf(sentenceOrder / 2)); if (modifications == Boolean.FALSE) { parse.setText(ParseDisplay(sentences.get(sentenceOrder))); } String parseString = parsedSentence; edu.stanford.nlp.parser.ui.TreeJPanel tjp = new edu.stanford.nlp.parser.ui.TreeJPanel(); String ptbTreeString = (parseString); Tree tree = null; try { tree = (new PennTreeReader(new StringReader(ptbTreeString), new LabeledScoredTreeFactory(new StringLabelFactory()))).readTree(); } catch (IOException ex) { Logger.getLogger(ParseTreeCorrector.class.getName()).log(Level.SEVERE, null, ex); } tjp.setTree(tree); tjp.setBackground(Color.white); tjp.setFont(new Font("Traditional arabic", 10, 10)); JInternalFrame frame = new JInternalFrame(); frame.getContentPane().add(tjp, BorderLayout.CENTER); frame.setPreferredSize(new Dimension(parseTree.getWidth(), parseTree.getHeight())); frame.setMaximizable(true); frame.setClosable(true); frame.setIconifiable(true); frame.setResizable(true); frame.pack(); frame.setVisible(true); frame.setVisible(true); parseTree.add(frame); //====================================================================== }
From source file:nlpedit.ui.NLPTree.java
License:Open Source License
public Tree getTree() { Tree ntree = new LabeledScoredTreeNode(); try {/*from ww w . j a va2 s . co m*/ ntree = (new PennTreeReader(new StringReader(getTreeString()), new LabeledScoredTreeFactory(new StringLabelFactory()))).readTree(); } catch (IOException e) { e.printStackTrace(); } return ntree; }