本文整理汇总了Python中nltk.corpus.util.LazyCorpusLoader.dict方法的典型用法代码示例。如果您正苦于以下问题:Python LazyCorpusLoader.dict方法的具体用法?Python LazyCorpusLoader.dict怎么用?Python LazyCorpusLoader.dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.corpus.util.LazyCorpusLoader
的用法示例。
在下文中一共展示了LazyCorpusLoader.dict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LazyCorpusLoader
# 需要导入模块: from nltk.corpus.util import LazyCorpusLoader [as 别名]
# 或者: from nltk.corpus.util.LazyCorpusLoader import dict [as 别名]
from __future__ import division
import sys
import os.path
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
import poetry
import re
from nltk.corpus import cmudict
d = cmudict.dict()
from nltk.corpus.util import LazyCorpusLoader
from nltk.corpus.reader import *
suffdict = LazyCorpusLoader(
'cmusuffdict', CMUDictCorpusReader, ['cmusuffdict'])
suffdict = suffdict.dict()
def suffdict_phonemes(word):
# Use my cmu-based last syllable dictionary
if re.search("((?i)[bcdfghjklmnpqrstvwxz]{1,2}[aeiouy]+[bcdfghjklmnpqrstvwxz]*(e|ed)?('[a-z]{1,2})?)(?![a-zA-Z]+)", word.lower()):
last_syl = re.search("((?i)[bcdfghjklmnpqrstvwxz]{1,2}[aeiouy]+[bcdfghjklmnpqrstvwxz]*(e|ed)?('[a-z]{1,2})?)(?![a-zA-Z]+)", word.lower()).group()
if last_syl in suffdict:
return suffdict[last_syl][0]
# else try without the first letter
elif last_syl[1 - len(last_syl):] in suffdict:
return suffdict[last_syl[1 - len(last_syl):]][0]
# else try without the first 2 letters
elif last_syl[2 - len(last_syl):] in suffdict:
return suffdict[last_syl[2 - len(last_syl):]][0]
# else try without the last 2 letters, if it ends in 's
elif last_syl[-2:] == "'s":
if last_syl[:-2] in suffdict: