Skip to content

Instantly share code, notes, and snippets.

@MarcinKosinski
Created July 26, 2018 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcinKosinski/cf95233bfb86b087e86552b95b2a6ec1 to your computer and use it in GitHub Desktop.
Save MarcinKosinski/cf95233bfb86b087e86552b95b2a6ec1 to your computer and use it in GitHub Desktop.
download.file('https://github.com/MarcinKosinski/trigeR5/raw/master/dicts/polimorfologik-2.1.zip', destfile = 'poli.zip')
unzip('poli.zip', exdir = 'dicts')
library(data.table);library(dplyr)
polimorfologik <- fread('dicts/polimorfologik-2.1.txt', data.table = FALSE) %>% set_colnames(c('stem', 'words', 'random_stuff')) %>% select(1:2)
random_polish_text <-
'Wbrew wcześniejszym doniesieniom mediów, w bazie pod Latok I (szczyt w masywie w grupie Panmah Muztagh, części Karakorum), gdzie organizowana jest pomoc dla Aleksandra Gukowa (rosyjski himalaista nadał sygnał SOS i musi zostać ewakuowany, bo jest pozbawiony ekwipunku), nie ma też Andrzeja Bargiela. - Andrzej zgłosił chęć pomocy i wzięcia udziału w akcji ratunkowej. Jednak obecnie znajduje się w Skardu, gdzie dotarł wczoraj z bazy pod K2 - czytamy na twitterowym koncie pierwszego człowieka w historii, który zjechał z wierzchołka K2.'
(polish_stop_words <- readLines('https://raw.githubusercontent.com/MarcinKosinski/trigeR5/master/dicts/polish_stopwords.txt'))
polish_stop_words <- polish_stop_words %>% strsplit(split = ', ', fixed = TRUE) %>% unlist
polish_stop_words <- c(polish_stop_words, toupper(polish_stop_words))
library(tibble);library(magrittr)
text_to_be_stemmed <-
random_polish_text %>%
stringi::stri_extract_all_words() %>%
unlist %>%
tm::removeWords(polish_stop_words) %>%
as_tibble() %>%
set_colnames('words') %>%
filter(words != "")
text_to_be_stemmed %>% left_join(polimorfologik)
# example result ----------------------------------------------------------
# # A tibble: 60 x 2
# words stem
# <chr> <chr>
# 1 Wbrew NA
# 2 wcześniejszym NA
# 3 doniesieniom doniesienie
# 4 mediów NA
# 5 bazie baza
# 6 bazie bazia ----------be careful with that, sometime you get 2 propositions for stemming
# 7 Latok NA
# 8 szczyt szczyt
# 9 masywie masyw
# 10 grupie grupa
# to pick only one proposition per word try this
text_to_be_stemmed %>% left_join(polimorfologik) %>% group_by(words) %>% top_n(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment