|
Rank: Member
Groups: Registered
Joined: 11/21/2017 Posts: 16 Location: Ukraine
|
Hi all,
I was wondering if someone can help me with the following:
I need to use a custom user dictionary, but all that I have is a memory stream of a file with words.
UserDictionary's Constructor requires file path, therefore, file with words must be saved either locally or be available by path. Keyoti.RapidSpell.UserDictionary ud = new Keyoti.RapidSpell.UserDictionary('filePath\Dict.txt');
after that the dictionary instance should be set as a user dictionary in spell cheker: checker.SetUserDictionary(ud);
So, is there any chance to use a memory stream as a source for UserDictionary object without saving it to file?
Thanks in advance.
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Hi, if you write a subclass like that in this example https://keyoti.com/kb/De...uestId=128&catId=55 you won't have to specify a filepath, and can load/save it to your stream. I'm assuming you will be writing to the stream when the Add button is clicked. Jim -your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 11/21/2017 Posts: 16 Location: Ukraine
|
Thanks! Your answer was really helpful!
|
|
Rank: Member
Groups: Registered
Joined: 11/21/2017 Posts: 16 Location: Ukraine
|
Hi Jim,
Some time ago I asked you about usage of memoryStream as a user dictionary source and you advised to inherit UserDictionary class and do processing of MemoryStream storage in it.
I implemented such inheritor, but for some reason after I have applied a new version of Spell check (5.3) (it might be not related to the issue, but the code was not changed), an unexpected behavior appeared.
I am filling wordList variable of my child class that inherits UserDictionary with three words from file:
JSmith IGoblet jblack
and I can see that when I set my inheritor as a user dictionary it already includes the mentioned words (without any unexpected characters) in it. (I am doing that with SetUserDictionary() method of Keyoti.RapidSpell.RapidSpellChecker class).
Additionally, I am enabling flag SetIncludeUserDictionaryInSuggestions to have the words as proposals.
After that I am trying to check the following string:
"IGoblet and JSmith jblack and Jblack"
In this case, I am getting results that the word "JSmith" is an error, but at the same time, I have absolutely the same word as a proposal for this error.
If I have only "JSmith" word in user dictionary, the string is checked correctly.
The question is: is it enough to add the words to wordList list or I need to do something else at the moment to make it work? You might have some thoughts on that and if you do, please, share those with me.
A piece of code that is used to load words from stream attached below:
using System; using System.Text; using System.Collections; using System.IO; using Keyoti.RapidSpell;
namespace CustomKeyoti { public class CustomUserDictionary : UserDictionary { ArrayList wordList; MemoryStream stream;
protected void loadWordsFromStream() { wordList = new ArrayList();
var reader = new StreamReader(this.stream);
for (string line = reader.ReadLine(); line != null; line = reader.ReadLine()) { wordList.Add(line); } }
public CustomUserDictionary(MemoryStream stream) { // Read words from stream to arraylist if (stream == null) { throw new ArgumentException("Parameter cannot be null", "stream"); }
this.stream = stream;
this.loadWordsFromStream(); }
... // code for adding / removing words etc.
}
Thanks in advance.
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Hi, what does the ReadAll method look like? Also which version were you using before? I can double check the change and make sure we didn't inadvertently break it. Jim -your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 11/21/2017 Posts: 16 Location: Ukraine
|
Thank you very much for the response.
The code of ReadAll method:
public override int ReadAll(ArrayList a) { a.Clear();
a.AddRange(wordList);
return a.Count; }
The previous version we used was 3.8.
I would be grateful for that. Thanks in advance.
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Ok, in ReadAll can you add this line before AddRange It uses BinarySearch now so it's important that the list is sorted. Best Jim -your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 11/21/2017 Posts: 16 Location: Ukraine
|
Hi Jim,
Your solution works in my case.
Thank you very much!
|
|
Rank: Guest
Groups:
|
Message was deleted by Moderator.
|
|