Stemming Algorithms for the Portuguese Language

Travis-CI Build Status AppVeyor Build Status Coverage Status CRAN_Status_Badge

This packages wraps 3 stemming algorithms for the portuguese language available in R. It unifies the API for the stemmers and provides easy stemming completion.

Installing

You can install directly from Github using:

devtools::install_github("dfalbel/ptstem")

or from CRAN using:

Using

Consider the following text, extracted from Stemming in Wikipedia

This will use the rslp algorithm to stem the text.

You can complete stemmed words using the argument complete = T.

ptstem(text, algorithm = "rslp", complete = TRUE)

The other implemented algorithms are:

  • hunspell: the same algorithm used in OpenOffice corrector. (available via hunspell package)
  • porter: available via SnowballC package.

You can stem using those algorithms by changing the algorithm argument in ptstem function.

library(ptstem)
ptstem(text, algorithm = "hunspell")
#> [1] "Em morfologia linguística e recuperação de informação a stemização (do inglês, stemização) é\no processo de reduzir palavras flexionadas (ou às vezes derivadas) ao seu tronco (stemização), base ou\nraiz, geralmente uma forma da palavras escrita. O tronco não precisa ser idêntico à raiz morfologia\nda palavras; ele geralmente é suficiente que palavras relacionadas ser mapeadas para o mesmo\ntronco, mesmo se este tronco não for ele próprio uma raiz válida. O estudo de algoritmos para\nstemização tem ser realizado em ciência da computação desde a década de 60. Vários motores de\nbuscas tratam palavras com o mesmo tronco como sinônimos como um tipo de expansão de consulta, em\num processo de combinação."
ptstem(text, algorithm = "porter")
#> [1] "Em morfologia linguística e recuperação de informação a stemização (do inglês, stemming) é\no processo de reduzir palavras flexionadas (ou às vezes derivadas) ao seu tronco (stem), base ou\nraiz, geralmente uma forma da palavras escrita. O tronco não precisa ser idêntico à raiz morfológica\nda palavras; ele geralmente é suficiente que palavras relacionadas sejam mapeadas para o mesmo\ntronco, mesmo se este tronco não for ele próprio uma raiz válida. O estudo de algoritmos para\nstemização tem sido realizado em ciência da computação desde a década de 60. Vários motores de\nbuscas tratam palavras com o mesmo tronco com sinônimos com um tipo de expansão de consulta, em\num processo de combinação."

Performance

The goal of stemming algorithms is to group related words and to separate unrelated words. With this in mind, you can talk about two kinds of possible errors when stemming:

  • Understemming: Related words were not grouped because you didn’t stem enought.
  • Overstemming: Unrelated words were grouped because you removed a large part of the word when stemming.

To measure these errors the function performance was implemented. It returns a data.frame with 3 columns. The name of the stemmer and 2 metrics:

  • UI: the undersampling index. It’s the proportion of related words that were not grouped.
  • OI: the overstemming index. It’s the proportion of unrelated words that were grouped.

Remember that OI is 0 if you don’t stem. So I think the true objective of a stemming algorithm is to reduce UI without augmenting OI too much.

ptstem package provides a dataset of grouped words for the portuguese language (found in this link). It’s in this dataset that performance function calculates the metrics described above.

See results:

This is not the only approach for measuring performance of the those algorithms. The article Assessing the impact of Stemming Accuracy on Information Retrieval – A multilingual perspective describes various ways to analyse stemming performance.