def read_prolog_transducer(f, linecount=[0]): """ Create a transducer as defined in prolog format in file *f*. *linecount* keeps track of the current line in the file. """ linecount_ = 0 fsm = HfstBasicTransducer() line = "" while (True): line = f.readline() linecount_ = linecount_ + 1 if line == "": raise hfst.exceptions.EndOfStreamException( "", "", linecount[0] + linecount_) line = line.rstrip() if line == "": pass # allow extra prolog separator(s) if line[0] == '#': pass # comment line else: break if not libhfst.parse_prolog_network_line(line, fsm): raise hfst.exceptions.NotValidPrologFormatException( line, "", linecount[0] + linecount_) while (True): line = f.readline() if (line == ""): retval = HfstTransducer(fsm, get_default_fst_type()) retval.set_name(fsm.name) linecount[0] = linecount[0] + linecount_ return retval line = line.rstrip() linecount_ = linecount_ + 1 if line == "": # prolog separator retval = HfstTransducer(fsm, get_default_fst_type()) retval.set_name(fsm.name) linecount[0] = linecount[0] + linecount_ return retval if libhfst.parse_prolog_arc_line(line, fsm): pass elif libhfst.parse_prolog_final_line(line, fsm): pass elif libhfst.parse_prolog_symbol_line(line, fsm): pass else: raise hfst.exceptions.NotValidPrologFormatException( line, "", linecount[0] + linecount_)
def read_prolog_transducer(f, linecount=[0]): """ Create a transducer as defined in prolog format in file *f*. *linecount* keeps track of the current line in the file. """ linecount_ = 0 fsm = HfstBasicTransducer() line = "" while(True): line = f.readline() linecount_ = linecount_ + 1 if line == "": raise hfst.exceptions.EndOfStreamException("","",linecount[0] + linecount_) line = line.rstrip() if line == "": pass # allow extra prolog separator(s) if line[0] == '#': pass # comment line else: break if not libhfst.parse_prolog_network_line(line, fsm): raise hfst.exceptions.NotValidPrologFormatException(line,"",linecount[0] + linecount_) while(True): line = f.readline() if (line == ""): retval = HfstTransducer(fsm, get_default_fst_type()) retval.set_name(fsm.name) linecount[0] = linecount[0] + linecount_ return retval line = line.rstrip() linecount_ = linecount_ + 1 if line == "": # prolog separator retval = HfstTransducer(fsm, get_default_fst_type()) retval.set_name(fsm.name) linecount[0] = linecount[0] + linecount_ return retval if libhfst.parse_prolog_arc_line(line, fsm): pass elif libhfst.parse_prolog_final_line(line, fsm): pass elif libhfst.parse_prolog_symbol_line(line, fsm): pass else: raise hfst.exceptions.NotValidPrologFormatException(line,"",linecount[0] + linecount_)