

Stanford NER provides 7class model to recognize PERSON, LOCATION, ORGANIZATION, DATE, TIME, PERCENT, MONEY. In previous blogs, we have discussed 3class model example. In this article, we will discuss 7class model with an example.
Table of Contents
Steps:
Step 1: Download Stanfordner-zip file.
Step 2: Extract Stanford bundle, add stanfor-ner jar file into your project classpath.
Step 3: write below code snippets
//path of classifier we want to load String classierPath = "D:\\classifiers\\english.muc.7class.distsim.crf.ser.gz"; //content that we want to classify String fileContents = "\"barak Obama was born in 1961 in Honolulu, Hawaii,\" in 1988 Obama enrolled in Harvard Law School. My friend got 98% in 10th standard."; //Load classifier , classifier should be load only one time AbstractSequenceClassifier classifier = CRFClassifier.getClassifierNoExceptions(classierPath); //classify the text List<List<CoreLabel>> out = classifier.classify(fileContents); //iterate the result and print it. for (List<CoreLabel> sentence : out) { for (CoreLabel word : sentence) { //unclassify label class is O , we will not print it here if(word.getString(CoreAnnotations.AnswerAnnotation.class).equals("O")) continue; System.out.println(word.word() + " = " + word.get(CoreAnnotations.AnswerAnnotation.class) ); } }
output:
Loading classifier from D:\classifiers\english.muc.7class.distsim.crf.ser.gz ... done [7.1 sec]. Obama = PERSON 1961 = DATE Honolulu = LOCATION Hawaii = LOCATION 1988 = DATE Harvard = ORGANIZATION Law = ORGANIZATION School = ORGANIZATION 98 = PERCENT % = PERCENT
Stanford NER live demo output:
Refer Live demo , Stanford CRF , CoreNLP annotators for details.
Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.