DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Stanford NLP POS Tagger With Maven

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!

Dhiraj Ray user avatar by
Dhiraj Ray
·
Jul. 17, 17 · Tutorial
Like (2)
Save
Tweet
Share
3.65K Views

Join the DZone community and get the full member experience.

Join For Free

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:

<dependency>
  <groupid>edu.stanford.nlp</groupid>
  <artifactid>stanford-corenlp</artifactid>
  <version>3.8.0</version>
</dependency>

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");
   system.out.println("----------------------------------");
   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:

standford-tagging-output

that's it!

NLP

Published at DZone with permission of Dhiraj Ray. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • An Introduction to Data Mesh
  • Bye-Bye, Regular Dev [Comic]
  • PHP vs React
  • Top 5 Java REST API Frameworks

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: