public bool IsInSameParagraph(XPath other) { for (int i = 0; i < Math.Max(_hierarchy.Length, other._hierarchy.Length); i++) { var ancestor = _hierarchy.ElementAtOrDefault(i); var otherAncestor = other._hierarchy.ElementAtOrDefault(i); if (ancestor != otherAncestor) { if (new [] { ancestor, otherAncestor }.Any(p => _textNodeTypes.Any(type => p == null || p.StartsWith(type)) == false)) { return(false); } } } return(true); }
public Fact(Guid reporter, string wording, string webPageUrl, XPath startNodeXPath, int startOffset, XPath endNodeXPath, int endOffset) { CheckWordCount(wording); if (startNodeXPath.IsInSameParagraph(endNodeXPath) == false) { throw new FactSpreadOverMultipleParagraphs(); } ApplyChange(new SuspiciousFactDetected( Guid.NewGuid(), reporter, wording.Clear(), webPageUrl, new HtmlLocation() { StartNodeXPath = startNodeXPath.ToString(), StartOffset = startOffset, EndNodeXPath = endNodeXPath.ToString(), EndOffset = endOffset } )); }