Title Back Colour Keyoti Title Line Title Curve
Blue Box Top

Usage of System.IO.MemoryStream as a UserDictionary source - RapidSpell Web ASP.NET - Forum

Welcome Guest Search | Active Topics | Log In | Register

Options
Cardagant
#1 Posted : Thursday, January 4, 2018 2:25:35 PM
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.
Jim
#2 Posted : Thursday, January 4, 2018 5:35:27 PM
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!


Cardagant
#3 Posted : Thursday, February 8, 2018 7:49:53 PM
Rank: Member

Groups: Registered

Joined: 11/21/2017
Posts: 16
Location: Ukraine
Thanks! Your answer was really helpful!
Cardagant
#4 Posted : Friday, March 23, 2018 5:47:12 PM
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.
Jim
#5 Posted : Friday, March 23, 2018 8:56:15 PM
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!


Cardagant
#6 Posted : Friday, March 23, 2018 10:57:21 PM
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.
Jim
#7 Posted : Saturday, March 24, 2018 1:32:57 AM
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

Code:

wordList.Sort();


It uses BinarySearch now so it's important that the list is sorted.

Best
Jim

-your feedback is helpful to other users, thank you!


Cardagant
#8 Posted : Monday, March 26, 2018 10:55:39 AM
Rank: Member

Groups: Registered

Joined: 11/21/2017
Posts: 16
Location: Ukraine
Hi Jim,

Your solution works in my case.

Thank you very much!
Jonathansmith
#9 Posted : Thursday, July 5, 2018 6:10:06 AM
Rank: Guest

Groups:

Message was deleted by Moderator.
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.




About | Contact | Site Map | Privacy Policy

Copyright © 2002- Keyoti Inc.