-
Jan 27th, 2017, 02:27 AM
#1
Thread Starter
Lively Member
Dictionaries not being searched well
I have a problem with searching Dictionaries in my program. If I begin a search with Dictionary 0, the search does not look for all possible matches completely in the RichTextBox, but skips to the next Dictionary. How can I solve this? I have created a video of how this problem is happening. Please help, not even one programmer in upwork could solve this problem. Can Microsoft help? Here is the video: https://yadi.sk/i/WWR3E57e3BBJWf
Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim i As Integer
Do While i < 7
Dim fileName As String = String.Format("dictionary{0}.txt", i)
If i > 7 Then
Exit Do
End If
Using reader As New StreamReader("C:\Users\Acer\Desktop\WindowsApplication3\WindowsApplication3\App_Data\" + fileName)
Do Until reader.EndOfStream
Dim parts = reader.ReadLine().Split("|"c)
' prepare replacement dictionary object from file content
If replacements.ContainsKey(parts(0)) Then
replacements(parts(0)).Add(parts(1))
Else
Dim newWordList As New List(Of String)
newWordList.Add(parts(1))
replacements.Add(parts(0), newWordList)
End If
Loop
End Using
i += 1
Loop
End Sub
-
Jan 27th, 2017, 10:04 AM
#2
Re: Dictionaries not being searched well
I don't think anyone is going to watch a video for a programming question.
Describe what your code is supposed to do, what kind of input files you use and what the actual problem is.
Using written text, no video instruction.
-
Jan 27th, 2017, 11:06 AM
#3
Re: Dictionaries not being searched well
The code shown will loop through the file until the end of file is found. If you feel that it is not really looping through the entire file, then there is an end of file somewhere in the middle of the file in question. After all, it's not quitting because it gets bored, or something like that. The only way to get out of the Do...Until loop is for the condition to be met.
So, there are two things you might look at. The first is that it IS going through the whole file, any you're mistaken as to what is in the whole file. The second is that it is not going through the whole file because there's an end of file marker in the middle. You could step through the code and look for either one, but that could be pretty boring, so you could add some variables to hold the number of lines read from the file, or maybe the last line read from the file, then add code to stop when that line is read such that you only need to step through that final line.
My usual boring signature: Nothing
-
Jan 31st, 2017, 03:42 AM
#4
Thread Starter
Lively Member
Re: Dictionaries not being searched well
Shaggy Hiker
The replacement dictionary is of type:
Code:
Private replacements As New Dictionary(Of String, List(Of String))
Last edited by nqioweryuadfge; Jan 31st, 2017 at 03:47 AM.
-
Jan 31st, 2017, 03:46 AM
#5
Thread Starter
Lively Member
Re: Dictionaries not being searched well
Arnoutdv
The code is supposed to ensure that the whole file has been checked for matches before it moves to the next file. It should repeat the search to check if all matches have been checked.
-
Jan 31st, 2017, 04:28 AM
#6
Re: Dictionaries not being searched well
How does your input file look like?
You are splitting the words on "|" in an array.
The first element of the array is the Key the other element the Value
Is the dictionary not filled with data after all files have been read?
Is the dictionary filled with the correct data?
You als mention a RichTextBox, I don't see any reference to a RichTextBox in the submitted code.
-
Jan 31st, 2017, 10:29 AM
#7
Re: Dictionaries not being searched well
Originally Posted by nqioweryuadfge
Shaggy Hiker
The replacement dictionary is of type:
Code:
Private replacements As New Dictionary(Of String, List(Of String))
Well, yeah I could see that, but based on what you asked, that didn't seem to be relevant to the problem. The code you showed was about filling a dictionary, so I assumed that you were actually having trouble filling the dictionary correctly. You DO mention searching the dictionaries, but there appears to be only one dictionary, and as Arnoutdv said, there is no mention of a RichTextBox.
Basically, I don't know what the actual question is. You're going to have to be more clear about it.
My usual boring signature: Nothing
-
Jan 31st, 2017, 01:01 PM
#8
Re: Dictionaries not being searched well
This is the fourth or fifth thread on this the OP has...
I'm not sure where the disconnect is... I thought it had been resolved.
here's what I've been able to piece together:
1) there's multiple Dictionary FILES (Dict1.txt -Dict5.txt)... that are piped delimited with value pairs.... Apple|Fruit
2) He loops through one file, pulls in the data, splits it, and adds the values to the dictionary object.
3) Somewhere there's text he loops through, looking for keys and replacing it with value (so apple becomes fruit)....
4) BUT ... let's say the first replace is apple|fruit and then later he has kumquat|apple .... so all apples are replaced by fruit and then all kumquats are replaced by apple ... which is as expected...
5) the process needs to re-start back at the beginning so it replaces the new apple with fruit... in short kumquat needs to be fruit by way of apple.
6) THEN and only then should it proceed to Dict2.txt
Pull up some of the other threads by the OP... there's at least 2, possibly 3 all on this subject... I thought I had him going in the right direction, but clearly not, so I've given up.
-tg
-
Jan 31st, 2017, 04:23 PM
#9
Re: Dictionaries not being searched well
I assume it's a very stupid advice to say get the replace dictionaries correct isn't it?
apple -> fruit
kumquat -> apple : WRONG
kumquat -> fruit
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|