Je trouve que les données pour former le modèle de sentiment dans train.txt est le format PTB ressemble à ceci.Créer un autre train.txt pour former le modèle de sentiment pour d'autres domaines
(3 (2 Yet) (3 (2 (2 the) (2 act)) (3 (4 (3 (2 is) (3 (2 still) (4 charming))) (2 here)) (2 .))))
que la vraie phrase devrait être
Yet the act is still charming here.
Mais après Parse je suis arrivé la structure différente
(ROOT (S (CC Yet) (NP (DT the) (NN act)) (VP (VBZ is) (ADJP (RB still) (JJ charming)) (ADVP (RB here))) (. .)))
suit mon code:
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,parse");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// read some text in the text variable
String text = "Yet the act is still charming here .";// Add your text here!
// create an empty Annotation just with the given text
Annotation annotation = new Annotation(text);
// run all Annotators on this text
pipeline.annotate(annotation);
// these are all the sentences in this document
// a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
// int sentiment = 0;
for(CoreMap sentence: sentences) {
// traversing the words in the current sentence
Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
System.out.println(tree);
// System.out.println(tree.yield());
tree.pennPrint(System.out);
// Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
// sentiment = RNNCoreAnnotations.getPredictedClass(tree);
}
// System.out.print(sentiment);
}
Ensuite, deux questions apparaissent quand j'utilise m y possède des phrases pour créer le fichier train.txt.
1.Mon arbre est différent de celui dans train.txt, je sais que le numéro dans le dernier est la polarité du sentiment.Mais il semble que la structure de l'arbre est différent, je veux obtenir un arbre d'analyse binarized qui pourrait ressembler comme celui-ci
((Yet) (((the) (act)) ((((is) ((still) (charming))) (here)) (.))))
Une fois que je reçois le numéro de sentiment que je peux le remplir pour obtenir mon propre train.txt
2.How pour obtenir toutes les phrases à chaque nœud de l'arbre d'analyse syntaxique binarisée, dans cet exemple , Je devrais obtenir
Yet
the
act
the act
is
still
charming
still charming
is still charming
here
is still charming here
.
is still charming here .
the act is still charming here .
Yet the act is still charming here.
Une fois que je les ai, je peux dépenser de l'argent en les annotant par des annotateurs humains.
En fait, je les ai beaucoup googlé, mais je n'ai pas pu les résoudre, alors je poste ici.Toutes les réponses utiles seraient les bienvenues!
Génial! Si je veux former un modèle de sentiment chinois, la phrase dans train.txt doit toujours être binaire analysée? @StanfordNLPHelp – ryh