From dfcdaab3a84389e610a57fa82ee0d3a216f4821d Mon Sep 17 00:00:00 2001 From: unwox Date: Thu, 10 Oct 2024 11:51:21 +0600 Subject: allow to specify several tags for a product (instead of one category) --- parser/parser.fnl | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'parser/parser.fnl') 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} -- cgit v1.2.3