static IList <Coreference> GetCoReferences(XElement document, IList <Sentence> Sentences) { List <Coreference> result = new List <Coreference>(); var coreferences = from c in document.Elements("document").Elements("coreference").Elements("coreference") select c; foreach (var item in coreferences) { var co = new Coreference(); var mentions = from c in item.Elements("mention") select c; Mention root = null; foreach (var mention in mentions) { var m = new Mention(); m.Read(mention, Sentences); m.Head = Sentences.Where(c => c.Id == m.Sentence).First().Tokens.Where(c => c.SentenceLoc == m.HeadLoc).First(); if (mention.Attributes("representative").Count() != 0) { co.Root = m; root = m; } else { m.Root = root; co.Mentions.Add(m); } } result.Add(co); } var Roots = result.Select(c => c.Root).ToList(); //obtain non root mention and avoid recursive mentions foreach (var coreference in result) { foreach (var mention in coreference.Mentions) { if (Roots.Where(c => c.Contains(mention)).Count() > 0) { mention.Enable = false; } } } return(result); }
public bool Contains(Mention mention) { return(this.Sentence == mention.Sentence && this.Start <= mention.Start && this.End >= mention.End); }