1

我正在尝试使用带有 JWNL API 的 WordNet 来阻止字符串。当我尝试加载字典时,它给了我一个 FileNotFoundException。

这是初始化字典的代码:

public static void Initializer(){
    try {
        JWNL.initialize(new FileInputStream("file_properties.xml"));
        dictionary = Dictionary.getInstance();
        morphPro = dictionary.getMorphologicalProcessor();
    }
    catch(FileNotFoundException e){
        e.printStackTrace();

    } catch (JWNLException e) {
        e.printStackTrace();
    }
}

这就是我得到的:

net.didion.jwnl.JWNLException: Unable to install net.didion.jwnl.dictionary.FileBackedDictionary
    at net.didion.jwnl.util.factory.Element.install(Element.java:34)
    at net.didion.jwnl.JWNL.initialize(JWNL.java:169)
    at Algorithms.Stemmer.Initializer(Stemmer.java:54)
    at Algorithms.Stemmer.WordStemmer(Stemmer.java:33)
    at Algorithms.Stemmer.StringStemmer(Stemmer.java:26)
    at GUI.ButtonListener.actionPerformed(ButtonListener.java:167)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: net.didion.jwnl.JWNLException: The properties file must specify a dictionary path
    at net.didion.jwnl.util.factory.AbstractValueParam.create(AbstractValueParam.java:34)
    at net.didion.jwnl.dictionary.FileBackedDictionary.install(FileBackedDictionary.java:111)
    at net.didion.jwnl.util.factory.Element.install(Element.java:32)

我很确定它与路径有关,但我无法确切找出问题所在,因为我更改了properties.xml要使用的文件C:\WordNet\2.1\dict\- 所以应该没问题吗?

4

5 回答 5

1

将版本号更改为file_properties.xml正确的版本。

于 2013-08-30T19:15:04.847 回答
1

我也遇到了同样的问题。错误是:

gate.creole.ResourceInstantiationException: net.didion.jwnl.JWNLException: Unable to install net.didion.jwnl.dictionary.FileBackedDictionary
    at gate.wordnet.JWNLWordNetImpl.init(JWNLWordNetImpl.java:62)
    at gate.Factory.createResource(Factory.java:432)
    at gate.Factory.createResource(Factory.java:139)
    at WordNetApp.main(WordNetApp.java:45)
Caused by: net.didion.jwnl.JWNLException: Unable to install net.didion.jwnl.dictionary.FileBackedDictionary
    at net.didion.jwnl.util.factory.Element.install(Element.java:34)
    at net.didion.jwnl.JWNL.initialize(JWNL.java:169)
    at gate.wordnet.JWNLWordNetImpl.init(JWNLWordNetImpl.java:57)
    ... 3 more
Caused by: net.didion.jwnl.JWNLException: The properties file must specify a dictionary path
    at net.didion.jwnl.util.factory.AbstractValueParam.create(AbstractValueParam.java:34)
    at net.didion.jwnl.dictionary.FileBackedDictionary.install(FileBackedDictionary.java:111)
    at net.didion.jwnl.util.factory.Element.install(Element.java:32)
    ... 5 more
Caused by: net.didion.jwnl.JWNLException: Could not create a file manager of type class net.didion.jwnl.princeton.file.PrincetonRandomAccessDictionaryFile
    at net.didion.jwnl.dictionary.file_manager.FileManagerImpl.create(FileManagerImpl.java:98)
    at net.didion.jwnl.util.factory.AbstractValueParam.create(AbstractValueParam.java:32)
    ... 7 more
Caused by: 

java.io.FileNotFoundException: C:\Program Files\WordNet\index.verb

(The system cannot find the file specified)
        at java.io.RandomAccessFile.open(Native Method)
        at java.io.RandomAccessFile.<init>(Unknown Source)
        at net.didion.jwnl.princeton.file.PrincetonRandomAccessDictionaryFile.openFile(PrincetonRandomAccessDictionaryFile.java:76)
        at net.didion.jwnl.dictionary.file.AbstractDictionaryFile.open(AbstractDictionaryFile.java:58)
        at net.didion.jwnl.dictionary.file.DictionaryCatalog.open(DictionaryCatalog.java:45)
        at net.didion.jwnl.dictionary.file.DictionaryCatalogSet.open(DictionaryCatalogSet.java:34)
        at net.didion.jwnl.dictionary.file_manager.FileManagerImpl.<init>(FileManagerImpl.java:71)
        at net.didion.jwnl.dictionary.file_manager.FileManagerImpl.create(FileManagerImpl.java:96)
        ... 8 more

所以我发现了问题。在那个 properties.xml 中,我给出了错误的路径:

<param name="dictionary_path" value="C:/Program Files/WordNet/"/>

所以我将其路径更改为包含动词文件的目录:

<param name="dictionary_path" value="C:/Program Files/WordNet/2.1/dict/"/>

所以我的问题解决了。

于 2013-09-04T11:49:50.987 回答
1

同样你需要把data.adj等改成adj.dat的形式(当然如果你不愿意修改file_properties.xml中的版本号)

于 2013-10-15T00:31:15.383 回答
0

好的,所以我发现了问题所在。它正在寻找错误的文件。我将 index.verb、index.adj 等重命名为 verb.idx... 这解决了问题,程序现在能够在字典中查找单词。

于 2012-05-22T11:00:57.290 回答
0

jwnl 不适用于 wordnet 2.1 版本。所以尝试使用wordnet 2.0 然后它可以正常工作。

于 2015-10-13T09:59:39.903 回答