Pergunta

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.

Foi útil?

Solução

Here try this:

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

You have to tokenize the words.

This is the output I get:

[('He', None), ('was', None), ('born', None), ('in', None), ('March', 'MAR'), ('1991', None)]
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top