private List <PossitionOfWord> GetKeysPossitions(int id, Database db = null, bool test = false) { List <PossitionOfWord> list = new List <PossitionOfWord>(); if (db == null) { db = new Database(); } string SQL; if (test) { SQL = $"SELECT TOP 5 * FROM OCR_2018.dbo.T004_Possitions WHERE Pattern_ID = {id} AND (Word_Key NOT LIKE '%Meno%' OR Word_Key NOT LIKE '%Ulica%' OR " + $"Word_Key NOT LIKE '%Psč%' OR Word_Key NOT LIKE '%Štát%') AND K_X != 0 AND K_Y != 0"; } else { SQL = $"SELECT * FROM OCR_2018.dbo.T004_Possitions WHERE Pattern_ID = {id}"; } SqlDataReader data = (SqlDataReader)db.Execute(SQL, CONSTANTS.Operation.SELECT); while (data.Read()) { var pos = new PossitionOfWord(); pos.Key = data[2].ToString(); pos.Value = data[3].ToString(); pos.KeyBounds = new System.Drawing.Rectangle((int)data[4], (int)data[5], (int)data[6], (int)data[7]); pos.ValueBounds = new System.Drawing.Rectangle((int)data[8], (int)data[9], (int)data[10], (int)data[11]); pos.DictionaryKey = data[12].ToString(); list.Add(pos); } data.Close(); db.Close(); return(list); }
private void pictureBox1_MouseUp_1(object sender, MouseEventArgs e) { _isMouseDown = false; _firstMove = true; _resizingBottom = false; _resizingRight = false; if (_drawingNewRect) { if (_newPositions == null) { _newPositions = new PossitionOfWord(); } _drawingNewRect = false; if (!_onlyValue && _countOfNewRect == 2) { _newPositions.KeyBounds = _newRect; } else if (!_onlyValue && _countOfNewRect == 1) { _newPositions.ValueBounds = _newRect; } else if (_onlyValue && _countOfNewRect == 1) { _newPositions.ValueBounds = _newRect; } _countOfNewRect--; if (_countOfNewRect == 0) { _newPositions.Key = cmbKey.SelectedValue.ToString(); if (cmbClientInfo.Visible) { _newPositions.Key += " " + cmbClientInfo.SelectedValue.ToString(); } _newPositions.Value = string.Empty; if (cmbClientInfo.Visible) { _newPositions.DictionaryKey = ((KeyValuePair <string, string>)cmbClientInfo.SelectedItem).Value; } else { _newPositions.DictionaryKey = ((KeyValuePair <string, string>)cmbKey.SelectedItem).Value; } _p.ListOfKeyPossitions.Add(_newPositions); AddRectangle(_newPositions); _newPositions = null; _canDraw = false; panel4.Enabled = true; panel5.Enabled = true; panel6.Enabled = true; } } setRectangle(); FillListView(_p); }
private PossitionOfWord GetSelectedWords() { if (dataGridValues.SelectedRows.Count == 1) { PossitionOfWord b = dataGridValues.SelectedRows[0].DataBoundItem as PossitionOfWord; btnRemove.Enabled = true; return(b); } else { btnRemove.Enabled = false; return(null); } }
/// <summary> /// Function return TextLine where the value should be. Function work only with top edges of line and value rectangle /// </summary> /// <param name="w">Word from database we are looking for</param> /// <returns></returns> private TextLine GetLineForValueBounds(PossitionOfWord w) { var lineLower = _textLines.Where(l => (l.Bounds.Top > w.ValueBounds.Top)).FirstOrDefault(); var lineHigher = _textLines.Where(l => (l.Bounds.Top < w.ValueBounds.Top)).LastOrDefault(); // get overlap according to row above var topExceed = Math.Abs(w.ValueBounds.Y - lineLower.Bounds.Y); var bottomExceed = 0; if (lineLower.Bounds.Bottom < w.ValueBounds.Bottom) { bottomExceed = Math.Abs(w.ValueBounds.Bottom - lineLower.Bounds.Bottom); } var fullContent = w.ValueBounds.Width * w.ValueBounds.Height; var exceedContent = (bottomExceed + topExceed) * w.ValueBounds.Width; var overlayLower = 100.00 - ((float)exceedContent / fullContent) * 100.00; // get overlap according to row below var topExceed2 = Math.Abs(w.ValueBounds.Y - lineHigher.Bounds.Y); var bottomExceed2 = 0; if (lineHigher.Bounds.Bottom < w.ValueBounds.Bottom) { bottomExceed = Math.Abs(w.ValueBounds.Bottom - lineHigher.Bounds.Bottom); } var fullContent2 = w.ValueBounds.Width * w.ValueBounds.Height; var exceedContent2 = (bottomExceed2 + topExceed2) * w.ValueBounds.Width; var overlayHigher = 100.00 - ((float)exceedContent2 / fullContent2) * 100.00; if (overlayLower > overlayHigher) { return(lineLower); } else { return(lineHigher); } }
private void SaveDataToPreviewObject(string key, PossitionOfWord w, PreviewObject prew) { if (prew.Clients.Count > 0) { foreach (Client c in prew.Clients) { if (key.Contains(Common.RemoveDiacritism(c.ClientID))) { Type type = c.GetType(); PropertyInfo prop = type.GetProperty(w.DictionaryKey); prop.SetValue(c, w.Value, null); return; } } } foreach (KeyValuePair <string, string> pair in Dictionary.GetInstance().columns) { var txt = Common.RemoveDiacritism(pair.Key); if (key.Contains(txt)) { var c = new Client(); c.ClientID = txt; Type type = c.GetType(); PropertyInfo prop = type.GetProperty(w.DictionaryKey); prop.SetValue(c, w.Value, null); prew.Clients.Add(c); return; } } // it's an Evidence value Type typeE = prew.Evidence.GetType(); PropertyInfo propE = typeE.GetProperty(w.DictionaryKey); propE.SetValue(prew.Evidence, w.Value, null); }
private void AddRectangle(PossitionOfWord key) { if (key != null) { txtPartConfidence.Text = key.Confidence.ToString(); ClearImageAndText(); System.Drawing.Image img = (System.Drawing.Image)_newImage.Clone(); _newGraphics = System.Drawing.Graphics.FromImage(img); _p.ListOfKeyPossitions.ForEach(c => c.IsActive = false); key.IsActive = true; if (key.KeyBounds.Equals(key.ValueBounds)) { _newGraphics.DrawRectangle(_myPenword, key.ValueBounds); } else { _newGraphics.DrawRectangle(_myPenword, key.KeyBounds); _newGraphics.DrawRectangle(_myPenword, key.ValueBounds); } pictureBox1.Image = img; } }
private void SavePossitionToLists(string key, string stringkey, string value, TextLine Keyline, TextLine valueLine, string colText = "", int x1 = 0, int x2 = 0) { if (!_p.ListOfKeyPossitions.Any(c => c.Key.Equals(key))) { List <Word> tmpKeyWords = new List <Word>(); List <Word> tmpValueWords = new List <Word>(); float conf = 0; int count = 0; tmpKeyWords = GetWordsForPositionSave(Keyline, stringkey, ref conf, ref count); tmpValueWords = GetWordsForPositionSave(valueLine, value, ref conf, ref count, x1, x2); //key PossitionOfWord pk = new PossitionOfWord(); if (stringkey != string.Empty) { var v = tmpKeyWords.First <Word>(); var vl = tmpKeyWords.Last <Word>(); pk.KeyBounds = new System.Drawing.Rectangle(v.Bounds.X, v.Bounds.Y, tmpKeyWords.Last <Word>().Bounds.Right - v.Bounds.Left, v.Bounds.Height); } if (key.Equals("Name") || key.Equals("Street") || key.Equals("PSCCity") || key.Equals("State")) { pk.Key = colText; } else { pk.Key = stringkey; } pk.Value = value; //value if (value == string.Empty || !tmpValueWords.Any()) { pk.ValueBounds = new System.Drawing.Rectangle(pk.KeyBounds.Right, pk.KeyBounds.Y, 100, pk.KeyBounds.Height); } else { var w = tmpValueWords.First <Word>(); if (Keyline == valueLine) { // not a column if (!string.IsNullOrWhiteSpace(value)) { pk.ValueBounds = new System.Drawing.Rectangle(w.Bounds.X, w.Bounds.Y, tmpValueWords.Last <Word>().Bounds.Right - w.Bounds.Left, w.Bounds.Height); } else { var x = w.Bounds.Right; var y = w.Bounds.Y; var width = 0; try { if (stringkey == string.Empty) { width = tmpValueWords.Last <Word>().Bounds.Right - w.Bounds.Left; } else { var vl = tmpKeyWords.Last <Word>(); width = Keyline.Words[Keyline.Words.IndexOf(vl) + 1].Bounds.Left - vl.Bounds.Right; } } catch (ArgumentOutOfRangeException e) { width = w.Bounds.Right + 50; } pk.ValueBounds = new System.Drawing.Rectangle(x, y, width, w.Bounds.Height); } } else { // was looking in column if (!string.IsNullOrWhiteSpace(value)) { pk.ValueBounds = new System.Drawing.Rectangle(w.Bounds.X, w.Bounds.Y, tmpValueWords.Last <Word>().Bounds.Right - w.Bounds.Left, w.Bounds.Height); } else { pk.ValueBounds = new System.Drawing.Rectangle(x1, valueLine.Bounds.Y, x2 - x1, w.Bounds.Height); } } } pk.Confidence = string.Format("{0:N2}%", (conf / count)); pk.DictionaryKey = key; _p.ListOfKeyPossitions.Add(pk); } }