public static void Main(string[] args)
        {
            Edu.Stanford.Nlp.Trees.CoordinationTransformer transformer = new Edu.Stanford.Nlp.Trees.CoordinationTransformer(null);
            Treebank   tb           = new MemoryTreebank();
            Properties props        = StringUtils.ArgsToProperties(args);
            string     treeFileName = props.GetProperty("treeFile");

            if (treeFileName != null)
            {
                try
                {
                    ITreeReader tr = new PennTreeReader(new BufferedReader(new InputStreamReader(new FileInputStream(treeFileName))), new LabeledScoredTreeFactory());
                    for (Tree t; (t = tr.ReadTree()) != null;)
                    {
                        tb.Add(t);
                    }
                }
                catch (IOException e)
                {
                    throw new Exception("File problem: " + e);
                }
            }
            foreach (Tree t_1 in tb)
            {
                System.Console.Out.WriteLine("Original tree");
                t_1.PennPrint();
                System.Console.Out.WriteLine();
                System.Console.Out.WriteLine("Tree transformed");
                Tree tree = transformer.TransformTree(t_1);
                tree.PennPrint();
                System.Console.Out.WriteLine();
                System.Console.Out.WriteLine("----------------------------");
            }
        }
Esempio n. 2
0
        public virtual void TestRead()
        {
            string         treeText   = "(1 (2 This)) (3 (4 is) (5 a)) (6 (\\* small) (7 \\/test))";
            StringReader   reader     = new StringReader(treeText);
            PennTreeReader treeReader = new PennTreeReader(reader);

            string[] expected = new string[] { "(1 (2 This))", "(3 (4 is) (5 a))", "(6 (* small) (7 /test))" };
            for (int i = 0; i < expected.Length; ++i)
            {
                Tree tree = treeReader.ReadTree();
                NUnit.Framework.Assert.IsTrue(tree != null);
                NUnit.Framework.Assert.AreEqual(expected[i], tree.ToString());
            }
            Tree tree_1 = treeReader.ReadTree();

            NUnit.Framework.Assert.IsFalse(tree_1 != null);
        }
Esempio n. 3
0
 // todo [cdm 2015]: These next two methods duplicate the Tree.valueOf methods!
 /// <summary>Simple tree reading utility method.</summary>
 /// <remarks>Simple tree reading utility method.  Given a tree formatted as a PTB string, returns a Tree made by a specific TreeFactory.</remarks>
 public static Tree ReadTree(string ptbTreeString, ITreeFactory treeFactory)
 {
     try
     {
         PennTreeReader ptr = new PennTreeReader(new StringReader(ptbTreeString), treeFactory);
         return(ptr.ReadTree());
     }
     catch (IOException ex)
     {
         throw new Exception(ex);
     }
 }
 /// <summary>Just for testing.</summary>
 public static void Main(string[] args)
 {
     try
     {
         ITreeReader tr = new PennTreeReader(new StringReader("(S (NP (NNP Sam)) (VP (VBD died) (NP (NN today))))"), new LabeledScoredTreeFactory());
         Tree        t  = tr.ReadTree();
         System.Console.Out.WriteLine(t);
         TreeGraphNode tgn = new TreeGraphNode(t, (TreeGraphNode)null);
         System.Console.Out.WriteLine(tgn.ToPrettyString(0));
         EnglishGrammaticalStructure gs = new EnglishGrammaticalStructure(tgn);
         System.Console.Out.WriteLine(tgn.ToPrettyString(0));
         tgn.PercolateHeads(new SemanticHeadFinder());
         System.Console.Out.WriteLine(tgn.ToPrettyString(0));
     }
     catch (Exception e)
     {
         log.Error("Horrible error: " + e);
         log.Error(e);
     }
 }