public bool IncreaseifMatch(fieldClusterModel clusterin) { if (isClusterMatch(clusterin)) { NumberOfrepitions++; return(true); } return(false); }
private bool AddIfInside(fieldClusterModel ClusterCandidate) { var parentRect = GetRect; if (parentRect.Contains(ClusterCandidate.Area)) { ClusterCandidate.fields.ForEach(a => AddWord(a)); return(true); } return(false); }
private bool AddIfIntersect(fieldClusterModel ClusterCandidate) { if (Math.Abs(GetHeightAverage - ClusterCandidate.GetHeightAverage) / (GetHeightAverage + ClusterCandidate.GetHeightAverage) > MISMATCHChance) { return(false); } if (GetRect.IntersectsWith(ClusterCandidate.GetRect)) { ClusterCandidate.fields.ForEach(a => AddWord(a)); return(true); } return(false); }
public static List <FieldClusterLine> CreateLines(DocumentData doc, fieldClusterModel cluster) { DocumentDataNavigation docNavigate = doc.WordsNavigator; var wordList = cluster.Fields; var wordHeight = CalcWordHeight(wordList); List <FieldClusterLine> result = new List <FieldClusterLine>(); wordList = wordList.OrderBy(a => a.Rectangle.Top).ToList(); List <MappedWord> newWordList = new List <MappedWord>(wordList); Dictionary <MappedWord, List <MappedWord> > wordLines = new Dictionary <MappedWord, List <MappedWord> >(); foreach (var word in newWordList) { var inTheSameLine = docNavigate.GetWords(new System.Windows.Rect(cluster.Area.Left, word.Rectangle.Top, cluster.Area.Width, word.Rectangle.Height)) .Where(x => x.Cluster.ID == word.Cluster.ID && x.Clusterline == null) .Where(x => x == word || x.Rectangle.Top + (x.Rectangle.Height / 2) * 1.2 < word.Rectangle.Bottom) .ToList(); if (inTheSameLine.Count == 0) { throw new Exception("A) No words in word line"); } wordLines.Add(word, inTheSameLine); } int index = 0; while (newWordList.Count > 0) { MappedWord WordTop = newWordList.FirstOrDefault(x => x.Rectangle.Height < wordHeight * 2); if (WordTop == null) { WordTop = newWordList.First(); } var baseWords = wordLines[WordTop].Where(x => x.Clusterline == null).ToList(); if (baseWords.Count == 0) { // Bad word throw new Exception("B) No words in word line"); } FieldClusterLine FieldLine = new FieldClusterLine(); FieldLine.ID = index++; FieldLine.Fields = wordLines.Where(x => baseWords.Contains(x.Key)) .SelectMany(x => x.Value) .Where(x => x.Clusterline == null) .Distinct() .OrderBy(x => x.Rectangle.Left) .ToList(); newWordList.RemoveAll(a => FieldLine.Fields.Contains(a)); //FieldLine.Fields = newWordList.Where(a => WordTop.Line.Words.Contains(a)).ToList().OrderBy(b => b.Rectangle.X).ToList(); // FieldLine.Fields = newWordList.Where(a => (a.Rectangle.Top <= (WordTop.Rectangle.Top + (WordTop.Rectangle.Height * PrecentAsLine)))).ToList().OrderBy(b=>b.Rectangle.X).ToList(); FieldLine.Fields.ForEach(a => a.Clusterline = FieldLine); result.Add(FieldLine); } return(result); }
public bool isClusterMatch(fieldClusterModel clusterin) { return(false);// Enumerable.SequenceEqual(Fields.OrderBy(a => a.Name).Select(a => a.Name), clusterin.fields.OrderBy(a => a.Name).Select(a => a.Name)); }