Finding Tense of A sentence using stanford nlp
Asked Answered
D

4

10

Q1.I am trying to get tense of a complete sentence,just don't know how to do it using nlp. Any help appreciated.

Q2 .What all information can be extracted from a sentence using nlp?

Currently I can, I get : 1.Voice of sentence 2.subject object verb 3.POS tags.

Any more info can be extracted please let me know.

Durware answered 3/3, 2014 at 6:12 Comment(6)
I want complete tense eg: simple present OR present perfect continuous tense ... as far as i know I cannot get simply from POS tagsDurware
Can you please let me know how do you determine the voice of sentence, subject object verb, etc... I am using NLTK and I am able to get the POS tags but not the voice of sentence or subject, objectMadrigal
For this you can use parse tree and get all the stuff you want.Durware
sorry I am not sure how to do that. Can you please explain in detail. Do we need to use the "Pattern.en" package or something else ?Madrigal
Please check nltk.org/book/ch08.htmlDurware
Well as @Madrigal has mentioned, I don't think NLTK provides voice of the sentence, instead all the useful attributes associated with the textual sentence.Crucial
B
18

The Penn treebank defines VBD and VBN as the past tense and the past participle of a verb, respectively. In many sentences, simply getting the POS tags and checking for the presence of these two tags will suffice. In others, however, there may be verbs in multiple tenses while the sentence as a whole is in the past tense. For these cases, you need to use constituency parsing. Stanford NLP also provides a parser. You can use this to detect the outermost verb phrase (tagged as VP). If a past tense/participle form of a verb is an ancestor of all other verbs in the verb phrase, the tense of your sentence should be marked as past tense.

The example given by Dror yields this:

(ROOT
  (S
    (NP (PRP I))
    (VP (VBD did) (RB n't)
      (VP (VB want)
        (NP (DT the) (NN dog)
          (S
            (VP (TO to)
              (VP (VB eat)
                (NP (PRP$ my) (NN homework))))))))
    (. .)))

Even though eat is not past tense, the topmost verb in the verb phrase is correctly tagged VBD (i.e. past tense).

edit (some additional information):

Complex sentences have what is called the primary tense and a secondary tense. For sentences like "By the time I will reach there, he'd have already left", there is no such thing as 'the complete tense'. You can only distinguish between the primary and the secondary.

If you want information about perfect, continuous, etc., then you will have to derive rules based on the POS tags. E.g. an auxiliary verb in present tense followed by a verb in the past tense will express the present perfect tense (if there are obvious counterexamples, please add to the answer ... I can't think of any right now).

Bramwell answered 3/3, 2014 at 11:57 Comment(2)
I want complete tense eg: simple present OR present perfect continuous tense ... as far as i know I cannot get simply from POS tagsDurware
That is true, you can't get it simply from the POS tags. But you can get a much more accurate result by using the phrase structures presented in parse trees such as the one my answer provides. It will not, however, work for sentences like "By the time I will reach there, he'd have already left."Bramwell
S
4

Basically the tense of a sentence in English is determined by the form of the verb that is the head of the sentence. You may read more about this topic in this post about The Contextors’ Tense Conjugator. Identifying the head verb and its form is possible using a parser.

The kind of information that can be extracted from a sentence depends on the analysis you perform. You can extract other components of the sentence such as prepositional complements, predicative complements and adjuncts, as well as other grammatical attributes such as aspect, secondary tense, modality and polarity. Some sentences contains embedded clauses, like in the example below from the Contextors API. In this case, you may want to extract this information also from the embedded clause.

enter image description here

Stanislas answered 3/3, 2014 at 10:24 Comment(2)
Please suggest any other free api this is in beta and maybe not opensourceDurware
You can use Stanford NLP, Freeling, Gate, NLTK.Ake
G
4

8 years later but maybe someone is still searching for another solution. As part of my study I actually tried to distinguish the tense including the tense aspect (for instance future simple, present perfect progressive, future perfect,...) in a sentence using the dependency parser of the Stanford Core NLP and a deterministic program I put together after a lot of research on english grammar. I'm a beginner programmer and not a linguist. However, I got a weighted f1-score of 89,75% on my test data which isnt bad. So if anyone wants to build on that foundation, heres the logic I implemented displayed as a flow chart: flow chart to distinguish tense aspects

If anyone is interested, I could also send the paper I wrote about it. Its in german, but I could translate relevant parts if needed. Don't know if this answer helps anyone, but since I spend so much time with this question, I thought I'd share the results :)

Gleich answered 12/10, 2022 at 18:45 Comment(4)
Very nice flow chart! Do you have any publicly available code on it?Whisenhunt
Thanks! I now made it public here: github.com/3scapeX/textReadabilityClassifier I had to exclude the data though since I dont own the rights. The tense aspect is in the "grammar_module" and starts at line 167. Lots of nested elifs, but I tried to add a lot of comments when I wrote it, so I hope it's at least a little bit readable.Gleich
Awesome, thanks so much for doing this!Whisenhunt
No problem! If you use it or happen to discover something, I would be happy to hear about itGleich
E
2

I want complete tense eg: simple present OR present perfect continuous tense ... as far as i know I cannot get simply from POS tags

Note that what you have in your examples above are not examples of tense, they are rather examples of certain tense/aspect configurations. While tense by itself (past, present, future) places an eventuality in time, aspect categories (progressive, continuous, perfective, and the like) rather relate the eventuality to the flow of time (i.e. whether it is bounded/completed, whether it was a continuous event, etc). Thus, tense and aspect are two distinct grammatical categories. In English, they both form part of the verbal complex, which makes it easy to confuse them as well as find/analyze them in a single method. In many other languages, they are realized separately (distinct structural positions, functional items, constructions, etc.). Beware.

Enzymolysis answered 10/3, 2014 at 11:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.