【问题标题】:Stemming with WordNet using JWNL - Unable to install dictionary使用 JWNL 使用 WordNet 提取词干 - 无法安装字典
【发布时间】:2012-05-21 16:20:20
【问题描述】:

我正在尝试使用 WordNet 和 JWNL API 来阻止字符串。当我尝试加载字典时,它给了我一个 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\ - 所以应该可以吗?

【问题讨论】:

    标签: java api dictionary filenotfoundexception wordnet


    【解决方案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 中,我给出了错误的路径:

    &lt;param name="dictionary_path" value="C:/Program Files/WordNet/"/&gt;

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

    &lt;param name="dictionary_path" value="C:/Program Files/WordNet/2.1/dict/"/&gt;

    所以我的问题解决了。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          【解决方案4】:

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

          【讨论】:

          • 文件映射基于正在使用的 wordnet 版本。并且应该在初始化文件中指定。
          【解决方案5】:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多