это класс, который реализует StanfordNLP - "SentimentAnalyzer".
Я хочу использовать с этим классом несколько раз для различных алгоритмов.
Где я должен назвать этот класс, чтобы он не повредил мне, когда я запускаю проект?
открытый класс SentimentAnalyzer {
private StanfordCoreNLP pipeline;
//private Hashtable<String, ArrayList<String>> POS_TaggingArray; // k, v
public void initializeCoreNLP() {
Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse");
pipeline = new StanfordCoreNLP(props);
}
public void getSentiment(String text) {
int index = 0;
Annotation annotation= new Annotation(text);
pipeline.annotate(annotation);
Hashtable<String, ArrayList<String>> POS_array = new Hashtable<String, ArrayList<String>>();
List<String> sentances_list=new ArrayList<>( );
List<Tree> constituencyParse = new ArrayList<>( );
List<String> W_lemmas= new ArrayList<>( );
String[] ner;
ner = new String[text.length()];
List<CoreMap> sentences = annotation.get( CoreAnnotations.SentencesAnnotation.class ); //divide to sentences
for (CoreMap sentence : sentences) {
sentances_list.add( sentence.toString() );
constituencyParse.add( sentence.get(TreeCoreAnnotations.TreeAnnotation.class) ) ;
for (CoreLabel token : sentence.get( CoreAnnotations.TokensAnnotation.class )) {
String word = token.get( CoreAnnotations.TextAnnotation.class );//get the word
String pos = token.get( CoreAnnotations.PartOfSpeechAnnotation.class );//get part of sentance
String key = String.valueOf( POS_array.get(pos) );
if(key.equals( "null" )) {
POS_array.put(pos, new ArrayList<String>());
POS_array.get(pos).add(word);
} else{
POS_array.get(pos).add(word);
}
if(pos.equals( "NN" ) || pos.equals( "NNS" ) || pos.equals( "NNP" ) || pos.equals( "NNSP" )){ //for w list
W_lemmas.add( token.get(CoreAnnotations.LemmaAnnotation.class) );
String role = token.get( CoreAnnotations.NamedEntityTagAnnotation.class );
if (!(role==null)) {
ner[index]=role;
}
else {
ner[index]="empty";
}
}
index+=1;
}
}
}
}