コード例 #1
0
ファイル: inflect.py プロジェクト: jmtoivan/NLP-tools
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
コード例 #2
0
ファイル: inflect.py プロジェクト: jmtoivan/NLP-tools
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
コード例 #3
0
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
コード例 #4
0
ファイル: inflect.py プロジェクト: jmtoivan/NLP-tools
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
コード例 #5
0
ファイル: omor_query.py プロジェクト: unhammer/hfst3
'''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()
コード例 #6
0
ファイル: hfstBot.py プロジェクト: unhammer/hfst3
 def analyze(self, message):
     """Return analyses"""
     results = self.transducer.lookup_fd(message)
     vresults = libhfst.vectorize(results)
     return self.process_result_vector(vresults)
コード例 #7
0
 def analyze(self, message):
     """Return analyses"""
     results = self.transducer.lookup_fd(message)
     vresults = libhfst.vectorize(results)
     return self.process_result_vector(vresults)