开发者

Convert plural nouns into singular nouns

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 1开发者_如何学Go2.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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜