KJXDMDMJ4O4BMJL5HF2MY23OKBRZJ57JPD2BUBJXBUUQPMMBFZNAC 2QXUFAF3OJS7IMLP4K2IUUBX3X7QZEZSYRE3Z6O6UAJCSPKH4ZRAC ZAHK7S53I3RLV7NAY7CND3N5SDQMKFWARDRJFP6JP5HMTYLJZYIQC 6YMH7UABZZQXOZWJOA4VKS63TRXJHBSZIZPYLNQYTBGXA7SRSV4AC WFSTP2DNIG6QE5F7GEZQ6NRCO7UPDLP5L7PQPBBNYJ6TC2PXZGOQC YYDITCHVLMT2AE3P65STHJVHNG47BE3TSW3FNSXK2XCOB3VIRJQQC DIJO2HGF3PO7BSYOUZN2DMHU2SRR6CLQ245XKXSETZPJHF6RRKDAC 77ZDLLUTFQ3L3FELAWZQTOG5DUPINOXV5VYLEYBEONDOW2BSVZJAC SDQM4ROF7EPX5G7Z4V37ZNWKWNC7ZHZQQ4ZVKLDZTLJSERCSC4CQC FCCU7MKCCJF3WF3ZEJPLOERQYWX42UXS4QCVM7AXH6O4S765KJYAC ICGDK5NMJH7PYZF3C6CAIXF6COSNX6ORYRGOPZNWJRRHWGZWMAHQC 56LYC22XXLMHGOXXDZ3V6ZVSPHXXBQ6XU75QSXJUW7PTKOMZHZ4QC MU2YNCBOBEBDCFVQZZEMLQW6HF5AY53M62UYPIS6I2NVDPPFZKUQC WY2RZ3DJUNJTIH3UOCQUQZLVGMEEDLEJIIYTWZFCPMJ4CJKKXXTQC {:sentence, s} -> String.length(s) > 2_ -> true
{:sentence, s} ->Enum.all?([&long_sentence?/1,¬_blacklisted?/1],fn chk -> chk.(s) end)_ ->trueend)enddefp long_sentence?(sentence) doString.length(sentence) > 2enddefp not_blacklisted?("(Rim.") dofalseenddefp not_blacklisted?(_sentence) dotrueenddef is_esperanto?(word) docheck_esperanto(word)enddefp check_esperanto(word) doEnum.any?([&is_alias?/1,&is_table_word?/1,&is_in_vocab?/1,&is_conjuction?/1,&is_pronoun?/1,&is_preposition?/1,&is_noun?/1,&is_adjective?/1,&is_adverb?/1,&is_verb?/1],fn f -> f.(word) end)enddefp is_alias?({_, _}), do: truedefp is_alias?(_), do: falsedefp is_noun?(word) doString.ends_with?(word, ["o", "oj", "on", "ojn"])enddefp is_adjective?(word) doString.ends_with?(word, ["a", "aj", "an", "ajn"])enddefp is_adverb?(word) doString.ends_with?(word, ["e", "en"])enddefp is_pronoun?(word) dobase = ~w(mi ni vi li ŝi ĝi ili oni si)Enum.any?(base, fn b ->word == b || word == b <> "a" || word == b <> "n" || word == b <> "aj" || word == b <> "an" ||word == b <> "ajn"
enddefp is_preposition?(word) dopreps = ~w(alanstataŭantaŭapudĉeĉirkaŭdadeeksterelenĝisinterjekontraŭkrommalantaŭmaltranspopostpretersubsupersurtratrans)Enum.any?(preps, fn b -> word == b end)enddefp is_table_word?(word) dotws = ~w(kiotioioĉioneniokiontionionĉionnenionkiutiuiuĉiuneniukiuntiuniunĉiunneniunkiujtiujiujĉiujneniujkiujntiujniujnĉiujnneniujnkiatiaiaĉianeniakiantianianĉianneniankiajtiajiajĉiajneniajkiajntiajniajnĉiajnneniajnkiestiesiesĉiesnenieskietieieĉieneniekientienienĉiennenienkiamtiamiamĉiamneniamkialtialialĉialnenialkieltielielĉielnenielkiomtiomiomĉiomneniom)Enum.any?(tws, fn tw -> word == tw end)enddefp is_conjuction?(word) doEnum.any?(~w(kajaŭsedplusminusnek),fn conj -> conj == word end)enddefp is_verb?(word) doString.ends_with?(word, ["i", "as", "is", "os", "us", "u"])enddefp is_in_vocab?(word) dowords = MapSet.new(~w(ajnalmenaŭankaŭapenaŭdoeĉjajenkvazaŭmemnurpliplejpreskaŭtamentretrojesnetujporĉarmorgaŭhieraŭ))MapSet.member?(words, word)
sentence|> Esperantisto.Text.sentence_to_words()|> Task.async_stream(fn word ->DB.save_word(sentence_id, word)wordend,timeout: 30000,max_concurrency: 10)|> Stream.map(fn {:ok, v} -> v end)|> Stream.scan({nil, nil},fn word, {_, prev} -> {prev, word} end)|> Task.async_stream(fn {prev, word} ->DB.save_word_order(prev, word)end,timeout: 30000,max_concurrency: 10)|> Stream.run()
check =words|> Enum.reduce({[], []}, fn word, {esp, not_esp} ->case Esperantisto.Text.is_esperanto?(word) dotrue ->{[word | esp], not_esp}false ->{esp, [word | not_esp]}endend)
acc
case check do{[], []} ->Logger.debug("Empty sentence: #{inspect(sentence)}")acc{esp, not_esp} ->len_esp = length(esp)len_not_esp = length(not_esp)total = len_esp + len_not_esppercentage = len_esp * 100 / totalif percentage >= @desired_percentage dosentence_id = DB.save_sentence(acc.book_id, sentence)words|> Task.async_stream(fn word ->DB.save_word(sentence_id, word)wordend,timeout: 30000,max_concurrency: 10)|> Stream.map(fn {:ok, v} -> v end)|> Stream.scan({nil, nil},fn word, {_, prev} -> {prev, word} end)|> Task.async_stream(fn {prev, word} ->DB.save_word_order(prev, word)end,timeout: 30000,max_concurrency: 10)|> Stream.run()accelseLogger.warn("Too many non esperanto words: #{len_not_esp}/#{total} (#{inspect(not_esp)}) in sentence #{sentence}")accendend