Beispiel #1
0
        /// <summary>
        /// The tree t is normally expected to be a Penn-Treebank-style tree
        /// in which the top node is an extra node that has a unary expansion.
        /// </summary>
        /// <remarks>
        /// The tree t is normally expected to be a Penn-Treebank-style tree
        /// in which the top node is an extra node that has a unary expansion.
        /// If this isn't the case, an extra node is added and the user is warned.
        /// </remarks>
        public virtual Tree TransformTree(Tree t)
        {
            if (trainOptions.printTreeTransformations > 0)
            {
                TrainOptions.PrintTrainTree(null, "ORIGINAL TREE:", t);
            }
            Tree trTree = annotator.TransformTree(t);

            if (trainOptions.selectivePostSplit)
            {
                trTree = postSplitter.TransformTree(trTree);
            }
            if (trainOptions.printTreeTransformations > 0)
            {
                TrainOptions.PrintTrainTree(trainOptions.printAnnotatedPW, "ANNOTATED TREE:", trTree);
            }
            if (trainOptions.printAnnotatedRuleCounts)
            {
                Tree tr2 = trTree.DeepCopy(new LabeledScoredTreeFactory(), new StringLabelFactory());
                ICollection <Tree> localTrees = tr2.LocalTrees();
                foreach (Tree tr in localTrees)
                {
                    annotatedRuleCounts.IncrementCount(tr);
                }
            }
            if (trainOptions.printAnnotatedStateCounts)
            {
                foreach (Tree subt in trTree)
                {
                    if (!subt.IsLeaf())
                    {
                        annotatedStateCounts.IncrementCount(subt.Label().Value());
                    }
                }
            }
            // if we add the ROOT first, then we don't know how to percolate the heads at the top
            AddRoot(trTree);
            // this creates a few non-binarized rules at the top
            Tree binarizedTree = binarizer.TransformTree(trTree);

            if (trainOptions.printTreeTransformations > 0)
            {
                TrainOptions.PrintTrainTree(trainOptions.printBinarizedPW, "BINARIZED TREE:", binarizedTree);
                trainOptions.printTreeTransformations--;
            }
            if (forceCNF)
            {
                binarizedTree = new CNFTransformers.ToCNFTransformer().TransformTree(binarizedTree);
            }
            //        System.out.println("BinarizedCNF:\n");
            //        binarizedTree.pennPrint();
            return(binarizedTree);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            CategoryWordTag.printWordTag = false;
            string       path           = args[0];
            IList <Tree> trees          = TreebankAnnotator.GetTrees(path, 200, 219, 0, 10);
            IList <Tree> annotatedTrees = new TreebankAnnotator(new Options(), path).AnnotateTrees(trees);

            foreach (Tree tree in annotatedTrees)
            {
                System.Console.Out.WriteLine("ORIGINAL:\n");
                tree.PennPrint();
                System.Console.Out.WriteLine("CNFed:\n");
                Tree cnfTree = new CNFTransformers.ToCNFTransformer().TransformTree(tree);
                cnfTree.PennPrint();
                System.Console.Out.WriteLine("UnCNFed:\n");
                Tree unCNFTree = new CNFTransformers.FromCNFTransformer().TransformTree(cnfTree);
                unCNFTree.PennPrint();
                System.Console.Out.WriteLine("\n\n");
            }
        }