Hello, I'm facing a strange problem. I have a word for example "ABCDE". I want to match this word againsta sentence like "ABC EFGH IJKL DE". As you can see, the query word is splited and distributed across the senetence. How can I design algorithm which can give me result like the query word has acombination in the sentence and their position. An example; QUERY word: ABCDEF TARGET sentence: EFGH UIOP ABC GHY JKLU EF I expect the output as the query word has a perfect match by the combining words 3,6. I tried several algorithms like smithwatermann, levenstein distance and others, but I could figure out how I can compare string with randomly distributed sub-strings in a sentence. One way of doing is, breaking sentence into words and make all possible combinations and start matching with query which would take forever if I have 500 words. Any help or suggestion would be highly appreciated.
asdf23211
Posts
-
Algorithm for comparing word with randomly distributed substring -
Algorithm for comapring word with randomly distributed substringHello, I'm facing a strange problem. I have a word for example "ABCDE". I want to match this word againsta sentence like "ABC EFGH IJKL DE". As you can see, the query word is splited and distributed across the senetence. How can I design algorithm which can give me result like the query word has acombination in the sentence and their position. An example; QUERY word: ABCDEF TARGET sentence: EFGH UIOP ABC GHY JKLU EF I expect the output as the query word has a perfect match by the combining words 3,6. I tried several algorithms like smithwatermann, levenstein distance and others, but I could figure out how I can compare string with randomly distributed sub-strings in a sentence. One way of doing is, breaking sentence into words and make all possible combinations and start matching with query which would take forever if I have 500 words. Any help or suggestion would be highly appreciated.
-
pattern/string matching algorithmI think this should be common problem in Computer science. I have a data like this
List>> Qdata = new ArrayList>>();//QUERY
List>> Tdata = new ArrayList>>();//TARGETList Qg1 = Arrays.asList("C", "A", "PC", "R"); List Qg2 = Arrays.asList("DQ", "EQ", "KC", "AC"); List Qg3 = Arrays.asList("KQ", "AT"); List Qg4 = Arrays.asList("KQ", "AT", "DQ", "KC","AC","KQ", "AT", "KC","AC","KQ", "AT", "DQ", "KC","AC"); List Qg5 = Arrays.asList("KQ", "AT", "DQ", "KC","AC"); List Qg6 = Arrays.asList("KQ", "AT", "DQ", "KC","AC"); List Qg7 = Arrays.asList("AC","KQ", "AT","AT", "DQ", "KC","AC"); Map\> Qmap = new HashMap\>(); Qmap.put(1, Qg1); Qmap.put(2, Qg2); Qmap.put(3, Qg3); Qmap.put(4, Qg4); Qmap.put(5, Qg5); Qmap.put(6, Qg6); Qmap.put(7, Qg7); List Tg1 = Arrays.asList("C", "A", "PC", "?"); List Tg2 = Arrays.asList("KQ", "AT","DQ", "EQ", "KC", "AC"); List Tg3 = Arrays.asList("AT", "DQ", "KC","AC"); List Tg4 = Arrays.asList("KQ", "AT", "DQ", "KC","AC","KQ", "AT", "KC","AC"); List Tg5 = Arrays.asList("KQ", "AT", "DQ", "KC","AC"); List Tg6 = Arrays.asList("KQ", "AT", "DQ", "KC","AC"); List Tg7 = Arrays.asList("AT","AT", "DQ", "KC","AC"); List Tg8 = Arrays.asList("AC"); List Tg9 = Arrays.asList("ACL","AC","C","A","PC"); Map\> Tmap = new HashMap\>(); Tmap.put(1, Tg1); Tmap.put(2, Tg2); Tmap.put(3, Tg3); Tmap.put(4, Tg4); Tmap.put(5, Tg5); Tmap.put(6, Tg6); Tmap.put(7, Tg7); Tmap.put(8, Tg8); Tmap.put(9, Tg9); Qdata.add(Qmap); Tdata.add(Tmap)
want to match Qdata with Tdata, the tricky part here is, if you observe the data Qg3+Qg2 forms Tg2 Tg4+Tg3 forms Qg4 with "kQ" missing between Tg4 and Tg3 Tg8+Tg9 forms Qg7 and with the rest, it is pretty straight forward. I don't know how to deal with this tricky part. I used map to store the data because it is more desired for the algorithm to finds matching in the same position in Tdata and Qdata like Qg5 has a complete match with Tg5 Qg6 has a complete match with Tg6 The final ideal output that I expect in this case is: Qg1 matches with Tg1
-
Pass dynamic datagridview value to textboxI have a code which generated dynamic gridviews based on a column ('c_AnalyticalSystemID"). Now I have a samll problem in passing cell parameter into a textbox which I clicked on a datagridview. the code is : private void button1_Click(object sender, EventArgs e) { string query = "select t.c_AnalyticalSystemID,t.c_RetentionTime,t.c_IonType , t.c_MSstage, k.c_MSstage, t.c_IonFormula, k.c_IonCharge, t.c_IonMass as 'Mass', t.c_MinArea, t.c_UserID_stamp,c_Time_Stamp,k.c_IonTypeRule from C_Analytical_Type1 t join C_AnalyticalSystems c on t.c_analyticalsystemid = c. c_analyticalsystemid join C_Analytical_Type1_IonTypes k on k.c_iontype = t.c_iontype where t.c_id=" + Convert.ToInt32(textBox1.Text.ToString()) + ""; DataTable dt_cmbo_ = new DataTable(); OdbcDataAdapter cmbo_ = new OdbcDataAdapter("SELECT c_IonCharge,c_IonType,c_IonTypeExplained from C_Analytical_Type1_IonTypes", OdbcCon); dt_cmbo_.Columns.Clear(); dt_cmbo_.Rows.Clear(); cmbo_.Fill(dt_cmbo_); OdbcCommand cmd = new OdbcCommand(query, OdbcCon); OdbcDataReader dr = cmd.ExecuteReader(); DataTable dt1 = new DataTable(); dt1.Load(dr); int margin = 30; Point pt = new Point(margin, margin); panel1.Controls.Clear(); DataTable distinctSystemIDs = dt1.DefaultView.ToTable(true, "c_AnalyticalSystemID"); // DataTable ion = dt.DefaultView.ToTable(true, "c_IonTypeExplained"); for (int i = 0; i <= distinctSystemIDs.Rows.Count -1; i++) { int systemID = (int)distinctSystemIDs.Rows[i][0]; DataGridView dgw = new DataGridView(); Label l = new Label(); l.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; l.Location = pt; l.Text = "System " + systemID.ToString(); pt.Y += l.Height + 2; // margin is for spacing between grids dgw.Tag = systemID; // store systemID of the DGV if you need it later dgw.AllowUserToAddRows = false; dgw.AllowUserToDeleteRows = false; dgw.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; dgw.Size = new Size(730, 100); // 2 * margin = left + right margin dgw.Location = pt;
-
controls in richtextboxHi, I have got a serious problem. I have connect a table with the windows form. The table looks like Id name age place country 1 sss 11 ttt qqq 2 ww 12 eee qqq Now I'm able to display all of them in a richtextbox in the following format whose country = qqq 1. Id ="1" Name = "sss" age =11 place = "ttt" country = "qqq" 2. Id ="2" Name = "ww" age =12 place = "eee" country = "qqq" now i add a linklabel control to the textbox. the text of the linklabel wiill be the result of Name column when on click it is linked to a webpage. here my problem is it is not scrolling along with text. this is how my code looks : public void button3_Click(object sender, EventArgs e) { OdbcCommand bcC2 = new OdbcCommand(); bcC2.CommandText = "select * from C_RefCitation where c_id like ('" + textBox5.Text + "')"; bcC2.Connection = OdbcCon; DataSet q3 = new DataSet(); OdbcDataAdapter db1A2 = new OdbcDataAdapter(bcC2); db1A2.Fill(q3); dataGridView1.DataSource = q3.Tables[0]; richTextBox2.Visible = true; richTextBox2.Clear(); for (int x = 0; x < dataGridView1.Rows.Count - 1; x++) { richTextBox2.AppendText((x + 1).ToString() + ". "); for (int y = 0; y < dataGridView1.Columns.Count; y++) { richTextBox2.AppendText("\n"); richTextBox2.AppendText(dataGridView1.Columns[y].HeaderText); richTextBox2.AppendText(" : "); if (dataGridView1.Columns[y].HeaderText.ToString() == "c_CitationDOI") { this.richTextBox2.SelectionStart = this.richTextBox2.TextLength; int index = richTextBox2.Text.Length; Point position = richTextBox2.GetPositionFromCharIndex(index); LinkLabel label = new System.Windows.Forms.LinkLabel(); RichTextBox sri = new System.Windows.Forms.RichTextBox(); label.Text = dataGridView1.Rows[x].Cells[y].Value.ToString(); label.AutoSize = true; label.Location = new Point(0,position.Y); label.LinkBehavior = LinkBehavior.NeverUnderline; richTextBox2.Controls.Add(label); richTextBox2.AppendText(label.Text); label.Links.Add(1, 7, dataGridView1.Rows[x].Cells[y].Value.ToString()); label.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.label_LinkClicked); } else { richTextBox2.AppendText(dataGridView1.Rows[x].Cells[y].Value.ToString()); } if (y != dataGridView1.Columns.Count - 1) { richTextBox2.AppendText(", "); } } richTextBox2.AppendText("\n\n\n "); } } please help me in modifying this code so that the controls scroll along with text box. Thank you very much