2016-11-26 114 views
0

我想用Java中的斯坦福NLP做一些情感分析。我正在使用Maven,但出現以下錯誤:斯坦福大學NLP RuntimeIOException

java.lang.Exception: edu.stanford.nlp.io.RuntimeIOException: java.io.IOException: Unable to resolve "/home/amos/CPP/2016/Hadoop/englishPCFG.ser.gz" as either class path, filename or URL 
    at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:462) 
    at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:522) 
Caused by: edu.stanford.nlp.io.RuntimeIOException: java.io.IOException: Unable to resolve "/home/amos/CPP/2016/Hadoop/englishPCFG.ser.gz" as either class path, filename or URL 
    at edu.stanford.nlp.parser.common.ParserGrammar.loadModel(ParserGrammar.java:182) 
    at edu.stanford.nlp.pipeline.ParserAnnotator.loadModel(ParserAnnotator.java:187) 
    at edu.stanford.nlp.pipeline.ParserAnnotator.<init>(ParserAnnotator.java:107) 
    at edu.stanford.nlp.pipeline.AnnotatorImplementations.parse(AnnotatorImplementations.java:132) 
    at edu.stanford.nlp.pipeline.AnnotatorFactories$10.create(AnnotatorFactories.java:420) 
    at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:85) 
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:289) 
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:126) 
    at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:122) 
    at nl.uva.cpp.WordCountMapper.create_pipeline(WordCountMapper.java:68) 
    at nl.uva.cpp.WordCountMapper.map(WordCountMapper.java:73) 
    at nl.uva.cpp.WordCountMapper.map(WordCountMapper.java:22) 
    at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145) 
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:784) 
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341) 
    at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:243) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.io.IOException: Unable to resolve "/home/amos/CPP/2016/Hadoop/englishPCFG.ser.gz" as either class path, filename or URL 
    at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:448) 
    at edu.stanford.nlp.io.IOUtils.readObjectFromURLOrClasspathOrFileSystem(IOUtils.java:310) 
    at edu.stanford.nlp.parser.common.ParserGrammar.loadModel(ParserGrammar.java:179) 
    ... 20 more 

我不確定該怎麼做。我已經從here下載了Stanford CoreNLP,但我不確定我應該在哪裏提取它。

我還添加了

<dependency> 
    <groupId>edu.stanford.nlp</groupId> 
    <artifactId>stanford-corenlp</artifactId> 
    <version>3.5.0</version> 
</dependency> 
<dependency> 
    <groupId>edu.stanford.nlp</groupId> 
    <artifactId>stanford-corenlp</artifactId> 
    <version>3.5.0</version> 
    <classifier>models</classifier> 
</dependency> 

pom.xml文件,並開始運行mvn package時下載,但似乎並沒有幫助。

+0

提取罐子到你的項目文件夾。像projectPath/lib – Nuwanda

回答

0

當你正在使用Hadoop,您可以通過使用Maven Shade Plugin

用java脂肪罐子項目的建設項目(MVN包),它會創建一個單獨的jar具有所有依賴性合併成it.You需要經過把你的hadoop驅動類作爲mainClass在這裏就像

<transformer> implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
<mainClass>your-driver-class</mainClass> 
</transformer>