473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Thesaurus Implementation

Hi Everybody!

Hoping that every body would be fine at this group.

I am learning c sharp. Please, if anybody can make this program, i
would be highly obliged.

Implement a thesaurus (a dictionary of synonyms) that implements the
IThesaurus interface
Interface IThesaurus
{
// Adds a word and its synonyms to the thesaurus
void AddWord(string word, string[] synonyms);
// Removes a word from the thesurus
void RemoveWord(string word);
// Find the synonyms associated with a word
string[] FindSynonyms(string word);
// Returns a sorted list of all the words in the //thesaurus
string[] WordList();
}
Discuss your implementation. What kind of performance can you expect
from the operations? What should be done to make it threadsafe?

Thanks in Advance.

John

Sep 16 '06 #1
8 7837
Hi,

Did you try by yourself first ?
Nobody here will do a program your asked to do but we can help.
Try to use a hashtable in order to store the data.

Good work,

Martin

<jo*******@gmail.coma écrit dans le message de news:
11*********************@d34g2000cwd.googlegroups.c om...
Hi Everybody!

Hoping that every body would be fine at this group.

I am learning c sharp. Please, if anybody can make this program, i
would be highly obliged.

Implement a thesaurus (a dictionary of synonyms) that implements the
IThesaurus interface
Interface IThesaurus
{
// Adds a word and its synonyms to the thesaurus
void AddWord(string word, string[] synonyms);
// Removes a word from the thesurus
void RemoveWord(string word);
// Find the synonyms associated with a word
string[] FindSynonyms(string word);
// Returns a sorted list of all the words in the //thesaurus
string[] WordList();
}
Discuss your implementation. What kind of performance can you expect
from the operations? What should be done to make it threadsafe?

Thanks in Advance.

John

Sep 17 '06 #2
This is the code i tried so far, but it is giving error.

using System;
using System.Collections;

namespace Thesaurus
{

public interface IThesaurus
{
// Adds a word and its synonyms to the thesaurus
void AddWord(string word, string[] synonyms);
// Removes a word from the thesurus
void RemoveWord(string word);
// Find the synonyms associated with a word
string[] FindSynonyms(string word);
// Returns a sorted list of all the words in the //thesaurus
string[] WordList();
}

public class ImpIThesaurus:IThesaurus
{
#region IThesaurus Members
public Hashtable ThesDict;

public ImpIThesaurus()
{
ThesDict = new Hashtable();
}
public void AddWord(string word, string[] synonyms)
{
for ( int i = 0; i < (synonyms.Length - 1); i++ )
{
ThesDict.Add(word,synonyms[i]);
}
}

public void RemoveWord(string word)
{
// TODO: Add ImpIThesaurs.RemoveWord implementation
}

public string[] FindSynonyms(string word)
{
// TODO: Add ImpIThesaurs.FindSynonyms implementation
return null;
}

public string[] WordList()
{
// TODO: Add ImpIThesaurs.WordList implementation
return null;
}

#endregion

}

/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ImpIThesaurus trs = new ImpIThesaurus();
string[] list = {"a","b","c"};
trs.AddWord("A",list);

//
// TODO: Add code to start application here
//
}
}
}

Martin CLAVREUIL wrote:
Hi,

Did you try by yourself first ?
Nobody here will do a program your asked to do but we can help.
Try to use a hashtable in order to store the data.

Good work,

Martin

<jo*******@gmail.coma écrit dans le message de news:
11*********************@d34g2000cwd.googlegroups.c om...
Hi Everybody!

Hoping that every body would be fine at this group.

I am learning c sharp. Please, if anybody can make this program, i
would be highly obliged.

Implement a thesaurus (a dictionary of synonyms) that implements the
IThesaurus interface
Interface IThesaurus
{
// Adds a word and its synonyms to the thesaurus
void AddWord(string word, string[] synonyms);
// Removes a word from the thesurus
void RemoveWord(string word);
// Find the synonyms associated with a word
string[] FindSynonyms(string word);
// Returns a sorted list of all the words in the //thesaurus
string[] WordList();
}
Discuss your implementation. What kind of performance can you expect
from the operations? What should be done to make it threadsafe?

Thanks in Advance.

John
Sep 19 '06 #3
johner...@gmail.com wrote:
This is the code i tried so far, but it is giving error.
Yes, because you can only have any particular key once in a hashtable.
You'll need to make the value for the entry the array of strings, or a
list, or something like that.

Jon

Sep 19 '06 #4
Hi,

Thanks for the instant reply.

I am not allowed to do that. I have to follow the interface only.
Therefore, i cannot use string array for one value. Thus, i have no
clue what to do.

Please if anyone can help me out.

John
Jon Skeet [C# MVP] wrote:
johner...@gmail.com wrote:
This is the code i tried so far, but it is giving error.

Yes, because you can only have any particular key once in a hashtable.
You'll need to make the value for the entry the array of strings, or a
list, or something like that.

Jon
Sep 19 '06 #5
johner...@gmail.com wrote:
Thanks for the instant reply.

I am not allowed to do that. I have to follow the interface only.
Therefore, i cannot use string array for one value. Thus, i have no
clue what to do.

Please if anyone can help me out.
The interface doesn't specify how you have to implement it. You could
easily follow the interface and use an array (or an ArrayList) as the
value in your hashtable, copying contents where necessary. How you
store things internally doesn't have to have an impact on how you
expose the data to the outside world.

Jon

Sep 19 '06 #6
Hi Jon,

I have implemented the method like this now:

public void AddWord(string word, string[] synonyms)
{
string[] wrd = new string[synonyms.Length];

for ( int i = 0; i < (synonyms.Length - 1); i++ )
{
wrd[i] = word;
ThesDict.Add(wrd[i],synonyms[i]);
}
}

But it still give error.

An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll

Additional information: Item has already been added. Key in
dictionary: "A" Key being added: "A"

The program '[3064] Thesaurus.exe' has exited with code 0 (0x0).


Jon Skeet [C# MVP] wrote:
johner...@gmail.com wrote:
Thanks for the instant reply.

I am not allowed to do that. I have to follow the interface only.
Therefore, i cannot use string array for one value. Thus, i have no
clue what to do.

Please if anyone can help me out.

The interface doesn't specify how you have to implement it. You could
easily follow the interface and use an array (or an ArrayList) as the
value in your hashtable, copying contents where necessary. How you
store things internally doesn't have to have an impact on how you
expose the data to the outside world.

Jon
Sep 19 '06 #7
Hi Jon,

I have implemented the method like this now:

public void AddWord(string word, string[] synonyms)
{
string[] wrd = new string[synonyms.Length];

for ( int i = 0; i < (synonyms.Length - 1); i++ )
{
wrd[i] = word;
ThesDict.Add(wrd[i],synonyms[i]);
}
}

But it still give error.

An unhandled exception of type 'System.ArgumentException' occurred in
mscorlib.dll

Additional information: Item has already been added. Key in
dictionary: "A" Key being added: "A"

The program '[3064] Thesaurus.exe' has exited with code 0 (0x0).


Jon Skeet [C# MVP] wrote:
johner...@gmail.com wrote:
Thanks for the instant reply.

I am not allowed to do that. I have to follow the interface only.
Therefore, i cannot use string array for one value. Thus, i have no
clue what to do.

Please if anyone can help me out.

The interface doesn't specify how you have to implement it. You could
easily follow the interface and use an array (or an ArrayList) as the
value in your hashtable, copying contents where necessary. How you
store things internally doesn't have to have an impact on how you
expose the data to the outside world.

Jon
Sep 19 '06 #8
jo*******@gmail.com wrote:
I have implemented the method like this now:

public void AddWord(string word, string[] synonyms)
{
string[] wrd = new string[synonyms.Length];

for ( int i = 0; i < (synonyms.Length - 1); i++ )
{
wrd[i] = word;
ThesDict.Add(wrd[i],synonyms[i]);
}
}

But it still give error.
Yes, it would - you're still adding the same key multiple times, adding
just a single word each time.

Instead, make a copy of the array (eg into an ArrayList) and call Add a
single time. You'll also need to check for existing values in case
someone calls
Add ("x", firstArray);
Add ("x", secondArray);

Jon

Sep 19 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jaffa | last post by:
hi all, i'm currently designing a search engine. I'd like certain keywords to have affiliated synonyms listed so that I can find out which keywords are symantically related to each other. Is...
0
by: Melody Droid | last post by:
I recently made some conceptual breakthroughs regarding the interval permutation pre-sorting and the pitch-class-set/scale post-sorting aspects of my envisioned symmetrical melody thesaurus...
3
by: Jason | last post by:
Is it possible to connect and asp page to the Microsoft Office Thesaurus? I would like to be able to pass a word to it and get back all of the synonyms as either a string, array, or collection.
1
by: Hans Malherbe | last post by:
I would like to access the Word thesaurus from a .NET WinForm application if the client has Microsoft Word installed. Is it possible? I could not find anything in the Office XP help.
2
by: hammad | last post by:
I had made a .NET Application that use microsoft Word thesaurus using msword file when i made windows application it works well but when i try web application it make exception that i have no...
3
by: Marc | last post by:
Hi everyone, I'm trying to build a Thesaurus. In my thesaurus i've created the following tables: terms, btnt (broader terms/narrower terms), rt (related terms) The structures of the tables...
3
by: moondaddy | last post by:
I'm looking for a thesaurus tool I can use in an application. I was hoping it could be a web service where my app could submit a work and get a list of results back which my code could use. any...
0
by: Piero 'Giops' Giorgi | last post by:
Hi! I have the DB, now with about 100 Million rows (Going strong!!!) One question... I'm using Thesaurus search (COOL!!!) for names, (Rebecca, Reba, Becky, Becca....) to query for nicknames...
0
by: Calvin Spealman | last post by:
Sounds like you might want to read up on RDF On Tue, Aug 12, 2008 at 10:41 AM, Benjamin Michiels <benjamin.michiels@gmail.comwrote: -- Read my blog! I depend on your acceptance of my...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.