Пример #1
0
        /// <summary>
        /// Returns a <code>TreeFactory</code> that produces
        /// <code>TreeGraphNode</code>s.  The <code>Label</code> of
        /// <code>this</code> is examined, and providing it is not
        /// <code>null</code>, a <code>LabelFactory</code> which will
        /// produce that kind of <code>Label</code> is supplied to the
        /// <code>TreeFactory</code>.  If the <code>Label</code> is
        /// <code>null</code>, a <code>CoreLabel.factory()</code> will be used.
        /// The factories returned on different calls are different: a new one is
        /// allocated each time.
        /// </summary>
        /// <returns>a factory to produce treegraphs</returns>
        public override ITreeFactory TreeFactory()
        {
            ILabelFactory lf;

            if (Label() != null)
            {
                lf = Label().LabelFactory();
            }
            else
            {
                lf = CoreLabel.Factory();
            }
            return(new TreeGraphNodeFactory(lf));
        }
        /// <summary>Copies the Auxiliary tree.</summary>
        /// <remarks>
        /// Copies the Auxiliary tree.  Also, puts the new names-&gt;nodes map in the TsurgeonMatcher that called copy.
        /// <br />
        /// The trees and labels to use when making the copy are specified
        /// with treeFactory and labelFactory.  This lets the tsurgeon script
        /// produce trees which are of the same type as the input trees.
        /// Each of the tsurgeon relations which copies a tree should include
        /// pass in the correct factories.
        /// </remarks>
        public virtual Edu.Stanford.Nlp.Trees.Tregex.Tsurgeon.AuxiliaryTree Copy(TsurgeonMatcher matcher, ITreeFactory treeFactory, ILabelFactory labelFactory)
        {
            if (labelFactory == null)
            {
                labelFactory = CoreLabel.Factory();
            }
            IDictionary <string, Tree> newNamesToNodes = Generics.NewHashMap();
            Pair <Tree, Tree>          result          = CopyHelper(tree, newNamesToNodes, treeFactory, labelFactory);

            //if(! result.first().dominates(result.second()))
            //log.info("Error -- aux tree copy doesn't dominate foot copy.");
            matcher.newNodeNames.PutAll(newNamesToNodes);
            return(new Edu.Stanford.Nlp.Trees.Tregex.Tsurgeon.AuxiliaryTree(result.First(), result.Second(), newNamesToNodes, originalTreeString));
        }
Пример #3
0
 public Debinarizer(bool forceCNF)
     : this(forceCNF, CoreLabel.Factory())
 {
 }
 public LabeledScoredTreeReaderFactory(TreeNormalizer tm)
 {
     lf      = CoreLabel.Factory();
     this.tm = tm;
 }
 /// <summary>Create a new TreeReaderFactory with CoreLabel labels.</summary>
 public LabeledScoredTreeReaderFactory()
 {
     lf = CoreLabel.Factory();
     tm = new BobChrisTreeNormalizer();
 }
Пример #6
0
 /// <summary>Make a TreeFactory that produces LabeledScoredTree trees.</summary>
 /// <remarks>
 /// Make a TreeFactory that produces LabeledScoredTree trees.
 /// The labels are of class <code>CoreLabel</code>.
 /// </remarks>
 public LabeledScoredTreeFactory()
     : this(CoreLabel.Factory())
 {
 }
        /// <exception cref="System.IO.IOException"/>
        public override Pair <Annotation, InputStream> Read(InputStream @is)
        {
            if (compress && !(@is is GZIPInputStream))
            {
                @is = new GZIPInputStream(@is);
            }
            BufferedReader reader = new BufferedReader(new InputStreamReader(@is));
            Annotation     doc    = new Annotation(string.Empty);
            string         line;
            // read the coref graph (new format)
            IDictionary <int, CorefChain> chains = LoadCorefChains(reader);

            if (chains != null)
            {
                doc.Set(typeof(CorefCoreAnnotations.CorefChainAnnotation), chains);
            }
            // read the coref graph (old format)
            line = reader.ReadLine().Trim();
            if (line.Length > 0)
            {
                string[] bits = line.Split(" ");
                if (bits.Length % 4 != 0)
                {
                    throw new RuntimeIOException("ERROR: Incorrect format for the serialized coref graph: " + line);
                }
                IList <Pair <IntTuple, IntTuple> > corefGraph = new List <Pair <IntTuple, IntTuple> >();
                for (int i = 0; i < bits.Length; i += 4)
                {
                    IntTuple src = new IntTuple(2);
                    IntTuple dst = new IntTuple(2);
                    src.Set(0, System.Convert.ToInt32(bits[i]));
                    src.Set(1, System.Convert.ToInt32(bits[i + 1]));
                    dst.Set(0, System.Convert.ToInt32(bits[i + 2]));
                    dst.Set(1, System.Convert.ToInt32(bits[i + 3]));
                    corefGraph.Add(new Pair <IntTuple, IntTuple>(src, dst));
                }
                doc.Set(typeof(CorefCoreAnnotations.CorefGraphAnnotation), corefGraph);
            }
            // read individual sentences
            IList <ICoreMap> sentences = new List <ICoreMap>();

            while ((line = reader.ReadLine()) != null)
            {
                ICoreMap sentence = new Annotation(string.Empty);
                // first line is the parse tree. construct it with CoreLabels in Tree nodes
                Tree tree = new PennTreeReader(new StringReader(line), new LabeledScoredTreeFactory(CoreLabel.Factory())).ReadTree();
                sentence.Set(typeof(TreeCoreAnnotations.TreeAnnotation), tree);
                // read the dependency graphs
                AnnotationSerializer.IntermediateSemanticGraph intermCollapsedDeps   = LoadDependencyGraph(reader);
                AnnotationSerializer.IntermediateSemanticGraph intermUncollapsedDeps = LoadDependencyGraph(reader);
                AnnotationSerializer.IntermediateSemanticGraph intermCcDeps          = LoadDependencyGraph(reader);
                // the remaining lines until empty line are tokens
                IList <CoreLabel> tokens = new List <CoreLabel>();
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Length == 0)
                    {
                        break;
                    }
                    CoreLabel token = LoadToken(line, haveExplicitAntecedent);
                    tokens.Add(token);
                }
                sentence.Set(typeof(CoreAnnotations.TokensAnnotation), tokens);
                // convert the intermediate graph to an actual SemanticGraph
                SemanticGraph collapsedDeps = intermCollapsedDeps.ConvertIntermediateGraph(tokens);
                sentence.Set(typeof(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation), collapsedDeps);
                SemanticGraph uncollapsedDeps = intermUncollapsedDeps.ConvertIntermediateGraph(tokens);
                sentence.Set(typeof(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation), uncollapsedDeps);
                SemanticGraph ccDeps = intermCcDeps.ConvertIntermediateGraph(tokens);
                sentence.Set(typeof(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation), ccDeps);
                sentences.Add(sentence);
            }
            doc.Set(typeof(CoreAnnotations.SentencesAnnotation), sentences);
            return(Pair.MakePair(doc, @is));
        }
Пример #8
0
 /// <summary>
 /// Make a <code>TreeFactory</code> that produces <code>TreeGraphNode</code>s.
 /// The labels are of class <code>CoreLabel</code>.
 /// </summary>
 public TreeGraphNodeFactory() :
     this(CoreLabel.Factory())
 {
 }
Пример #9
0
        /// <summary>
        /// Return a <code>TreeFactory</code> that produces trees of the
        /// same type as the current <code>Tree</code>.  That is, this
        /// implementation, will produce trees of type
        /// <code>LabeledScoredTree(Node|Leaf)</code>.
        /// The <code>Label</code> of <code>this</code>
        /// is examined, and providing it is not <code>null</code>, a
        /// <code>LabelFactory</code> which will produce that kind of
        /// <code>Label</code> is supplied to the <code>TreeFactory</code>.
        /// If the <code>Label</code> is <code>null</code>, a
        /// <code>StringLabelFactory</code> will be used.
        /// The factories returned on different calls a different: a new one is
        /// allocated each time.
        /// </summary>
        public override ITreeFactory TreeFactory()
        {
            ILabelFactory lf = (Label() == null) ? CoreLabel.Factory() : Label().LabelFactory();

            return(new LabeledScoredTreeFactory(lf));
        }