Beispiel #1
0
def get_analysis(word):
    analysis = analyser.lookup_fd(str(word.encode('utf-8')))
    results = process_result_vector(libhfst.vectorize(analysis))
    if results == []:
    	return None
    analysis = unicode(results[0][0], encoding='utf-8')
    return analysis
Beispiel #2
0
def generate_word(analysis):
    word = synthetiser.lookup_fd(str(analysis.encode('utf-8')))
    results = process_result_vector(libhfst.vectorize(word))
    if len(results) != 0:
        word = unicode(results[0][0], encoding='utf-8')
        return word
    else:
        return None
def new_generator(analysis):
    word = synthetiser.lookup_fd(analysis)
    results = process_result_vector(libhfst.vectorize(word))
    if len(results) != 0:
        word = results[0][0]
        return word
    else:
        return None
Beispiel #4
0
def get_POS_list(word_list):
    POS_list = []
    line = ''
    for word in word_list:
        analysis = analyser.lookup_fd(str(word.encode('utf-8')))
        results = process_result_vector(libhfst.vectorize(analysis))
        POS = get_POS_tag(results[0][0])
        POS_list.append(POS)
    return POS_list
Beispiel #5
0
'''This is a demo python script to show how you might do lookup through
libhfst, in this case using an omorfi installation.'''

import os, sys
from itertools import ifilterfalse as ffilter
import libhfst
datadir = "/usr/local/share/hfst/fi"
omorfipath = os.path.abspath(datadir + "/morphology.finntreebank.hfstol")

def process_result_vector(vector):
    results = []
    for entry in vector:
        if len(entry) < 2:
            continue
        weight = entry[0]
        string = ''.join(ffilter(libhfst.FdOperation.is_diacritic, entry[1]))
        results.append((string, weight))
    return results

istr = libhfst.HfstInputStream(omorfipath)
transducer = libhfst.HfstTransducer(istr)
input = raw_input()
while input:
    results = process_result_vector(libhfst.vectorize(transducer.lookup_fd(input)))
    for result in results:
        print result[0] + '\t' + str(result[1])
    try:
        input = raw_input()
    except EOFError:
        sys.exit()
Beispiel #6
0
 def analyze(self, message):
     """Return analyses"""
     results = self.transducer.lookup_fd(message)
     vresults = libhfst.vectorize(results)
     return self.process_result_vector(vresults)
Beispiel #7
0
 def analyze(self, message):
     """Return analyses"""
     results = self.transducer.lookup_fd(message)
     vresults = libhfst.vectorize(results)
     return self.process_result_vector(vresults)