使用同义词库生成句子

发布于 2024-09-24 11:48:00 字数 490 浏览 5 评论 0原文

我正在 .NET 中创建一个应用程序。

我有一个正在运行的应用程序名称 http://www.spinnerchief.com/。它做了我需要它做的事情,但我没有从谷歌得到任何帮助。 我的应用程序需要功能性结果,用户可以给出一个句子,然后用户可以获得相同的句子,但措辞不同。

这是我想要的一个例子。

假设我放了一句话“Pankaj 是个好人”。输出应类似于以下内容:

潘卡杰是一个伟大的人。
Pankaj 是一个出色的人。
Pankaj 是一个可以接受的人。
Pankaj 是一个很棒的家伙。
Pankaj 是一位出色的男性。
Pankaj 是个好人。
Pankaj 是一位出色的绅士

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦开始←不甜 2024-10-01 11:48:00

要对任意句子正确执行此操作,您需要对源句子执行自然语言分析。您可能需要查看 SharpNLP 库 - 它是一个免费的 C#/.NET 自然语言处理工具库。

如果您正在寻找一种更简单的方法,则必须愿意在某种程度上牺牲正确性。例如,您可以创建一个触发词词典,当它们出现在句子中时,它们会被替换为同义词库中的同义词。这种方法的问题是确保用等效的词性替换单词。在英语中,根据句子中的上下文用法,某些单词可能会成为不同的词性(动词、形容词、副词等)。

您需要解决的另一个注意事项(如果您不使用 NLP 库)是词干提取。在大多数语言中,某些词性会根据其适用的主语(或句子的宾语、说话者或时态)进行共轭/修饰(英语动词)。

如果您只想替换形容词(如您的示例中所示),那么使用触发词的方法可能会起作用 - 但它不容易扩展。在你做任何事情之前,我建议你明确定义你的问题域的要求和规则......并用它来决定采取哪条路线。

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.

半暖夏伤 2024-10-01 11:48:00

为此,最适合您使用的是 WordNet 及其下位词/上位词关系。有一个 WordNet .Net 库。对于您想要替换的每个单词,您可以获取它的上位词(即,对于人,上位词意味着“人是一种...”)或下位词(“X 是一种人”)。然后只需替换您要替换的单词即可。

您需要确保您拥有正确的词性(即名词、形容词、动词...),并且还存在语义问题,这可能会引入一些不需要的变化(语义#1 是最常见的) 。

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).

梦在深巷 2024-10-01 11:48:00

我对 .Net 一无所知,但您应该考虑使用字典函数(我确信有一个,或者至少有一个可以简化流程的库(如果没有的话))。

然后,您必须遍历字符串,并省略“is”或“a”等单词。只选取您想要同义词的单词。

之后,让一个循环吐出你的句子就非常简单了。

祝你好运。

I don't know anything about .Net, but you should look into using a dictionary function (I'm sure there is one, or at least a library that streamlines the process if there isn't).

Then, you'd have to go through the string, and ommit words like "is" or "a". Only taking words you want to have synonyms for.

After this, its pretty simple to have a loop spit out your sentences.

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文