views:

120

answers:

4

Hi

We have a requirement in which we need to change change the words or phrases in the sentence while keeping its meaning intact. This application is going to provide suggestions to users who are involved in copy-writing.

I don't know where should I start... we have not yet finalized the technology but would like to do it in a Python or in .Net.

A: 

Some combination of synonyms and Markov chains might work, but you'll always get strange results. Don't expect a program to make better phrases than humans.

Ivo van der Wijk
+10  A: 

Just for laughs:

import urllib2
import urllib
import sys
import json

def translate(text,lang1,lang2):
    base_url='http://ajax.googleapis.com/ajax/services/language/translate?'    
    langpair='%s|%s'%(lang1,lang2)
    params=urllib.urlencode( (('v',1.0),
                       ('q',text.encode('utf-8')),
                       ('langpair',langpair),) )
    url=base_url+params
    content=urllib2.urlopen(url).read()
    try:
        trans_dict=json.loads(content)
    except AttributeError:
        try:
            trans_dict=json.load(content)    
        except AttributeError:
            trans_dict=json.read(content)
    return trans_dict['responseData']['translatedText']

languages='de da nl zh-tw ko es pt el'.split()
text=(' '.join(sys.argv[1:])).decode('utf-8')

for lang in languages:
    result=translate(text,'en',lang)
    result=translate(result,lang,'en')
    print(result)
    print

Running

test.py "Hi, We have a requirement in which we need to change the words or phrases in the sentence while keeping its meaning intact."

yields

Hi, we have a commitment in which we have to change the words or phrases in a sentence while preserving its meaning.

Hello, We have a requirement where we need to change words or phrases in the sentence while keeping its meaning intact.

Hi, We have a requirement we need the words or phrases within the meaning while changing its meaning intact.

Hey, we have a requirement, we need to change the word or phrase in the sentence meaning, while maintaining its integrity.

Hi, we maintain that we need to change the word or phrase in the sentence requirements have meant that literally.

Hello, We have a requirement that we must change the words or phrases in the sentence, keeping intact its meaning.

Hi, we have an obligation that we need to change words or phrases in the sentence, keeping intact its meaning.

Hello, We have a requirement where we need to change the words or phrases in the sentence, while keeping intact the concept.

unutbu
This is nice one, I liked it...
Software Enthusiastic
Good job! I would have tried synonym substion with WordNet, and wouldn't have thought of two-way translation as the solution to this one.
Ken Bloom
@Ken Bloom, I am just thinking about that approach only...
Software Enthusiastic
Any idea how to detect Nouns from sentences?
Software Enthusiastic
@Software Enthusiastic: run a part of speech tagger, like the Stanford POS tagger, OpenNLP, or the one in NLTK.
Ken Bloom
A: 

If you are looking for computer aid, where the software provides suggestions for solutions or part of solutions, I think to provide automated thesaurus lookup for the content words in each sentence would be a good start. Just use a stop-word list to filter out uninteresting words. Translation Memory is a related concept, where NLP is used to aid in translation, I'm sure you can get ideas for the user-interface etc. from this. There are several open source solutions available.

If you want a totally unsupervised process, I think parsing into some semantic representation and changing some content words based on WordNet for example, and then generate from this is perhaps the theoretically cleanest approach. If only grammatical restructuring is okay then drop the changing. The quality, however, will most probably be low. If you only need this for a narrow field, it is possible to do a lot of tailoring, and making quite good results possible.

johanbev
A: 

Use nltk in python. Access to part-of-speech tagging and wordnet, both of which will be necessary to make reasonable substitutions.

http://www.nltk.org/

muckabout
Yeah, I am planning to use nltk sdk with corpus wordnet corpus...
Software Enthusiastic
A verb inflector and noun pluralizer will also be important if you're using WordNet.
Ken Bloom