def compile_pmatch_file(filename): """ Compile pmatch expressions as defined in *filename* and return a tuple of transducers. An example: If we have a file named streets.txt that contains: define CapWord UppercaseAlpha Alpha* ; define StreetWordFr [{avenue} | {boulevard} | {rue}] ; define DeFr [ [{de} | {du} | {des} | {de la}] Whitespace ] | [{d'} | {l'}] ; define StreetFr StreetWordFr (Whitespace DeFr) CapWord+ ; regex StreetFr EndTag(FrenchStreetName) ; we can run: defs = hfst.compile_pmatch_file('streets.txt') const = hfst.PmatchContainer(defs) assert cont.match("Je marche seul dans l'avenue desTernes.") == "Je marche seul dans l'<FrenchStreetName>avenue des Ternes</FrenchStreetName>." """ with open(filename, 'r') as myfile: data=myfile.read() myfile.close() defs = compile_pmatch_expression(data) return defs