Last active
August 29, 2015 14:02
-
-
Save avgerin0s/9ab381396fe99b1e0985 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule GreekStemmer do | |
@alphabet ~r/^[ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ]+$/i | |
def protected_words do | |
end | |
def exceptions do | |
end | |
def process(regex, word) do | |
destructure [_, st, _], Regex.run(regex, word) | |
st | |
end | |
def stem(word) do | |
if should_stem?(word) do | |
cond do | |
st = process(~r/^(.+?)(ΑΔΕΣ|ΑΔΩΝ)$/u, word) -> | |
if st =~ ~r/(ΟΚ|ΜΑΜ|ΜΑΝ|ΜΠΑΜΠ|ΠΑΤΕΡ|ΓΙΑΓΙ|ΝΤΑΝΤ|ΚΥΡ|ΘΕΙ|ΠΕΘΕΡ|ΚΑΠΛΑΜ|ΠΑΡ|ΨΑΡ|ΤΖΟΥΡ|ΤΑΜΠΟΥΡ)$/u do | |
st | |
else | |
st <> "ΑΔ" | |
end | |
st = process(~r/^(.+?)(ΕΔΕΣ|ΕΔΩΝ)$/u, word) -> | |
if st =~ ~r/(ΟΠ|ΙΠ|ΕΜΠ|ΥΠ|ΓΗΠ|ΔΑΠ|ΚΡΑΣΠ|ΜΙΛ)$/u do | |
st <> "ΕΔ" | |
else | |
st | |
end | |
true -> | |
word | |
end | |
else | |
word | |
end | |
end | |
def should_stem?(word) do | |
word && String.length(word) > 3 && word =~ @alphabet | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment