将复数名词转换为单数名词

发布于 2024-11-29 03:13:33 字数 836 浏览 1 评论 0原文

如何使用 R 将复数名词转换为单数名词?我使用 tagPOS 函数来标记每个文本,然后提取所有标记为“NNS”的复数名词。但是如果我想将这些复数名词转换为单数该怎么办?


library("openNLP")
library("tm")
acq_o <- "Gulf Applied Technologies Inc said it sold its subsidiaries engaged in pipelines and terminal operations for 12.2 mln dlrs. The company said the sale is subject to certain post closing adjustments, which it did not explain. Reuter."

acq = tm_map(Corpus(DataframeSource(data.frame(acq_o))), removePunctuation)
acqTag <- tagPOS(acq)
acqTagSplit = strsplit(acqTag," ")
qq = 0
tag = 0
for (i in 1:length(acqTagSplit[[1]])){
        qq[i] <-strsplit(acqTagSplit[[1]][i],'/')
        tag[i] = qq[i][[1]][2]
}

index = 0
k = 0
for (i in 1:(length(acqTagSplit[[1]]))) { 
    if (tag[i] == "NNS"){
        k = k +1             
        index[k] = i     
    } 
}
index

How can plural nouns be converted into singular nouns using R? I use the the tagPOS function which tags each text and then extract all of plural nouns which were tagged as "NNS". But what to do in case I want to convert those plural nouns into singular ones.?


library("openNLP")
library("tm")
acq_o <- "Gulf Applied Technologies Inc said it sold its subsidiaries engaged in pipelines and terminal operations for 12.2 mln dlrs. The company said the sale is subject to certain post closing adjustments, which it did not explain. Reuter."

acq = tm_map(Corpus(DataframeSource(data.frame(acq_o))), removePunctuation)
acqTag <- tagPOS(acq)
acqTagSplit = strsplit(acqTag," ")
qq = 0
tag = 0
for (i in 1:length(acqTagSplit[[1]])){
        qq[i] <-strsplit(acqTagSplit[[1]][i],'/')
        tag[i] = qq[i][[1]][2]
}

index = 0
k = 0
for (i in 1:(length(acqTagSplit[[1]]))) { 
    if (tag[i] == "NNS"){
        k = k +1             
        index[k] = i     
    } 
}
index

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

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

发布评论

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

评论(1

坦然微笑 2024-12-06 03:13:33

我确信您可以通过外部程序传输数据,或者用它来预处理数据。

如果您无论如何都要进行标记,德国项目 TreeTagger 会执行以下操作:同时标记和词形还原做得很好。

编辑:tchrist 正确地提醒我,无论您的目的是什么,如果您实际上正在寻找复数名词的单数表面形式,那么寻求自制的解决方案根本不会解决它。

如果你不这样做,那么 Neo_Me(再次在评论中)似乎找到了一个在 R 中进行词干提取的包:包 snowball (RStem 似乎已经停产。AFAICT,Snowball 取代了它。)

当然,这只是 Porter 词干分析器的一个实现或包装。使用风险自负,它将把诸如 wives 之类的东西变成 wif 或类似的东西。

我突然想到,R 有 CRAN。在那里寻找“引理”让我意识到依赖于Java的包 wordnet< /a>.它似乎有一个 getLemma 函数。整个包对你来说可能有点大材小用,但如果你找不到更好的东西,仍然可能让你有所收获。

I'm sure you could pipe your data through an external program, or pre-process your data with it.

If you're doing tagging anyway, the German project TreeTagger does a nice job of tagging and lemmatising at the same time.

EDIT: tchrist was right to remind me that, whatever your purposes, if you're actually looking for the singular surface forms of your plural nouns, going for a home-baked solution isn't going to cut it at all.

And if you don't then Neo_Me (again, in the comments) seems to have found a package that does stemming in R: the package snowball (RStem seems to have been discontinued. AFAICT, Snowball replaces it.)

This is just an implementation or wrapper around the Porter stemmer, of course. Use at your own risk, it is going to stem stuff like wives into wif or something like that.

It just occurred to me, that R has CRAN. Looking for "lemma" there made me aware of the Java-dependent package wordnet. It seems to have a getLemma function. The whole package is likely overkill for you, but might still get you somewhere if you can't find anything better.

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