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
Some examples of singular nouns are pen, slate, chalk, bottle, tub, soap, window, phone, cycle, pigeon, chair, game, meal and so on.
A singular noun is a noun that refers to only one person, place, thing, or idea. It's contrasted with plural nouns, which refer to more than one person, place, thing, or idea. An example of a singular noun is cat, which represents one cat; an example of a plural noun is cats, which represents two or more cats.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With