public bool ReplaceNERs(SentenceFragment fragmentFrom) { bool success = false; try { foreach (var re in fragmentFrom.RecognizedEntities) { bool replaced = false; for (int i = 0; i < this.RecognizedEntities.Count; i++) { if (this.RecognizedEntities[i].IsSameDimension(re)) { this.RecognizedEntities[i] = re; replaced = true; success = true; } } if (!replaced) { this.RecognizedEntities.Add(re); } } } catch (Exception ex) { //could not replace or add } return(success); }
public bool IsEquivalent(SentenceFragment fragment) { if (fragment == null || fragment.RecognizedEntities == null || this.RecognizedEntities == null) { return(false); } foreach (var ner in fragment.RecognizedEntities) { if (!this.RecognizedEntities.Contains(ner, new NERComparer())) { return(false); } } return(true); }
public bool IsEquivalent(SentenceFragment fragment, List <string> dimensionNames) { if (fragment == null || fragment.RecognizedEntities == null || this.RecognizedEntities == null) { return(false); } foreach (var ner in fragment.RecognizedEntities) { if (dimensionNames.Contains(ner.Entity.DomainName, StringComparer.InvariantCultureIgnoreCase) && !this.RecognizedEntities.Contains(ner, new NERComparer())) { return(false); } } return(true); }
public object Clone() { SentenceFragment fragmentClone = this.MemberwiseClone() as SentenceFragment; fragmentClone.RecognizedEntities = new List <RecognizedEntity>(); if (fragmentClone != null) { foreach (var ner in this.RecognizedEntities) { var nerClone = ner.Clone() as RecognizedEntity; if (nerClone != null) { fragmentClone.RecognizedEntities.Add(nerClone); } } } return(fragmentClone); }
public bool IsNEDEquivalent(SentenceFragment fragment) { if (fragment == null || fragment.RecognizedEntities == null || this.RecognizedEntities == null) { return(false); } int nedCount = 0; //match 1st against 2nd fragment foreach (var ner in fragment.RecognizedEntities) { if (ner.Entity is NED) { nedCount++; bool found = false; foreach (var re in this.RecognizedEntities) { if (re.Entity is NED && !new NERComparer().Equals(ner, re)) { found = true; break; } } if (!found) { return(false); } } } //if mismatch in NED count they are obviously not ned-equivalent - that completes matching 2nd against 1st fragment as well if (this.RecognizedEntities.Count(re => re.Entity is NED) > nedCount) { return(false); } return(true); }