-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TechPrimers
committed
Jul 11, 2017
0 parents
commit 53c6e45
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea/ | ||
target/ | ||
|
||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Stanford Core NLP Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.techprimers.nlp</groupId> | ||
<artifactId>core-nlp-example</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>edu.stanford.nlp</groupId> | ||
<artifactId>stanford-corenlp</artifactId> | ||
<version>3.2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>edu.stanford.nlp</groupId> | ||
<artifactId>stanford-corenlp</artifactId> | ||
<version>3.2.0</version> | ||
<classifier>models</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>edu.stanford.nlp</groupId> | ||
<artifactId>stanford-parser</artifactId> | ||
<version>3.2.0</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import edu.stanford.nlp.ling.CoreAnnotations; | ||
import edu.stanford.nlp.ling.CoreLabel; | ||
import edu.stanford.nlp.pipeline.Annotation; | ||
import edu.stanford.nlp.pipeline.StanfordCoreNLP; | ||
import edu.stanford.nlp.util.CoreMap; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
public class CoreNlpExample { | ||
|
||
public static void main(String[] args) { | ||
|
||
// creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution | ||
Properties props = new Properties(); | ||
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref"); | ||
StanfordCoreNLP pipeline = new StanfordCoreNLP(props); | ||
|
||
// read some text in the text variable | ||
String text = "What is the Weather in Bangalore right now?"; | ||
|
||
// create an empty Annotation just with the given text | ||
Annotation document = new Annotation(text); | ||
|
||
// run all Annotators on this text | ||
pipeline.annotate(document); | ||
|
||
List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class); | ||
|
||
for (CoreMap sentence : sentences) { | ||
// traversing the words in the current sentence | ||
// a CoreLabel is a CoreMap with additional token-specific methods | ||
for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) { | ||
// this is the text of the token | ||
String word = token.get(CoreAnnotations.TextAnnotation.class); | ||
// this is the POS tag of the token | ||
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class); | ||
// this is the NER label of the token | ||
String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class); | ||
|
||
System.out.println(String.format("Print: word: [%s] pos: [%s] ne: [%s]", word, pos, ne)); | ||
} | ||
} | ||
} | ||
} |