def get_pos(abbrev, pos, phon=False, segment=False, translate=False, load_morph=False, guess=True, simplified=False, verbose=False): """Just a handy function for working with the POS objects when re-compiling and debugging FSTs. @param abbrev: abbreviation for a language, for example, 'am' @type abbrev: string @param pos: part-of-speech for the FST, for example, 'v' @type pos: string @param phon: whether the FST is for phonology @type phon: boolean @param segment: whether the FST is for segmentation @type segment: boolean @param verbose: whether to print out various messages @type verbose: boolean @return: POS object for the the language and POS @rtype: instance of the POSMorphology class """ hm.load_lang(abbrev, segment=segment, phon=phon, load_morph=load_morph, translate=translate, guess=guess, simplified=simplified, verbose=verbose) lang = hm.morpho.get_language(abbrev, phon=phon, segment=segment, simplified=simplified, translate=translate, load=load_morph, load_morph=load_morph, verbose=verbose) if lang: return lang.morphology[pos]
GNU General Public License for more details. You should have received a copy of the GNU General Public License along with HornMorpho. If not, see <http://www.gnu.org/licenses/>. Copyleft, 2018, Michael Gasser <*****@*****.**> """ import hm import cProfile import pstats def profile(call, file="prof.txt"): cProfile.run(call, file) p = pstats.Stats(file) p.sort_stats('time').print_stats(20) if __name__ == "__main__": print("Loading Amharic") hm.load_lang('am', load_morph=False, guess=False, verbose=True) AM = hm.morpho.get_language('am', verbose=True) print("Analyzing yeteseberew 1") profile("AM.anal_word('yeteseberew')") print("Analyzing yeteseberew 2") profile("AM.anal_word('yeteseberew')") print("Recompiling Amharic verb FSTs") AMV = AM.morphology['v'] profile("AMV.load_fst(True, compose_backwards=False, verbose=True)")