how to detect a tense of a sentence?

1,036 views
Skip to first unread message

milman

unread,
Mar 4, 2011, 1:03:18 PM3/4/11
to nltk-users
Hi people,

For quite a time now I'm looking for a way to detect a tense of a
sentence, given a sentence which is tagged correctly.

For "Present Simple", for example, we could have those sentences:
" I eat banana"
"the monkey eats a banana"
"he eats a green banana"

It's easy to set a grammar rule for each one, but to get all of them I
need to use a regular expression. I tell myself that someone probably
created regexs for the tenses, but I just couldn't find any!

Anyone can shed some light here?

Thanks!

Justin Olmanson

unread,
Mar 4, 2011, 3:08:00 PM3/4/11
to nltk-...@googlegroups.com
wouldn't tagged correctly imply tenses   meaning you just need to pipe the different tenses you want to allow
http://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html



    grammar = r"""
        NP: {<CC>*<WRB>?<PDT>?<WDT|DT|WP\$|PRP\$>?<LS>*<CD|JJR|JJS|JJ>*<PRP|WP|NNP|NNPS|NNS|NN|NPS|NP|PPS|PP>+}
        PP: {<IN|TO|RP><NP>}
        VP: {<EX|RB|RBS|WRB>*<MD>*<TO>*<VBD|VBG|VBN|VBP|VBZ|VB>+<RB|RBS|WRB>*<RP>*}
        CL: {<PP|NP><VP><PP>*<\.|\?|!>*|<VP><PP|NP><\.|\?|!>*}
        """
    j = nltk.RegexpParser(grammar, loop=2)
    k = str(j.parse(taggedText))  #convert to string



justin





--
You received this message because you are subscribed to the Google Groups "nltk-users" group.
To post to this group, send email to nltk-...@googlegroups.com.
To unsubscribe from this group, send email to nltk-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nltk-users?hl=en.


vineet yadav

unread,
Mar 4, 2011, 8:21:24 PM3/4/11
to nltk-...@googlegroups.com, Justin Olmanson
Hi,
You can use chunker to find out all verb chunks. Then you can find
tense for each verb chunk with the helps of POS tag present in chunk.
For example if VBP and VBG POS tags are coming together in verb chunk
than tense for chunk is present continuous. You can also use morph
analysis dictionary
(ftp://ftp.cis.upenn.edu/pub/xtag/morph-1.5/morph-1.5.tar.gz) for
finding tense of each chunk.
Thanks
Vineet Yadav

uri milman

unread,
Mar 8, 2011, 6:20:00 AM3/8/11
to nltk-...@googlegroups.com
thanks for the ideas!

I was hoping for a tool to define a sentence, but it seems I'll have to do it myself:
I created simple expressions for several English tenses, and although it is not always simple, it is possible.

I couldn't compile any of the xtag code, but the tech report there (ftp://ftp.cis.upenn.edu/pub/xtag/release-2.24.2001/tech-report.pdf) gave me some directions for future use.


Vineet, did you manage to compile the morph?

thanks.
   - Uri
 

vineet yadav

unread,
Mar 8, 2011, 7:57:05 PM3/8/11
to nltk-...@googlegroups.com, Justin Olmanson
Hi Justin,
I parsed 'morph_english.flat' and written little bit api for morph
analysis related function according my need.
Thanks
Vineet Yadav
Reply all
Reply to author
Forward
0 new messages