java.io.IOException:无法打开“ ...”作为类路径,文件名或URL

时间:2018-07-19 21:56:41

标签: java python stanford-nlp

我遇到了如下所示的Java IO异常:

Loading unnormalized dictionary from /Users/edamame/Documents/library/stanford/./data//dict/pku.non
Exception in thread "main" edu.stanford.nlp.io.RuntimeIOException: java.io.IOException: Unable to open "/Users/edamame/Documents/library/stanford/./data//dict/pku.non" as class path, filename or URL
    at edu.stanford.nlp.wordseg.CorpusDictionary.readDict(CorpusDictionary.java:80)
    at edu.stanford.nlp.wordseg.CorpusDictionary.<init>(CorpusDictionary.java:40)
    at edu.stanford.nlp.wordseg.CorpusDictionary.<init>(CorpusDictionary.java:35)
    at edu.stanford.nlp.wordseg.NonDict2.<init>(NonDict2.java:32)
    at edu.stanford.nlp.wordseg.Gale2007ChineseSegmenterFeatureFactory.featuresCpC(Gale2007ChineseSegmenterFeatureFactory.java:482)
    at edu.stanford.nlp.wordseg.Gale2007ChineseSegmenterFeatureFactory.getCliqueFeatures(Gale2007ChineseSegmenterFeatureFactory.java:88)
    at edu.stanford.nlp.ie.crf.CRFClassifier.makeDatum(CRFClassifier.java:992)
    at edu.stanford.nlp.ie.crf.CRFClassifier.documentToDataAndLabels(CRFClassifier.java:452)
    at edu.stanford.nlp.ie.crf.CRFClassifier.getSequenceModel(CRFClassifier.java:1185)
    at edu.stanford.nlp.ie.crf.CRFClassifier.classifyMaxEnt(CRFClassifier.java:1218)
    at edu.stanford.nlp.ie.crf.CRFClassifier.classify(CRFClassifier.java:1128)
    at edu.stanford.nlp.ie.AbstractSequenceClassifier$2.process(AbstractSequenceClassifier.java:1172)
    at edu.stanford.nlp.ie.AbstractSequenceClassifier$2.process(AbstractSequenceClassifier.java:1169)
    at edu.stanford.nlp.ie.AbstractSequenceClassifier.classifyAndWriteAnswers(AbstractSequenceClassifier.java:1200)
    at edu.stanford.nlp.ie.AbstractSequenceClassifier.classifyAndWriteAnswers(AbstractSequenceClassifier.java:1133)
    at edu.stanford.nlp.ie.AbstractSequenceClassifier.classifyAndWriteAnswers(AbstractSequenceClassifier.java:1087)
    at edu.stanford.nlp.ie.crf.CRFClassifier.main(CRFClassifier.java:3047)
Caused by: java.io.IOException: Unable to open "/Users/edamame/Documents/library/stanford/./data//dict/pku.non" as class path, filename or URL
    at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:480)
    at edu.stanford.nlp.wordseg.CorpusDictionary.readDict(CorpusDictionary.java:54)
    ... 16 more

似乎找不到"/Users/edamame/Documents/library/stanford/./data//dict/pku.non"

这是我的文件位置:

edamame$ pwd
/Users/edamame/Documents/library/stanford/data/dict
edamame$ ls
pku    pku.gz

我想知道Java到底期望我的文件在哪里?谢谢! (PS。原始代码包装在python中,我在Mac上)

2 个答案:

答案 0 :(得分:1)

/之前,您在dict前加了两个斜杠:

 /Users/edamame/Documents/library/stanford/./data//dict/pku.non

将其更改为:

/Users/edamame/Documents/library/stanford/data/dict/pku.non

答案 1 :(得分:0)

您的路径中的//     / Users / edamame / Documents / library / stanford /./ data // dict / pku.non

在语法上是错误的。我不知道您如何组装此路径字符串,但必须修正此问题才能摆脱异常。