moduleLanguage.Lojban.Mlismu(newMlismu,isValidFatci,addFatci,readFatci,randomBridi,randomBridiRel,Mlismu)whereimportData.MaybeimportData.CharimportLanguage.Lojban.UtilimportSystem.DirectoryimportSystem.IOimportSystem.ProcessimportUtils-- | Create a new mlismu handle.newMlismu::FilePath->IO(EitherStringMlismu)newMlismupath=dois<-doesFileExistpathifisthendodb<-openFilepathAppendModereturn$Right$Mlismupathdbelsereturn$Left$"\""++path++"\" does not exist"-- | Is a fatci valid?isValidFatci::String->IOBoolisValidFatcitext=do-- validLojban <- isValidLojban textifTrue-- validLojbanthenisJust`fmap`mlismuBridi(Righttext)Nothing1elsereturnFalsemlismuBridi::(EitherFilePathString)->MaybeString->Int->IO(Maybe[String])mlismuBridipathselbrilines'=doout<-run("mlismu -n "++showlines'++" -f "++path'++selbri')inputcaseoutofRight("",good@(_:_))|Justgood'/=selbri->return$Just$lines$goodwheregood'=list""(head.lines)good_->returnNothingwhereselbri'=maybe""(" "++)selbripath'=eitherid(const"/dev/stdin")pathinput=either(const"")(++"\n")path-- | Return a random bridi for a (maybe) given selbri.randomBridi::Mlismu->MaybeString->IO(MaybeString)randomBridimlibridi=start`fmap`mlismuBridi(Left$mliFilemli)bridi1wherestart=(>>=listNothing(Just.head))-- | Try to return a random bridi for one of the given selbri.randomBridiRel::Mlismu->[String]->IO(MaybeString)randomBridiRelmlibridis=findMbridiswherefindM[]=randomBridimliNothingfindM(x:xs)=dorandomBridimli(Justx)>>=maybe(findMxs)(return.Just)-- | Add a new fatci.addFatci::Mlismu->String->IOBooladdFatcimlifatci=dois<-isValidFatcifatciifisthendohPutStrLn(mliDBmli)fatcihFlush(mliDBmli)returnTrueelsereturnFalse-- | Add any valid fatci from a set of utterances.readFatci::Mlismu->String->IO()readFatcimli=mapM_(addFatcimli).splitBridissplitBridis::String->[String]splitBridis=mapunwords.splitBy((=="i").filterisLetter).wordsdataMlismu=Mlismu{mliFile::FilePath,mliDB::Handle}