Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cyrillic support to tokenizer #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion lib/simple_bayes/tokenizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,37 @@ defmodule SimpleBayes.Tokenizer do

iex> SimpleBayes.Tokenizer.tokenize(~s(fo-o's ba_r"ed.))
~w(fo-o's ba_r"ed)

iex> SimpleBayes.Tokenizer.tokenize("шевченко")
["шевченко"]

iex> SimpleBayes.Tokenizer.tokenize("слава Україні")
["слава", "україні"]

iex> SimpleBayes.Tokenizer.tokenize(",воля або смерть .")
["воля", "або", "смерть"]

iex> SimpleBayes.Tokenizer.tokenize("Крим це Україна")
["крим", "це", "україна"]

iex> SimpleBayes.Tokenizer.tokenize("співуча, солов'їна")
["співуча", "солов'їна"]

iex> SimpleBayes.Tokenizer.tokenize("паляниця запашна.")
["паляниця", "запашна"]

iex> SimpleBayes.Tokenizer.tokenize(~s(де-не-де будь ласка "світлина". незабаром! Київ - моє місто))
["де-не-де", "будь", "ласка", "\\"світлина\\"", "незабаром", "київ", "-", "моє", "місто"]

"""
def tokenize(string) do
string
|> String.downcase()
|> String.replace(~r/[^0-9a-zA-Z _\-'"]+/, "")
|> String.replace(~r/[^0-9a-zа-яґієї _\-'"]+/iu, "")
|> String.split()
end


@doc """
Filters out a list based on another list.

Expand Down