/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package de.hsbo.fbg.sm4c.classify.filter;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import opennlp.tools.postag.POSModel;
import opennlp.tools.postag.POSTagger;
import opennlp.tools.postag.POSTaggerME;
import org.apache.logging.log4j.LogManager;

/**
 * Class for identifying the part of speech of a text
 *
 * @author Sebastian Drost
 */
public class PartOfSpeechTagger {

    private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(PartOfSpeechTagger.class);

    public static final String DEFAULT_POS_MODEL = "de-pos-maxent.bin";

    private POSModel posModel;
    private POSTagger posTagger;

    /**
     * Trains the part of speech tagger with a given POS Model.
     *
     * @param modelPath path starting from the classpath to the model
     */
    public void trainPOSModel(String modelPath) {
        try (InputStream in = this.getClass().getClassLoader().getResourceAsStream(modelPath)) {
            posModel = new POSModel(in);
            posTagger = new POSTaggerME(posModel);
        } catch (IOException ex) {
            LOGGER.error("Could not load tokenizer model", ex);
        }
    }

    /**
     * Tags the part of speech for given tokens.
     *
     * @param tokens Tokens to tag
     * @return List of tags for the tokens
     */
    public List<String> tagTokens(List<String> tokens) {
        return Arrays.asList(posTagger.tag(tokens.toArray(new String[0])));
    }

}

@@ -232,27 +232,45 @@
 ort 
-java.io.IOExcep
+edu.stanford.nlp.ling.CoreAnnota
 tion
+s
 ;%0Aim
@@ -278,297 +278,264 @@
 ort 
-java.io.InputStream;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport opennlp.tools.postag.POSModel;%0Aimport opennlp.tools.postag.POSTagger;%0Aimport opennlp.tools.postag.POSTaggerME;%0Aimport org.apache.logging.log4j.LogManager;%0A%0A/**%0A * Class for identifying the part of speech of a text
+edu.stanford.nlp.pipeline.Annotation;%0Aimport edu.stanford.nlp.pipeline.StanfordCoreNLP;%0Aimport edu.stanford.nlp.util.CoreMap;%0Aimport edu.stanford.nlp.util.PropertiesUtils;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Properties;%0A%0A/**
 %0A *%0A
@@ -616,405 +616,562 @@
 ate 
-static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(PartOfSpeechTagger.class);%0A%0A    public static final String DEFAULT_POS_MODEL = %22de-pos-maxent.bin%22;%0A%0A    private POSModel posModel;%0A    private POSTagger posTagger;%0A
+StanfordCoreNLP pipeline;%0A%0A    public PartOfSpeechTagger() %7B%0A        Properties props = PropertiesUtils.asProperties(%0A                %22annotators%22, %22tokenize, ssplit, pos%22,%0A                %22ssplit.isOneSentence%22, %22true%22,
 %0A    
-/**%0A
+    
      
-* Trains the part of speech tagger with a given POS Model.%0A
+   %22pos.model%22, %22edu/stanford/nlp/models/pos-tagger/german/german-hgc.tagger%22,%0A     
      
-*%0A
      
-* @param modelPath path starting from the classpath to the model
+ %22ner.model%22, %22edu/stanford/nlp/models/ner/german.conll.hgc_175m_600.crf.ser.gz%22,%0A                %22tokenize.language%22, %22de%22,%0A                %22ner.useSUTime%22, %22false%22);%0A        this.pipeline = new StanfordCoreNLP(props);
 %0A    
- */
+%7D%0A
 %0A   
@@ -1182,332 +1182,493 @@
 lic 
-void 
+List%3CS
 tr
-a
 in
-POSModel(String modelPath) %7B%0A        try (InputStream in = this.getClass().getClassLoader().getResourceAsStream(modelPath)) %7B%0A            posModel = new POSModel(in);%0A            posTagger = new POSTaggerME(posModel);%0A        %7D catch (IOException ex) %7B%0A            LOGGER.error(%22Could not load tokenizer model%22, ex
+g%3E tagPOS(String text) %7B%0A        Annotation document = new Annotation(text);%0A        pipeline.annotate(document);%0A        List%3CCoreMap%3E sentences = document.get(CoreAnnotations.SentencesAnnotation.class);%0A        List%3CString%3E result = new ArrayList();%0A%0A        sentences.forEach(s -%3E %7B%0A            s.get(CoreAnnotations.TokensAnnotation.class).forEach(t -%3E %7B%0A                String value = t.get(CoreAnnotations.PartOfSpeechAnnotation.class);%0A                result.add(value
 );%0A 
@@ -1678,298 +1678,421 @@
     
-%7D%0A
     %7D
+);
 %0A%0A    
-/**%0A     * Tags the part of speech for given tokens.%0A
+    %7D);%0A%0A//        sentences.forEach(s -%3E %7B%0A//
      
-*%0A
      
-* @param tokens Tokens to tag%0A     * @return List of tags for the tokens%0A
+  s.get(CoreAnnotations.MentionsAnnotation.class).forEach(em -%3E %7B%0A//    
      
-*/%0A
     
-public List%3CString%3E tagTokens(List%3CString%3E tokens) %7B%0A        return Arrays.asList(posTagger.tag(tokens.toArray(new String%5B0%5D)))
+   String value = em.get(CoreAnnotations.TextAnnotation.class);%0A//                String tag = em.get(CoreAnnotations.NamedEntityTagAnnotation.class);%0A//                result.add(new NamedEntity(value, tag));%0A//            %7D);%0A//        %7D);%0A        return result
 ;%0A  

improve POS tagging