module Study.Framework.Lojban.Extractors
( extractTrivialBridiGeneratorFromVocabulary
, extractSimpleBridiGeneratorFromTranslationGenerator
, extractLojbanSentencesFromTranslationGenerator
, extractLojbanSentencesFromTranslation
) where
import Core
import Language.Lojban.Core
import Util (chooseItemUniformly)
import Language.Lojban.Canonicalization (extractSimpleBridi)
import Study.Framework.Lojban.TranslationUtils (narrowTranslationGenerator)
import qualified Data.Text as T
extractTrivialBridiGeneratorFromVocabulary :: Vocabulary -> SimpleBridiGenerator
Vocabulary
vocabulary StdGen
r0 = (SimpleBridi
simpleBridi, StdGen
r1) where
(Text
brivla, StdGen
r1) = StdGen -> [Text] -> (Text, StdGen)
forall a. StdGen -> [a] -> (a, StdGen)
chooseItemUniformly StdGen
r0 ([Text] -> (Text, StdGen)) -> [Text] -> (Text, StdGen)
forall a b. (a -> b) -> a -> b
$ Vocabulary -> [Text]
vocabularyBrivlaList Vocabulary
vocabulary
simpleBridi :: SimpleBridi
simpleBridi = Bool -> Text -> [Text] -> [Text] -> SimpleBridi
SimpleBridi Bool
False Text
brivla [] []
extractSimpleBridiGeneratorFromTranslationGenerator :: TranslationGenerator -> SimpleBridiGenerator
TranslationGenerator
translationGenerator StdGen
r0 = (SimpleBridi
simpleBridi, StdGen
r1) where
narrowedTranslationGenerator :: TranslationGenerator
narrowedTranslationGenerator = TranslationGenerator -> TranslationGenerator
narrowTranslationGenerator TranslationGenerator
translationGenerator
(Text
sentence, StdGen
r1) = TranslationGenerator -> TextGenerator
extractLojbanSentencesFromTranslationGenerator TranslationGenerator
narrowedTranslationGenerator StdGen
r0
simpleBridi :: SimpleBridi
simpleBridi = case (Text -> Either String SimpleBridi
extractSimpleBridi Text
sentence) of
Left String
msg -> String -> SimpleBridi
forall a. HasCallStack => String -> a
error (String -> SimpleBridi) -> String -> SimpleBridi
forall a b. (a -> b) -> a -> b
$ String
"extractSimpleBridiFromTranslationGenerator: unable to parse sentence\nsentence: \"" String -> String -> String
forall a. [a] -> [a] -> [a]
++ (Text -> String
T.unpack Text
sentence) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\"\nmessage: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
msg String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"\""
Right SimpleBridi
simpleBridi' -> SimpleBridi
simpleBridi'
extractLojbanSentencesFromTranslationGenerator :: TranslationGenerator -> TextGenerator
TranslationGenerator
translationGenerator StdGen
r0 = (Text
sentence, StdGen
r2) where
(Translation
translation, StdGen
r1) = TranslationGenerator
translationGenerator StdGen
r0
(Text
sentence, StdGen
r2) = StdGen -> [Text] -> (Text, StdGen)
forall a. StdGen -> [a] -> (a, StdGen)
chooseItemUniformly StdGen
r1 ([Text] -> (Text, StdGen)) -> [Text] -> (Text, StdGen)
forall a b. (a -> b) -> a -> b
$ Translation -> [Text]
extractLojbanSentencesFromTranslation Translation
translation
extractLojbanSentencesFromTranslation :: Translation -> [T.Text]
([Text]
lojban_sentences, [Text]
translated_sentences) = [Text]
lojban_sentences