summaryrefslogtreecommitdiff
path: root/parser/parser.fnl
diff options
context:
space:
mode:
Diffstat (limited to 'parser/parser.fnl')
-rw-r--r--parser/parser.fnl50
1 files changed, 27 insertions, 23 deletions
diff --git a/parser/parser.fnl b/parser/parser.fnl
index d5baafa..ca74847 100644
--- a/parser/parser.fnl
+++ b/parser/parser.fnl
@@ -105,39 +105,43 @@
:match html))
;; FIXME: make guessing case insensitive
-(fn guess-category [title]
- (local title (if title (luna.utf.lower title) ""))
+(fn guess-tags [text]
+ (local text (if text (luna.utf.lower text) ""))
- (if (: (anywhere (peg.P "зеленый")) :match title)
- "Зеленый чай"
- (: (anywhere (peg.P "улун")) :match title)
- "Улун"
- (: (anywhere (peg.P "белый")) :match title)
- "Белый чай"
- (: (anywhere (peg.P "желтый")) :match title)
- "Желтый чай"
- (: (anywhere (peg.P "красный")) :match title)
- "Красный чай"
- (: (anywhere (peg.P "хэй ча")) :match title)
- "Хэй ча"
- (: (anywhere (+ (peg.P "матча") "маття")) :match title)
- "Матча"
- "Неизвестная категория"))
+ (if (: (anywhere (peg.P "зеленый")) :match text)
+ ["Зеленый чай"]
+ (: (anywhere (peg.P "улун")) :match text)
+ ["Улун"]
+ (: (anywhere (peg.P "белый")) :match text)
+ ["Белый чай"]
+ (: (anywhere (peg.P "желтый")) :match text)
+ ["Желтый чай"]
+ (: (anywhere (peg.P "красный")) :match text)
+ ["Красный чай"]
+ (: (anywhere (peg.P "хэй ча")) :match text)
+ ["Хэй ча"]
+ (: (anywhere (peg.P "шу пуэр")) :match text)
+ ["Шу пуэр"]
+ (: (anywhere (+ (peg.P "шен пуэр") "шэн пуэр")) :match text)
+ ["Шен пуэр"]
+ (: (anywhere (+ (peg.P "матча") "маття")) :match text)
+ ["Матча"]
+ []))
-(fn guess-year [title]
+(fn guess-year [text]
(number.string->number
(: (anywhere
(* (peg.C (^ (peg.R "09") 4))
(maybe " ")
(- (+ (peg.P "г") "год") (peg.P "гр"))))
- :match title)))
+ :match text)))
-(fn guess-weight [title]
- (if title
+(fn guess-weight [text]
+ (if text
(number.string->number
(: (anywhere
(* (peg.C pegs.number) (maybe " ") "гр"))
- :match title))
+ :match text))
nil))
{: match-many
@@ -147,6 +151,6 @@
: maybe
: pegs
:not pnot
- : guess-category
+ : guess-tags
: guess-year
: guess-weight}