当前位置: 首页>>代码示例>>Python>>正文


Python pos.POSTag类代码示例

本文整理汇总了Python中cltk.tag.pos.POSTag的典型用法代码示例。如果您正苦于以下问题:Python POSTag类的具体用法?Python POSTag怎么用?Python POSTag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了POSTag类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_pos_tags

    def _get_pos_tags(self, tokens):
        """Iterate through list of tokens and use POS tagger to build
        a corresponding list of tags.

        :param tokens: List of tokens to be POS-tagged
        :return: List with POS-tag for each token
        """
        # Import (and define tagger) with other imports?    
        from cltk.tag.pos import POSTag
        tagger = POSTag('latin')
        tokens = " ".join(tokens)
        tags = tagger.tag_ngram_123_backoff(tokens)
        tags = [tag[1][0].lower() if tag[1] else tag[1] for tag in tags]
        return tags
开发者ID:souravsingh,项目名称:cltk,代码行数:14,代码来源:backoff.py

示例2: post

    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]}
开发者ID:cltk,项目名称:cltk_api,代码行数:31,代码来源:views.py

示例3: test_pos_perceptron_tagger_old_english

 def test_pos_perceptron_tagger_old_english(self):
     """Test tagging Old English POS with Perceptron tagger."""
     tagger = POSTag('old_english')
     tagged = tagger.tag_perceptron('Hwæt! We Gardena in geardagum, þeodcyninga, þrym gefrunon, hu ða æþelingas ellen fremedon.')
     self.assertTrue(tagged)
开发者ID:TylerKirby,项目名称:cltk,代码行数:5,代码来源:test_old_english.py

示例4: test_pos_ngram123_tagger_old_english

 def test_pos_ngram123_tagger_old_english(self):
     """Test tagging Old English POS with a 1-, 2-, and 3-gram backoff tagger."""
     tagger = POSTag('old_english')
     tagged = tagger.tag_ngram_123_backoff('Hwæt! We Gardena in geardagum, þeodcyninga, þrym gefrunon, hu ða æþelingas ellen fremedon.')  # pylint: disable=line-too-long
     self.assertTrue(tagged)
开发者ID:TylerKirby,项目名称:cltk,代码行数:5,代码来源:test_old_english.py

示例5: test_pos_trigram_old_english

 def test_pos_trigram_old_english(self):
     """Test tagging old_english POS with trigram tagger."""
     tagger = POSTag('old_english')
     tagged = tagger.tag_trigram('Hwæt! We Gardena in geardagum, þeodcyninga, þrym gefrunon, hu ða æþelingas ellen fremedon.')
     self.assertTrue(tagged)
开发者ID:TylerKirby,项目名称:cltk,代码行数:5,代码来源:test_old_english.py

示例6: test_pos_unigram_latin

 def test_pos_unigram_latin(self):
     """Test tagging Latin POS with unigram tagger."""
     tagger = POSTag('latin')
     tagged = tagger.tag_unigram('Gallia est omnis divisa in partes tres')
     self.assertTrue(tagged)
开发者ID:TylerKirby,项目名称:cltk,代码行数:5,代码来源:test_tag.py

示例7: test_pos_tnt_tagger_greek

 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)
开发者ID:TylerKirby,项目名称:cltk,代码行数:5,代码来源:test_tag.py

示例8: test_pos_ngram123_tagger_greek

 def test_pos_ngram123_tagger_greek(self):
     """Test tagging Greek POS with a 1-, 2-, and 3-gram backoff tagger."""
     tagger = POSTag('greek')
     tagged = tagger.tag_ngram_123_backoff('θεοὺς μὲν αἰτῶ τῶνδ᾽ ἀπαλλαγὴν πόνων φρουρᾶς ἐτείας μῆκος')  # pylint: disable=line-too-long
     self.assertTrue(tagged)
开发者ID:TylerKirby,项目名称:cltk,代码行数:5,代码来源:test_tag.py

示例9: test_pos_ngram12_tagger_middle_low_german

 def test_pos_ngram12_tagger_middle_low_german(self):
     """ Test MOG POS 12-backoff tagger"""
     tagger = POSTag('middle_low_german')
     tagged = tagger.tag_ngram_12_backoff('Jck Johannes preister verwarer vnde voirs tender des Juncfrouwen kloisters to Mariendale')
     self.assertTrue(tagged)
开发者ID:TylerKirby,项目名称:cltk,代码行数:5,代码来源:test_tag.py

示例10: test_pos_tnt_tagger_old_norse

 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)
开发者ID:TylerKirby,项目名称:cltk,代码行数:6,代码来源:test_tag.py

示例11: test_pos_crf_tagger_latin

 def test_pos_crf_tagger_latin(self):
     """Test tagging Latin POS with CRF tagger."""
     tagger = POSTag('latin')
     tagged = tagger.tag_crf('Gallia est omnis divisa in partes tres')
     self.assertTrue(tagged)
开发者ID:TylerKirby,项目名称:cltk,代码行数:5,代码来源:test_tag.py

示例12: test_pos_ngram123_tagger_latin

 def test_pos_ngram123_tagger_latin(self):
     """Test tagging Latin POS with a 1-, 2-, and 3-gram backoff tagger."""
     tagger = POSTag('latin')
     tagged = tagger.tag_ngram_123_backoff('Gallia est omnis divisa in partes tres')  # pylint: disable=line-too-long
     self.assertTrue(tagged)
开发者ID:TylerKirby,项目名称:cltk,代码行数:5,代码来源:test_tag.py

示例13: LemmaReplacer



# Import modules

# For XML
from xml.dom.minidom import parse, parseString
import codecs
# For CLTK
from cltk.stem.latin.j_v import JVReplacer
from cltk.stem.lemma import LemmaReplacer
from cltk.tag.pos import POSTag

# Initialize CLTK
lemmatizer = LemmaReplacer('latin')
tagger = POSTag('latin')
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')
开发者ID:paolomonella,项目名称:ursus,代码行数:28,代码来源:cltkUrsus.py

示例14: getPos

 def getPos(self):
   tagger = POSTag('latin')
   return tagger.tag_unigram(self.text)
开发者ID:PonteIneptique,项目名称:Siena-2015,代码行数:3,代码来源:lemmatizer.py


注:本文中的cltk.tag.pos.POSTag类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。