1. regular expression in pos
judge the characteristic of a certain word by suffix pattern matching
-
>>> import nltk
-
>>> from nltk.corpus import brown
-
>>> brown_tagged_sents = brown.tagged_sents(categories='news')
-
>>> brown_sents = brown.sents(categories='news')
-
>>> patterns = [
-
... (r'.*ing$', 'VBG'),
-
... (r'.*ed$', 'VBD'),
-
... (r'.*es$', 'VBZ'),
-
... (r'.*ould$','MD'),
-
... (r'.*\'s$', 'NN$'),
-
... (r'.*s$', 'NNS'),
-
... (r'^-?[0-9]+(.[0-9]+)?$', 'CD'),
-
... (r'.*', 'NN')
-
... ]
-
>>> regexp_tagger = nltk.RegexpTagger(patterns)
-
>>> regexp_tagger.tag(brown_sents[3])[:10]
-
[(u'``', 'NN'), (u'Only', 'NN'), (u'a', 'NN'), (u'relative', 'NN'), (u'handful', 'NN'), (u'of', 'NN'), (u'such', 'NN'), (u'reports', 'NNS'), (u'was', 'NNS'), (u'received', 'VBD
2. classfier in pos
judge the characteristic of a certain word by suffix classfier
阅读(1044) | 评论(0) | 转发(0) |