Example #1
0
        private string MyCorefferencer(string str)
        {
            var modelPath         = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\Models\Coref";
            var coreferenceFinder = new TreebankLinker(modelPath);
            var sentences         = MySentenceDetector(str); //["Mr. & Mrs. Smith is a 2005 American romantic comedy action film.",
                                                             //"The film stars Brad Pitt and Angelina Jolie as a bored upper-middle class married couple.",
                                                             //"They are surprised to learn that they are both assassins hired by competing agencies to kill each other."];
            var coref = coreferenceFinder.GetCoreferenceParse(sentences);

            return(coref);
        }
Example #2
0
        private string IdentifyCoreferents(IEnumerable <string> sentences)
        {
            if (_coreferenceFinder == null)
            {
                _coreferenceFinder = new TreebankLinker(_modelPath + "coref");
            }

            var parsedSentences = new List <Parse>();

            foreach (string sentence in sentences)
            {
                Parse sentenceParse = ParseSentence(sentence);
                parsedSentences.Add(sentenceParse);
            }
            return(_coreferenceFinder.GetCoreferenceParse(parsedSentences.ToArray()));
        }
Example #3
0
        internal string IdentifyCoreferents(string[] sentences)
        {
            if (_mCoreferenceFinder == null)
            {
                _mCoreferenceFinder = new TreebankLinker(_modelPath + "coref");
            }

            var parsedSentences = new List <Parse>();

            foreach (string sentence in sentences)
            {
                Parse  sentenceParse = ParseSentence(sentence);
                string findNames     = FindNames(sentenceParse);
                parsedSentences.Add(sentenceParse);
            }
            return(_mCoreferenceFinder.GetCoreferenceParse(parsedSentences.ToArray()));
        }
Example #4
0
        public override void run(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine(Help);
            }
            else
            {
                TreebankLinker treebankLinker;
                try
                {
                    treebankLinker = new TreebankLinker(args[0], LinkerMode.TEST);
                }
                catch (IOException e)
                {
                    throw new TerminateToolException(-1, "Failed to load all coreferencer models!", e);
                }

                ObjectStream <string> lineStream = new PlainTextByLineStream(new InputStreamReader(Console.OpenStandardInput));

                PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "parses");
                perfMon.start();

                try
                {
                    int             sentenceNumber = 0;
                    IList <Mention> document       = new List <Mention>();
                    IList <Parse>   parses         = new List <Parse>();

                    string line;
                    while ((line = lineStream.read()) != null)
                    {
                        if (line.Equals(""))
                        {
                            DiscourseEntity[] entities = treebankLinker.getEntities(document.ToArray());
                            //showEntities(entities);
                            (new CorefParse(this, parses, entities)).show();
                            sentenceNumber = 0;
                            document.Clear();
                            parses.Clear();
                        }
                        else
                        {
                            Parse p = Parse.parseParse(line);
                            parses.Add(p);
                            Mention[] extents = treebankLinker.MentionFinder.getMentions(new DefaultParse(p, sentenceNumber));
                            //construct new parses for mentions which don't have constituents.
                            for (int ei = 0, en = extents.Length; ei < en; ei++)
                            {
                                //System.err.println("PennTreebankLiner.main: "+ei+" "+extents[ei]);

                                if (extents[ei].Parse == null)
                                {
                                    //not sure how to get head index, but its not used at this point.
                                    Parse snp = new Parse(p.Text, extents[ei].Span, "NML", 1.0, 0);
                                    p.insert(snp);
                                    extents[ei].Parse = new DefaultParse(snp, sentenceNumber);
                                }
                            }
                            document.AddRange(Arrays.asList(extents));
                            sentenceNumber++;
                        }

                        perfMon.incrementCounter();
                    }
                }
                catch (IOException e)
                {
                    CmdLineUtil.handleStdinIoError(e);
                }

                perfMon.stopAndPrintFinalResult();
            }
        }