Over a million developers have joined DZone.

Stanford NLP POS Tagger With Maven

DZone's Guide to

Stanford NLP POS Tagger With Maven

The Stanford NLP POS Tagger is used to mark up text to be processed by natural language processing and NLP. Read on to learn how to use it!

· AI Zone ·
Free Resource

Insight for I&O leaders on deploying AIOps platforms to enhance performance monitoring today. Read the Guide.

Last time, we talked about the Apache Open NLP POS Tagger. This post is about using the Stanford NLP to tag any part of speech.We will be setting up a Maven-based project to get started with Stanford NLP. In the example below, we will be using MaxentTagger to tag any POS by using Stanford NLP. Here are some different POS tags with their corresponding meaning:

POS Tags

Following is the Maven dependencies to get started with Stanford NLP:


To initialize MaxentTagger, we need to invoke the constructor with the location of parameter file with a trained tagger as english-left3words-distsim.tagger. For example:

MaxentTagger maxentTagger = new MaxentTagger("english-left3words-distsim.tagger");

Once the Maxent tagger is initialized, we can call predefined method tagString() provided inside this class to tag any sentence. This method basically returns a tagged string. Following is a sample code to use tagString():

String tag = maxentTagger.tagString(text);
   String[] eachTag = tag.split("\\s+");
   System.out.println("Word      " + "Stanford tag");
   for(int i = 0; i< eachTag.length; i++) {
     System.out.println(eachTag[i].split("_")[0] +"           "+ eachTag[i].split("_")[1]);

If you try to execute the above implementation for any text and if you have several test classes, you can combine them into a test suite. We can expect result following result:


That's it!

TrueSight is an AIOps platform, powered by machine learning and analytics, that elevates IT operations to address multi-cloud complexity and the speed of digital transformation.

nlp ,maven ,ai ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}