2013-12-03 13 views
9

Ich habe stanford core nlp-Pakete heruntergeladen und versucht, es auf meinem Computer zu testen.Ausführen und Testen von stanford core nlp Beispiel

Mit Befehl: java -cp "*" -mx1g edu.stanford.nlp.sentiment.SentimentPipeline -file input.txt

Ich habe die Stimmung Ergebnis in Form von positive oder negative. input.txt enthält den zu testenden Satz.

Auf mehr Befehl: java -cp stanford-corenlp-3.3.0.jar;stanford-corenlp-3.3.0-models.jar;xom.jar;joda-time.jar -Xmx600m edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,parse -file input.txt bei seiner Ausführung gibt follwing Linien:

H:\Drive E\Stanford\stanfor-corenlp-full-2013~>java -cp stanford-corenlp-3.3.0.j 
ar;stanford-corenlp-3.3.0-models.jar;xom.jar;joda-time.jar -Xmx600m edu.stanford 
.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,parse -file 
input.txt 
Adding annotator tokenize 
Adding annotator ssplit 
Adding annotator pos 
Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3wo 
rds/english-left3words-distsim.tagger ... done [36.6 sec]. 
Adding annotator lemma 
Adding annotator parse 
Loading parser from serialized file edu/stanford/nlp/models/lexparser/englishPCF 
G.ser.gz ... done [13.7 sec]. 

Ready to process: 1 files, skipped 0, total 1 
Processing file H:\Drive E\Stanford\stanfor-corenlp-full-2013~\input.txt ... wri 
ting to H:\Drive E\Stanford\stanfor-corenlp-full-2013~\input.txt.xml { 
    Annotating file H:\Drive E\Stanford\stanfor-corenlp-full-2013~\input.txt [13.6 
81 seconds] 
} [20.280 seconds] 
Processed 1 documents 
Skipped 0 documents, error annotating 0 documents 
Annotation pipeline timing information: 
PTBTokenizerAnnotator: 0.4 sec. 
WordsToSentencesAnnotator: 0.0 sec. 
POSTaggerAnnotator: 1.8 sec. 
MorphaAnnotator: 2.2 sec. 
ParserAnnotator: 9.1 sec. 
TOTAL: 13.6 sec. for 10 tokens at 0.7 tokens/sec. 
Pipeline setup: 58.2 sec. 
Total time for StanfordCoreNLP pipeline: 79.6 sec. 

H:\Drive E\Stanford\stanfor-corenlp-full-2013~> 

verstehen kann. Kein informatives Ergebnis.

bekam ich ein Beispiel an: stanford core nlp java output

import java.io.*; 
import java.util.*; 

import edu.stanford.nlp.io.*; 
import edu.stanford.nlp.ling.*; 
import edu.stanford.nlp.pipeline.*; 
import edu.stanford.nlp.trees.*; 
import edu.stanford.nlp.util.*; 

public class StanfordCoreNlpDemo { 

    public static void main(String[] args) throws IOException { 
    PrintWriter out; 
    if (args.length > 1) { 
     out = new PrintWriter(args[1]); 
    } else { 
     out = new PrintWriter(System.out); 
    } 
    PrintWriter xmlOut = null; 
    if (args.length > 2) { 
     xmlOut = new PrintWriter(args[2]); 
    } 

    StanfordCoreNLP pipeline = new StanfordCoreNLP(); 
    Annotation annotation; 
    if (args.length > 0) { 
     annotation = new Annotation(IOUtils.slurpFileNoExceptions(args[0])); 
    } else { 
     annotation = new Annotation("Kosgi Santosh sent an email to Stanford University. He didn't get a reply."); 
    } 

    pipeline.annotate(annotation); 
    pipeline.prettyPrint(annotation, out); 
    if (xmlOut != null) { 
     pipeline.xmlPrint(annotation, xmlOut); 
    } 
    // An Annotation is a Map and you can get and use the various analyses individually. 
    // For instance, this gets the parse tree of the first sentence in the text. 
    List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); 
    if (sentences != null && sentences.size() > 0) { 
     CoreMap sentence = sentences.get(0); 
     Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class); 
     out.println(); 
     out.println("The first sentence parsed is:"); 
     tree.pennPrint(out); 
    } 
    } 

} 

Versuchte es in Netbeans mit einschließlich notwendige Bibliothek auszuführen. Aber es immer zwischen stecken in oder gibt Ausnahme Exception in thread “main” java.lang.OutOfMemoryError: Java heap space

Du habe ich den Speicher in property/run/VM box

Jede Idee, die zugeteilt werden, wie kann ich über Java-Beispiel ausführen Befehlszeile?

Ich will die Stimmung Punktzahl des Beispiels

UPDATE

Ausgang erhalten: java -cp "*" -mx1g edu.stanford.nlp.sentiment.SentimentPipeline -file input.txt

enter image description here

löschte von: java -cp stanford-corenlp-3.3.0.j ar;stanford-corenlp-3.3.0-models.jar;xom.jar;joda-time.jar -Xmx600m edu.stanford .nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,parse -file input.txt

Out of of above command

+0

Was wurde in Ihrem einen Beispiel produziert, das funktionierte? (Das ist "H: \ Laufwerk E \ Stanford \ stanfor-corenlp-full-2013 ~ \ input.txt.xml") –

+0

@home: 'OutOfMemoryError' Ich habe bereits nach den Lösungen im Web gesucht und daran gearbeitet. Immer noch gleichen Fehler – user123

+0

@ ElliottFrisch: Bitte siehe Ich aktualisierte die Frage – user123

Antwort

14

Sie müssen das „Gefühl“ Kommentator in die Liste der Annotatoren hinzuzufügen:

-annotators tokenize,ssplit,pos,lemma,parse,sentiment 

ein „Gefühl“ Eigenschaft Dies wird in den einzelnen Satz Knoten in Ihrem XML.

+0

Ich fand das Beispiel, wo nicht alle 6 Annotatoren, die zur Stimmungsanalyse verwendet werden, aber nur 4. POS & Lemma sind nicht enthalten, wie kann es die Ergebnisse beeinflussen? Beispiel: https://blog.openshift.com/day-20-stanford-corenlp-performing-sentiment-analysis-of-twitter-using-java/ –

3

Für das Beispiel here müssen Sie die Sentiment-Analyse ausführen.

Offenbar ist dies eine Speicher teure Operation, kann es nicht mit nur 1 Gigabyte abgeschlossen. Dann können Sie die „Evaluation Tool“

java -cp "*" edu.stanford.nlp.sentiment.Evaluate edu/stanford/nlp/models/sentiment/sentiment.ser.gz input.txt 
+1

Elliott: Sie haben Recht, aber ich nahm '-mx1g' nach meiner Systemkonfiguration, und in der Befehlszeile funktionierte es auch – user123

+0

haben Sie Erfahrung von Stanford coreNLP Stimmung Teil zu testen ? – user123

+0

Nein, ich habe Erfahrung mit einer kommerziellen Stimmungsmaschine und Sie haben Stimmungsnoten dort in diesem Bild. –

20

Sie können in Ihrem Code Folgendes tun:

String text = "I am feeling very sad and frustrated."; 
Properties props = new Properties(); 
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse, sentiment"); 
StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 
<...> 
Annotation annotation = pipeline.process(text); 
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); 
for (CoreMap sentence : sentences) { 
    String sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class); 
    System.out.println(sentiment + "\t" + sentence); 
} 

Es wird die Stimmung des Satzes drucken und den Satz selbst, z.B. "Ich fühle mich sehr traurig und frustriert.„:

Negative I am feeling very sad and frustrated. 
+0

Wohin geben Sie den eingegebenen Satz im Programm? – Naveen

+0

Zum Beispiel hinzugefügt Annotation Annotation = pipeline.process (text); – saganas

1

Dies funktioniert gut für mich -

Maven Abhängigkeiten:

 <dependency> 
      <groupId>edu.stanford.nlp</groupId> 
      <artifactId>stanford-corenlp</artifactId> 
      <version>3.5.2</version> 
      <classifier>models</classifier> 
     </dependency> 
     <dependency> 
      <groupId>edu.stanford.nlp</groupId> 
      <artifactId>stanford-corenlp</artifactId> 
      <version>3.5.2</version> 
     </dependency> 
     <dependency> 
      <groupId>edu.stanford.nlp</groupId> 
      <artifactId>stanford-parser</artifactId> 
      <version>3.5.2</version> 
     </dependency> 

Java-Code:

public static void main(String[] args) throws IOException { 
     String text = "This World is an amazing place"; 
     Properties props = new Properties(); 
     props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse, sentiment"); 
     StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 

     Annotation annotation = pipeline.process(text); 
     List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); 
     for (CoreMap sentence : sentences) { 
      String sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class); 
      System.out.println(sentiment + "\t" + sentence); 
     } 
    } 

Ergebnisse:

Sehr positiv Diese Welt ist ein amazi ng place

Verwandte Themen