在Android Studio项目中添加StanfordCoreNLP库时出现(java.lang.VerifyError:Rejecting class)错误

时间:2018-02-07 16:59:40

标签: java android android-studio jar stanford-nlp

我正在开发一个Android应用程序(我是初学者)。我想在我的应用程序中使用Stanford CoreNLP 3.8.0库从用户句子中提取词性,引理,解析器等。

我已经按照这个youtube教程https://www.youtube.com/watch?v=9IZsBmHpK3Y在NetBeans中尝试了一个简单的java代码,它运行正常。

我导入NetBeans项目的jar文件是:stanford-corenlp-3.8.0.jar和stanford-corenlp-3.8.0-models.jar。

这是java源代码:

import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.util.CoreMap;

import java.util.List;
import java.util.Properties;

public class CoreNlpExample {

    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 = "What is the Weather in Bangalore right now?";

        // 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);

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

我想在Android Studio中尝试相同的代码,但我在Android Studio 3.0.1项目中添加这些外部库时遇到了问题。

我在一些网站上看到我需要减少jar文件的大小,我这样做并确保减少的jar在Netbeans项目中仍能正常工作。但我仍然在Android工作室遇到问题,这是我得到的错误:

java.lang.VerifyError: Rejecting class edu.stanford.nlp.pipeline.StanfordCoreNLP that attempts to sub-type erroneous class edu.stanford.nlp.pipeline.AnnotationPipeline (declaration of 'edu.stanford.nlp.pipeline.StanfordCoreNLP' appears in /data/app/com.example.fatimah.nlpapplication-bhlUJOCUwLhSbkWE7NBERA==/split_lib_dependencies_apk.apk)

有关如何解决此问题并成功导入斯坦福图书馆的任何建议?

0 个答案:

没有答案