Как получить сложные термины в Stanford CoreNLP / Apache Open NLP - PullRequest
0 голосов
/ 22 марта 2019

Я использовал Google NLP в своем проекте.Когда я использую Google NLP для извлечения терминов, тогда Google NLP возвращает единичные / составные термины в ответ.

например: Когда я отправляю «Полный теоретический анализ гидравлики конкретной водопропускной установки является трудоемким и сложным».текст в Google NLP API, затем он возвращает термины «анализ», «гидравлика», «установка водопропускной трубы» и т. д.

Теперь я пытаюсь сделать это с помощью библиотек OpenNLP / CoreNLP.Я пробовал это с классом токенизатора, где у меня есть термин с одним словом, но мне также нужны два / более слова.В приведенном выше примере я получил термин «установка водопропускной трубы», который состоит из двух слов.

  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, pos, lemma, ner, parse, dcoref");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

    // read some text in the text variable
    String text = "A complete theoretical analysis of the hydraulics of a particular culvert installation is time-consuming and complex.";

    // create an empty Annotation just with the given text
    Annotation document = new Annotation(text);

    // run all Annotators on this text
    pipeline.annotate(document);

    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);

    for (CoreMap sentence : sentences) {
        // traversing the words in the current sentence
        // a CoreLabel is a CoreMap with additional token-specific methods
        for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
            // this is the text of the token
            String word = token.get(CoreAnnotations.TextAnnotation.class);
            // this is the POS tag of the token
            String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
            // this is the NER label of the token
            String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);

            String  lemma =token.getString(CoreAnnotations.LemmaAnnotation.class);

            System.out.println(String.format("Print: word: [%s] pos: [%s] ne: [%s] lemma: [%s]", word, pos, ne, lemma));

        String ner=token.get(NamedEntityTagAnnotation.class);
        System.out.println("##### "+ner);
        }
    }
}
...