Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sentence generator using Thesaurus

Tags:

c#

thesaurus

I am creating an application in .NET.

I got a running application name http://www.spinnerchief.com/. It did what I needed it to do but but I did not get any help from Google. I need functional results for my application, where users can give one sentence and then the user can get the same sentence, but have it worded differently.

Here is an example of want I want.

Suppose I put a sentence that is "Pankaj is a good man." The output should be similar to the following one:

Pankaj is a great person.
Pankaj is a superb man.
Pankaj is a acceptable guy.
Pankaj is a wonderful dude.
Pankaj is a superb male.
Pankaj is a good human.
Pankaj is a splendid gentleman

like image 383
Pankaj Mishra Avatar asked Sep 21 '10 14:09

Pankaj Mishra


2 Answers

To do this correctly for any arbitrary sentence you would need to perform natural language analysis of the source sentence. You may want to look into the SharpNLP library - it's a free library of natural language processing tools for C#/.NET.

If you're looking for a simpler approach, you have to be willing to sacrifice correctness to some degree. For instance, you could create a dictionary of trigger words, which - when they appear in a sentence - are replaced with synonyms from a thesaurus. The problem with this approach is making sure that you replace a word with an equivalent part of speech. In English, it's possible for certain words to be different parts of speech (verb, adjective, adverb, etc) based on their contextual usage in a sentence.

An additional consideration you'll need to address (if you're not using an NLP library) is stemming. In most languages, certain parts of speech are conjugated/modified (verbs in English) based on the subject they apply to (or the object, speaker, or tense of the sentence).

If all you want to do is replace adjectives (as in your example) the approach of using trigger words may work - but it won't be readily extensible. Before you do anything, I would suggest that you clearly defined the requirements and rules for your problem domain ... and use that to decide which route to take.

like image 130
LBushkin Avatar answered Oct 22 '22 10:10

LBushkin


For this, the best thing for you to use is WordNet and it's hyponym/hypernym relations. There is a WordNet .Net library. For each word you want to alternate, you can either get it's hypernym (i.e. for person, a hypernym means "person is a kind of...") or hyponym ("X is a kind of person"). Then just replace the word you are alternating.

You will want to make sure you have the correct part-of-speech (i.e. noun, adjective, verb...) and there is also the issue of senses, which may introduce some undesired alternations (sense #1 is the most common).

like image 26
msbmsb Avatar answered Oct 22 '22 10:10

msbmsb