开发者

Changing the words keeping its meaning intact [closed]

开发者 https://www.devze.com 2023-01-13 05:56 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_运维百科 Closed 9 years ago.

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.


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.


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/


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消