3

If I try this code :

import nltk
pattern = [(r'(March)$','MAR')]
tagger=nltk.RegexpTagger(pattern)
print tagger.tag('He was born in March 1991')

I get an output likr this:

[('H', None), ('e', None), (' ', None), ('w', None), ('a', None), ('s', None), (' ', None), >('b', None), ('o', None), ('r', None), ('n', None), (' ', None), ('i', None), ('n', None), (' ', None), ('M', None), ('a', None), ('r', None), ('c', None), ('h', None), (' ', None), ('1', None), ('9', None), ('9', None), ('1', None)]

In fact I would like this tagger to recognise 'March' word with 'MAR' tag.

4

1 に答える 1

6

ここでこれを試してください:

import nltk
pattern = [(r'(March)$','MAR')]
tagger = nltk.RegexpTagger(pattern)
print tagger.tag(nltk.word_tokenize('He was born in March 1991'))

単語をトークン化する必要があります。

これは私が得る出力です:

[('He', None), ('was', None), ('born', None), ('in', None), ('March', 'MAR'), ('1991', None)]
于 2013-01-26T03:17:25.303 に答える