├── .gitignore
├── .travis.yml
├── License.txt
├── README.md
├── core-nlp-example-master
├── README.md
├── src
│ └── main
│ │ └── java
│ │ ├── CoreNlpExample.java
│ │ ├── LemmaExample.java
│ │ ├── NERExample.java
│ │ ├── POSExample.java
│ │ ├── Pipeline.java
│ │ ├── SentenceRecognizer.java
│ │ ├── SentimentAnalysis.java
│ │ └── TokenizeExample.java
└── target
│ ├── classes
│ └── .netbeans_automatic_build
│ ├── maven-archiver
│ └── pom.properties
│ └── test-classes
│ └── .netbeans_automatic_build
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk: oraclejdk8
3 | script: mvn clean verify -B
--------------------------------------------------------------------------------
/License.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) https://github.com/TechPrimers
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Natural Language Processing Using *Standford Core Nlp*
2 |
3 | [](https://travis-ci.com/TechPrimers/core-nlp-example)
4 | [](https://opensource.org/licenses/MIT)
5 | [](https://github.com/techprimers/core-nlp-example/stargazers)
6 | [](https://github.com/techprimers/core-nlp-example/issues)
7 | []()
8 | [](https://github.com/techprimers/core-nlp-example/network)
9 |
10 |
11 | ## Source Contains
12 |
13 | - LemmaExample
14 | - Named Entity Recognition
15 | - Parts of speech
16 | - Pipeline
17 | - Sentence Recognizer
18 | - Sentence Analysis
19 | - Token Generation.
20 |
21 | ## Setup
22 | 1. Need of java-8 to be installed in required system.
23 | 2. Direct Download zip or via svn.
24 | 3. POM Dependencies.
25 |
26 | ## Build and Run
27 | 1. Install maven or Use IDE Build and Clean feature.
28 | 2. Run via CMD/IDE.
29 |
30 | For More detailed information read this Dive in Nlp
31 |
--------------------------------------------------------------------------------
/core-nlp-example-master/README.md:
--------------------------------------------------------------------------------
1 | # Stanford Core NLP Example
2 |
--------------------------------------------------------------------------------
/core-nlp-example-master/src/main/java/CoreNlpExample.java:
--------------------------------------------------------------------------------
1 | import edu.stanford.nlp.ling.CoreAnnotations;
2 | import edu.stanford.nlp.ling.CoreLabel;
3 | import edu.stanford.nlp.pipeline.Annotation;
4 | import edu.stanford.nlp.pipeline.StanfordCoreNLP;
5 | import edu.stanford.nlp.util.CoreMap;
6 |
7 | import java.util.List;
8 | import java.util.Properties;
9 |
10 | public class CoreNlpExample {
11 |
12 | public static void main(String[] args) {
13 |
14 | // creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution
15 | Properties props = new Properties();
16 | props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
17 | StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
18 |
19 | // read some text in the text variable
20 | String text = "What is the Weather in Bangalore right now?";
21 |
22 | // create an empty Annotation just with the given text
23 | Annotation document = new Annotation(text);
24 |
25 | // run all Annotators on this text
26 | pipeline.annotate(document);
27 |
28 | List sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
29 |
30 | for (CoreMap sentence : sentences) {
31 | // traversing the words in the current sentence
32 | // a CoreLabel is a CoreMap with additional token-specific methods
33 | for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
34 | // this is the text of the token
35 | String word = token.get(CoreAnnotations.TextAnnotation.class);
36 | // this is the POS tag of the token
37 | String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
38 | // this is the NER label of the token
39 | String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);
40 |
41 | System.out.println(String.format("Print: word: [%s] pos: [%s] ne: [%s]", word, pos, ne));
42 | }
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/core-nlp-example-master/src/main/java/LemmaExample.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | import edu.stanford.nlp.ling.CoreLabel;
4 | import edu.stanford.nlp.pipeline.CoreDocument;
5 | import edu.stanford.nlp.pipeline.StanfordCoreNLP;
6 |
7 | import java.util.List;
8 |
9 | public class LemmaExample {
10 |
11 | public static void main(String[] args) {
12 |
13 | StanfordCoreNLP stanfordCoreNLP = Pipeline.getPipeline();
14 |
15 | String text = "I am trying to learn new technologies.";
16 |
17 | CoreDocument coreDocument = new CoreDocument(text);
18 |
19 | stanfordCoreNLP.annotate(coreDocument);
20 |
21 | List coreLabelList = coreDocument.tokens();
22 |
23 | for(CoreLabel coreLabel : coreLabelList) {
24 |
25 | String lemma = coreLabel.lemma();
26 |
27 | System.out.println(coreLabel.originalText() + " = "+ lemma);
28 |
29 | }
30 |
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/core-nlp-example-master/src/main/java/NERExample.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | import edu.stanford.nlp.ling.CoreAnnotations;
4 | import edu.stanford.nlp.ling.CoreLabel;
5 | import edu.stanford.nlp.pipeline.CoreDocument;
6 | import edu.stanford.nlp.pipeline.StanfordCoreNLP;
7 |
8 | import java.util.List;
9 |
10 | public class NERExample {
11 |
12 | public static void main(String[] args)
13 | {
14 |
15 | StanfordCoreNLP stanfordCoreNLP = Pipeline.getPipeline();
16 |
17 | String text = "Hey! My name is Krishnan and I have friend his name is Robert." +
18 | " We both are living in Berlin";
19 |
20 | CoreDocument coreDocument = new CoreDocument(text);
21 |
22 | stanfordCoreNLP.annotate(coreDocument);
23 |
24 | List coreLabels = coreDocument.tokens();
25 |
26 | for(CoreLabel coreLabel : coreLabels) {
27 |
28 | String ner = coreLabel.get(CoreAnnotations.NamedEntityTagAnnotation.class);
29 |
30 | System.out.println(coreLabel.originalText() + " = "+ ner);
31 | }
32 |
33 | /* List nameList = coreLabels
34 | .stream()
35 | .filter(coreLabel -> "Person".equalsIgnoreCase(coreLabel.get(CoreAnnotations.NamedEntityTagAnnotation.class)))
36 | .collect(Collectors.toList());
37 |
38 | System.out.println(nameList);
39 | */
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/core-nlp-example-master/src/main/java/POSExample.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | import edu.stanford.nlp.ling.CoreAnnotations;
4 | import edu.stanford.nlp.ling.CoreLabel;
5 | import edu.stanford.nlp.pipeline.CoreDocument;
6 | import edu.stanford.nlp.pipeline.StanfordCoreNLP;
7 |
8 | import java.util.List;
9 |
10 | public class POSExample {
11 |
12 | public static void main(String[] args) {
13 |
14 | StanfordCoreNLP stanfordCoreNLP = Pipeline.getPipeline();
15 |
16 | String text = "Hey! I am Dinesh Krishnan.";
17 |
18 | CoreDocument coreDocument = new CoreDocument(text);
19 |
20 | stanfordCoreNLP.annotate(coreDocument);
21 |
22 | List coreLabelList = coreDocument.tokens();
23 |
24 | for(CoreLabel coreLabel : coreLabelList) {
25 |
26 | String pos = coreLabel.get(CoreAnnotations.PartOfSpeechAnnotation.class);
27 | System.out.println(coreLabel.originalText() + " = "+ pos);
28 | }
29 |
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/core-nlp-example-master/src/main/java/Pipeline.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | import edu.stanford.nlp.pipeline.StanfordCoreNLP;
4 |
5 | import java.util.Properties;
6 |
7 | public class Pipeline {
8 |
9 | private static Properties properties;
10 | private static String propertiesName = "tokenize, ssplit, pos, lemma, ner, parse, sentiment";
11 | private static StanfordCoreNLP stanfordCoreNLP;
12 |
13 | private Pipeline() { }
14 |
15 | static {
16 | properties = new Properties();
17 | properties.setProperty("annotators", propertiesName);
18 | }
19 |
20 | public static StanfordCoreNLP getPipeline() {
21 | if(stanfordCoreNLP == null) {
22 | stanfordCoreNLP = new StanfordCoreNLP(properties);
23 | }
24 | return stanfordCoreNLP;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/core-nlp-example-master/src/main/java/SentenceRecognizer.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | import edu.stanford.nlp.pipeline.CoreDocument;
4 | import edu.stanford.nlp.pipeline.CoreSentence;
5 | import edu.stanford.nlp.pipeline.StanfordCoreNLP;
6 |
7 | import java.util.List;
8 |
9 | public class SentenceRecognizer {
10 |
11 | public static void main(String[] args) {
12 |
13 | StanfordCoreNLP stanfordCoreNLP = Pipeline.getPipeline();
14 |
15 | String text = "Hey! I am Dinesh Krishnan. I am Software Developer and Consultant.";
16 |
17 | CoreDocument coreDocument = new CoreDocument(text);
18 |
19 | stanfordCoreNLP.annotate(coreDocument);
20 |
21 | List sentences = coreDocument.sentences();
22 |
23 | for(CoreSentence sentence : sentences) {
24 |
25 | System.out.println(sentence.toString());
26 | }
27 |
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/core-nlp-example-master/src/main/java/SentimentAnalysis.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | import edu.stanford.nlp.pipeline.CoreDocument;
4 | import edu.stanford.nlp.pipeline.CoreSentence;
5 | import edu.stanford.nlp.pipeline.StanfordCoreNLP;
6 |
7 | import java.util.List;
8 |
9 | public class SentimentAnalysis
10 | {
11 |
12 | public static void main(String[] args) {
13 |
14 | StanfordCoreNLP stanfordCoreNLP = Pipeline.getPipeline();
15 |
16 | String text = "Hello this is John. I don`t like this place.";
17 |
18 | CoreDocument coreDocument = new CoreDocument(text);
19 |
20 | stanfordCoreNLP.annotate(coreDocument);
21 |
22 | List sentences = coreDocument.sentences();
23 |
24 | for(CoreSentence sentence : sentences) {
25 |
26 | String sentiment = sentence.sentiment();
27 |
28 | System.out.println(sentiment + "\t" + sentence);
29 |
30 | }
31 |
32 |
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/core-nlp-example-master/src/main/java/TokenizeExample.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | import edu.stanford.nlp.ling.CoreLabel;
4 | import edu.stanford.nlp.pipeline.CoreDocument;
5 | import edu.stanford.nlp.pipeline.StanfordCoreNLP;
6 |
7 | import java.util.List;
8 |
9 | public class TokenizeExample
10 | {
11 |
12 | public static void main(String[] args)
13 | {
14 |
15 | StanfordCoreNLP stanfordCoreNLP = Pipeline.getPipeline();
16 |
17 | String text = "Hey! This is Dinecvgdsh Krishnan";
18 |
19 | CoreDocument coreDocument = new CoreDocument(text);
20 |
21 | stanfordCoreNLP.annotate(coreDocument);
22 |
23 | List coreLabelList = coreDocument.tokens();
24 |
25 | for(CoreLabel coreLabel : coreLabelList) {
26 |
27 | System.out.println(coreLabel.originalText());
28 | }
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/core-nlp-example-master/target/classes/.netbeans_automatic_build:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TechPrimers/core-nlp-example/1fa06842b52614f9d3d76360f55ec84d602961c3/core-nlp-example-master/target/classes/.netbeans_automatic_build
--------------------------------------------------------------------------------
/core-nlp-example-master/target/maven-archiver/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven
2 | #Sat May 11 17:10:18 IST 2019
3 | version=1.0-SNAPSHOT
4 | groupId=com.techprimers.nlp
5 | artifactId=core-nlp-example
6 |
--------------------------------------------------------------------------------
/core-nlp-example-master/target/test-classes/.netbeans_automatic_build:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TechPrimers/core-nlp-example/1fa06842b52614f9d3d76360f55ec84d602961c3/core-nlp-example-master/target/test-classes/.netbeans_automatic_build
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.techprimers.nlp
8 | core-nlp-example
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 |
14 | edu.stanford.nlp
15 | stanford-corenlp
16 | 3.9.2
17 | jar
18 |
19 |
20 | edu.stanford.nlp
21 | stanford-corenlp
22 | 3.9.2
23 | models
24 |
25 |
26 | edu.stanford.nlp
27 | stanford-parser
28 | 3.9.2
29 |
30 |
31 |
32 | org.slf4j
33 | slf4j-api
34 | 1.7.5
35 |
36 |
37 |
38 | org.slf4j
39 | slf4j-simple
40 | 1.6.4
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------