private static SemanticGraph MakeGraph() { Tree tree; try { tree = new PennTreeReader(new StringReader("(S1 (S (S (S (NP (DT The) (NN CD14) (NN LPS) (NN receptor)) (VP (VBZ is) (, ,) (ADVP (RB however)) (, ,) (ADVP (RB up)) (VP (VBN regulated) (PRN (-LRB- -LRB-) (FRAG (RB not) (ADJP (RB down) (VBN regulated))) (-RRB- -RRB-)) (PP (IN in) (NP (JJ tolerant) (NNS cells)))))) (, ,) (CC and) (S (NP (NN LPS)) (VP (MD can) (, ,) (PP (IN in) (NP (NN fact))) (, ,) (ADVP (RB still)) (VP (VB lead) (PP (TO to) (NP (NP (NN activation)) (PP (IN of) (NP (JJ tolerant) (NNS cells))))) (SBAR (IN as) (S (VP (VBN evidenced) (PP (IN by) (NP (NP (NN mobilization)) (PP (IN of) (NP (DT the) (NN transcription) (NN factor) (NP (NP (JJ nuclear) (NN factor) (NN kappa) (NN B)) (PRN (-LRB- -LRB-) (NP (NN NF-kappa) (NN B)) (-RRB- -RRB-)))))))))))))) (. .)))" ), new LabeledScoredTreeFactory()).ReadTree(); } catch (IOException e) { // the tree should parse correctly throw new Exception(e); } return(SemanticGraphFactory.MakeFromTree(tree, SemanticGraphFactory.Mode.Basic, GrammaticalStructure.Extras.Maximal)); }
// main method only public static void Main(string[] args) { Treebank tb = new MemoryTreebank(); Properties props = StringUtils.ArgsToProperties(args); string treeFileName = props.GetProperty("treeFile"); string sentFileName = props.GetProperty("sentFile"); string testGraph = props.GetProperty("testGraph"); if (testGraph == null) { testGraph = "false"; } string load = props.GetProperty("load"); string save = props.GetProperty("save"); if (load != null) { log.Info("Load not implemented!"); return; } if (sentFileName == null && treeFileName == null) { log.Info("Usage: java SemanticGraph [-sentFile file|-treeFile file] [-testGraph]"); Tree t = Tree.ValueOf("(ROOT (S (NP (NP (DT An) (NN attempt)) (PP (IN on) (NP (NP (NNP Andres) (NNP Pastrana) (POS 's)) (NN life)))) (VP (VBD was) (VP (VBN carried) (PP (IN out) (S (VP (VBG using) (NP (DT a) (JJ powerful) (NN bomb))))))) (. .)))" ); tb.Add(t); } else { if (treeFileName != null) { tb.LoadPath(treeFileName); } else { string[] options = new string[] { "-retainNPTmpSubcategories" }; LexicalizedParser lp = ((LexicalizedParser)LexicalizedParser.LoadModel("/u/nlp/data/lexparser/englishPCFG.ser.gz", options)); BufferedReader reader = null; try { reader = IOUtils.ReaderFromString(sentFileName); } catch (IOException e) { throw new RuntimeIOException("Cannot find or open " + sentFileName, e); } try { System.Console.Out.WriteLine("Processing sentence file " + sentFileName); for (string line; (line = reader.ReadLine()) != null;) { System.Console.Out.WriteLine("Processing sentence: " + line); PTBTokenizer <Word> ptb = PTBTokenizer.NewPTBTokenizer(new StringReader(line)); IList <Word> words = ptb.Tokenize(); Tree parseTree = lp.ParseTree(words); tb.Add(parseTree); } reader.Close(); } catch (Exception e) { throw new Exception("Exception reading key file " + sentFileName, e); } } } foreach (Tree t_1 in tb) { SemanticGraph sg = SemanticGraphFactory.GenerateUncollapsedDependencies(t_1); System.Console.Out.WriteLine(sg.ToString()); System.Console.Out.WriteLine(sg.ToCompactString()); if (testGraph.Equals("true")) { SemanticGraph g1 = SemanticGraphFactory.GenerateCollapsedDependencies(t_1); System.Console.Out.WriteLine("TEST SEMANTIC GRAPH - graph ----------------------------"); System.Console.Out.WriteLine(g1.ToString()); System.Console.Out.WriteLine("readable ----------------------------"); System.Console.Out.WriteLine(g1.ToString(SemanticGraph.OutputFormat.Readable)); System.Console.Out.WriteLine("List of dependencies ----------------------------"); System.Console.Out.WriteLine(g1.ToList()); System.Console.Out.WriteLine("xml ----------------------------"); System.Console.Out.WriteLine(g1.ToString(SemanticGraph.OutputFormat.Xml)); System.Console.Out.WriteLine("dot ----------------------------"); System.Console.Out.WriteLine(g1.ToDotFormat()); System.Console.Out.WriteLine("dot (simple) ----------------------------"); System.Console.Out.WriteLine(g1.ToDotFormat("Simple", CoreLabel.OutputFormat.Value)); } } // System.out.println(" graph ----------------------------"); // System.out.println(t.allTypedDependenciesCCProcessed(false)); if (save != null) { log.Info("Save not implemented!"); } }