1. regular expression in pos
judge the characteristic of a certain word by suffix pattern matching
2. classfier in pos
judge the characteristic of a certain word by suffix classfier
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