wordnet代码中的RetrievalException

时间:2014-02-11 11:57:19

标签: java wordnet jaws-wordnet

我执行了这段代码:

package edu.smu.tspell.wordnet;

import java.util.Scanner;

public class TestJAWS
{

    /**
     * Main entry point. The command-line arguments are concatenated together
     * (separated by spaces) and used as the word form to look up.
     */
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);

        args =  new String[] {"airplane"};
        if (args.length > 0)
        {
            //  Concatenate the command-line arguments
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; i < args.length; i++)
            {
                buffer.append((i > 0 ? " " : "") + args[i]);
            }
            String wordForm = buffer.toString();
            //  Get the synsets containing the wrod form
            WordNetDatabase database = WordNetDatabase.getFileInstance();
            Synset[] synsets = database.getSynsets(wordForm);
            //  Display the word forms and definitions for synsets retrieved
            if (synsets.length > 0)
            {
                System.out.println("The following synsets contain '" +
                        wordForm + "' or a possible base form " +
                        "of that text:");
                for (int i = 0; i < synsets.length; i++)
                {
                    System.out.println("");
                    String[] wordForms = synsets[i].getWordForms();
                    for (int j = 0; j < wordForms.length; j++)
                    {
                        System.out.print((j > 0 ? ", " : "") +
                                wordForms[j]);
                    }
                    System.out.println(": " + synsets[i].getDefinition());
                }
            }
            else
            {
                System.err.println("No synsets exist that contain " +
                        "the word form '" + wordForm + "'");
            }
        }
        else
        {
            System.err.println("You must specify " +
                    "a word form for which to retrieve synsets.");
        }
    }

}

但是我收到了这个错误:

Exception in thread "main" edu.smu.tspell.wordnet.impl.file.RetrievalException: Error opening index file: .\C:\Users\piyush_p\Desktop\workspace\Wordnet\src\WordNet-3.0\dict\index.sense (The filename, directory name, or volume label syntax is incorrect)
    at edu.smu.tspell.wordnet.impl.file.SenseIndexReader.getInstance(SenseIndexReader.java:88)
    at edu.smu.tspell.wordnet.impl.file.WordFormLookup.loadSynsets(WordFormLookup.java:273)
    at edu.smu.tspell.wordnet.impl.file.WordFormLookup.getSynsets(WordFormLookup.java:230)
    at edu.smu.tspell.wordnet.impl.file.WordFormLookup.getSynsets(WordFormLookup.java:172)
    at edu.smu.tspell.wordnet.impl.file.FileDatabase.getSynsets(FileDatabase.java:87)
    at edu.smu.tspell.wordnet.WordNetDatabase.getSynsets(WordNetDatabase.java:61)
    at edu.smu.tspell.wordnet.TestJAWS.main(TestJAWS.java:28)
Caused by: java.io.FileNotFoundException: .\C:\Users\piyush_p\Desktop\workspace\Wordnet\src\WordNet-3.0\dict\index.sense (The filename, directory name, or volume label syntax is incorrect)
    at java.io.RandomAccessFile.open(Native Method)
    at java.io.RandomAccessFile.<init>(Unknown Source)
    at edu.smu.tspell.wordnet.impl.RandomAccessReader.<init>(RandomAccessReader.java:75)
    at edu.smu.tspell.wordnet.impl.LineLocator.<init>(LineLocator.java:54)
    at edu.smu.tspell.wordnet.impl.MultipleLineLocator.<init>(MultipleLineLocator.java:48)
    at edu.smu.tspell.wordnet.impl.file.SenseIndexReader.<init>(SenseIndexReader.java:102)
    at edu.smu.tspell.wordnet.impl.file.SenseIndexReader.getInstance(SenseIndexReader.java:83)
    ... 6 more`enter code here`

2 个答案:

答案 0 :(得分:2)

通过添加

解决了这个问题
`System.setProperty("wordnet.database.dir", "C:\WordNet-3.0\dict\");` 
主要方法

中的

答案 1 :(得分:1)

看起来你还没有下载数据库。因此,从下面给出的链接下载WordNet数据库: http://wordnet.princeton.edu/wordnet/download/current-version/

为数据库目录添加“dict”目录的路径:

System.setProperty("wordnet.database.dir", "/home/xyz/WordNet-3.0/dict");