sergey-tihon / Stanford.NLP.NET

Stanford NLP for .NET
http://sergey-tihon.github.io/Stanford.NLP.NET/
MIT License
595 stars 123 forks source link

Extract POS Tags and Words from Tagged Sentence #88

Closed ryanboyd closed 6 years ago

ryanboyd commented 6 years ago

I'm having a bit of difficulty, and I'm sure that it's due to my lack of familiarity with IKVM in particular. I'm using stanford-postagger-3.9.1 to run through texts and do basic POS tagging. So far, so good.

However, the next step for me is to get the actual properties of the edu.stanford.nlp.ling.TaggedWord object. For example, in the following code, it's essentially just building off of the (very helpful) examples:

var sentences = MaxentTagger.tokenizeText(new java.io.StringReader(InputText)).toArray();

foreach (ArrayList sentence in sentences)
{
    var taggedSentence = tagger.tagSentence(sentence);
    Iterator it = taggedSentence.iterator();
    while (it.hasNext())
    {
        var token = it.next();
    }
}

From here, however, I'm not really sure how to get the properties of token out as a string. I can see that it has 4 properties:

What I'm looking to do is pull out the str and tag properties so that I can do some other stuff with that information. However, I'm coming up completely short on how to go about this. Any help at all would be greatly appreciated -- I feel like I've tried just about everything that I can think of. I'm sure that it's a simple solution, but I'm completely missing it right now.

Aside from this, fantastic project all around -- amazing work.

**EDIT: I think that I've figured it out. I'm not sure if this is the most efficient way to go about it, but an explicit conversion seems to work:

Iterator it = taggedSentence.iterator();

while (it.hasNext())
 {

    TaggedWord token = (TaggedWord)it.next();                                    

}
sergey-tihon commented 6 years ago

Yes, explicit conversion is the right way.

Original CoreNLP Java API return Objects is most cases.

ryanboyd commented 6 years ago

@sergey-tihon Thank you so much for your reply. Much appreciated!