本文整理汇总了Python中cltk.tag.pos.POSTag.tag_tnt方法的典型用法代码示例。如果您正苦于以下问题:Python POSTag.tag_tnt方法的具体用法?Python POSTag.tag_tnt怎么用?Python POSTag.tag_tnt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cltk.tag.pos.POSTag
的用法示例。
在下文中一共展示了POSTag.tag_tnt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from cltk.tag.pos import POSTag [as 别名]
# 或者: from cltk.tag.pos.POSTag import tag_tnt [as 别名]
def post(self):
self.reqparse = reqparse.RequestParser()
self.reqparse.add_argument('string', required=True)
self.reqparse.add_argument('lang', required=True, choices=POS_METHODS.keys())
self.reqparse.add_argument('method', required=False,
default=DEFAULT_POS_METHOD)
args = self.reqparse.parse_args()
string = args['string']
lang = args['lang']
method = args['method']
if method not in POS_METHODS[lang]:
return {'message': {'method': method + ' is not a valid choice'}}
tagger = POSTag(lang)
tagged = []
if method == 'unigram':
tagged = tagger.tag_unigram(string)
elif method == 'bigram':
tagged = tagger.tag_bigram(string)
elif method == 'trigram':
tagged = tagger.tag_trigram(string)
elif method == 'ngram123':
tagged = tagger.tag_ngram_123_backoff(string)
elif method == 'tnt':
tagged = tagger.tag_tnt(string)
return {'tags': [{'word': word, 'tag': tag}
if tag is not None else {'word': word, 'tag': 'None'}
for word, tag in tagged]}
示例2: test_pos_tnt_tagger_greek
# 需要导入模块: from cltk.tag.pos import POSTag [as 别名]
# 或者: from cltk.tag.pos.POSTag import tag_tnt [as 别名]
def test_pos_tnt_tagger_greek(self):
"""Test tagging Greek POS with TnT tagger."""
tagger = POSTag('greek')
tagged = tagger.tag_tnt('θεοὺς μὲν αἰτῶ τῶνδ᾽ ἀπαλλαγὴν πόνων φρουρᾶς ἐτείας μῆκος') # pylint: disable=line-too-long
self.assertTrue(tagged)
示例3: test_pos_tnt_tagger_old_norse
# 需要导入模块: from cltk.tag.pos import POSTag [as 别名]
# 或者: from cltk.tag.pos.POSTag import tag_tnt [as 别名]
def test_pos_tnt_tagger_old_norse(self):
"""Test tagging Old Norse POS with TnT tagger."""
tagger = POSTag('old_norse')
tagged = tagger.tag_tnt('Hlióðs bið ek allar.')
print(tagged)
self.assertTrue(tagged)
示例4: test_pos_tnt_tagger_latin
# 需要导入模块: from cltk.tag.pos import POSTag [as 别名]
# 或者: from cltk.tag.pos.POSTag import tag_tnt [as 别名]
def test_pos_tnt_tagger_latin(self):
"""Test tagging Latin POS with TnT tagger."""
tagger = POSTag('latin')
tagged = tagger.tag_tnt('Gallia est omnis divisa in partes tres')
self.assertTrue(tagged)
示例5: JVReplacer
# 需要导入模块: from cltk.tag.pos import POSTag [as 别名]
# 或者: from cltk.tag.pos.POSTag import tag_tnt [as 别名]
j = JVReplacer()
# Parse XML
xmldoc = parse('/home/ilbuonme/siti/paolo.monella/ursus/casanatensis.xml')
#xmldoc = parse('/home/ilbuonme/siti/paolo.monella/ursus/shorter_casanatensis.xml')
wordElementList = xmldoc.getElementsByTagName('w')
for w in wordElementList:
form = w.attributes['ana'].value
print(form)
# Parse the inflected word
try:
lemmaList = lemmatizer.lemmatize(form.lower())
lemma = lemmaList[0].replace('v', 'u')
posList = tagger.tag_tnt(j.replace(form.lower()))
pos = posList[0][1]
w.setAttribute('n', form)
w.setAttribute('lemma', lemma)
w.setAttribute('ana', pos)
except:
raise
"""
with open('output.xml', 'w') as f:
f = codecs.lookup("utf-8")[3](f)
xmldoc.writexml(f, encoding="utf-8")
"""
f = open('output.xml', 'wb')
f = codecs.lookup("utf-8")[3](f)