moduleLanguage.Lojban.Util(-- * Query a Jbovlaste databaselujvoSelrafsis,lujvosSelrafsi,lujvosSelrafsis,lujvosSelrafsis',findGismu,findCmavo,findSelrafsi,filterSelma'o-- * External programs,grammar,translate,wordType,lujvoAndRate,selma'oInfo)whereimportUtilsimportLanguage.Lojban.JbovlasteimportControl.ArrowimportData.CharimportData.ListimportText.Regex-- | Return the selrafsis of a lujvo (string).lujvoSelrafsis::JboDB->String->Maybe[JboValsi]lujvoSelrafsisdb=listNothing(Just.valsiSelrafsis.head).valsidb-- | Returns all lujvos which contain the given selrafsi.lujvosSelrafsi::JboDB->String-- ^ selrafsi (either a cmavo or gismu)->[JboValsi]-- ^ lujvos containing said selrafsilujvosSelrafsidbw=filterValsidb(any((==w).valsiWord).valsiSelrafsis)-- | Returns all lujvos which contain any of the given selrafsis.lujvosSelrafsis::JboDB->[String]-- ^ selrafsis->[JboValsi]-- ^ lujvos containing any of the selrafsislujvosSelrafsisdbws=filterValsidb(any(flipelemws.valsiWord).valsiSelrafsis)-- | Returns all lujvos which contain all of the given selrafsis (in order).lujvosSelrafsis'::JboDB->[String]-- ^ selrafsis->[JboValsi]-- ^ lujvos containing all of the selrafsis (in order)lujvosSelrafsis'dbws=filterValsidb((==ws).mapvalsiWord.valsiSelrafsis)-- | Find a gismu valsi matching the given word.findGismu::JboDB->String->MaybeJboValsifindGismudbw=findValsidbgismuwheregismuv=valsiTypev==GismuType&&valsiWordv==w-- | Find a cmavo valsi matching the given word.findCmavo::JboDB->String->MaybeJboValsifindCmavodbw=findValsidbcmavowherecmavov=valsiTypev==CmavoType&&valsiWordv==w-- | Find a selrafsi matching the given rafsi.findSelrafsi::JboDB->String->MaybeJboValsifindSelrafsidbw=findValsidbselrafsiwhereselrafsiv=(valsiTypev==CmavoType||valsiTypev==GismuType)&&(any(==w)(valsiRafsisv)||(lengthw>=4&&valsiTypev==GismuType&&w`isPrefixOf`valsiWordv))-- | Returns all cmavo which belong to the given selma'o.filterSelma'o::JboDB->String->[JboValsi]filterSelma'odbs=filterValsidbselma'owhereselma'ov=valsiTypev==CmavoType&&fmapformat(valsiSelma'ov)==Just(formats)whereformat=filterisLetter.lower-- | Shows the grammar of a lojban utterance using jbofihe.grammar::String-- ^ The lojban utterance->IO(EitherString(String,String))-- ^ A pair of error and success strings.grammar=run"jbofihe -ie"-- | Translates a lojban utterance to English using jbofihe.translate::String-- ^ The lojban utterance->IO(EitherString(String,String))-- ^ English outputtranslate=run"jbofihe -x"-- | Shows the type of a word using vlatai.wordType::String-- ^ The lojban word->IO(EitherStringString)-- ^ Word typewordTypew=dor<-run("vlatai \""++(lojbanicw)++"\"")""caserofRight("",v)->return.Right.unwords.words$vRight(e,_)->return$LefteLefte->return$Lefte-- | Tries to construct and rate lujvo from selfrasis, using jvocuhadju.lujvoAndRate::[String]-- ^ selrafsis->IO(EitherString[(Int,String)])-- ^ Word typelujvoAndRatews=doletselrafsis=unwords$map(("\""++).(++"\"").lojbanic)wsr<-run("jvocuhadju "++selrafsis++"")""caserofRight("",g)->return$Right$map(rating.trim)$dropWhile(not.anyisDigit)$lines$gRight(e,_)->return$LefteLefte->return$Leftewhererating=(read***tail).breakisSpace-- | Returns information about a selma'o, using mahotic.selma'oInfo::String->IO(EitherStringString)selma'oInfos=dor<-run("mahotci -i \""++upper(lojbanics)++"\"")""caserofRight("",good)->return$Right(formatgood)Right(bad,_)->return$Left$"no entry for \""++s++"\""Left_->return$Left"mahotci pipe error"whereformat=flip(subRegexr1)"\n".flip(subRegexr)"\\1 \\2"r=mkRegex"([^\n])\n([^\n])"r1=mkRegex"\n\n"lojbanic=filtergoodwheregoodc=isLetterc||c=='\''||c==' 'lower=maptoLowerupper=maptoUpper