JWKTL - 无法连接到数据库

时间:2016-06-16 13:08:29

标签: java wiktionary

我正在尝试将JWKTL库安装到Java项目中。 JWKTL Getting started

现在我按照描述下载了转储文件,并将其解析为一个新目录。

我的代码是:

package main;

import java.io.File;
import java.util.List;

import de.tudarmstadt.ukp.jwktl.JWKTL;
import de.tudarmstadt.ukp.jwktl.api.IWiktionaryEdition;
import de.tudarmstadt.ukp.jwktl.api.IWiktionaryEntry;
import de.tudarmstadt.ukp.jwktl.api.IWiktionaryPage;
import de.tudarmstadt.ukp.jwktl.api.IWiktionaryRelation;
import de.tudarmstadt.ukp.jwktl.api.PartOfSpeech;
import de.tudarmstadt.ukp.jwktl.api.RelationType;


public class Main {

    final static String PATH_TO_DUMP_FILE = "/GetWords/enwiktionary-20160601-pages-articles-multistream.xml";
    final static String TARGET_DIRECTORY = "/GetWords/";
    final static boolean OVERWRITE_EXISTING_FILES = true;
    /**
     * Simple example which parses an English dump file and prints the entries for the word <i>Wiktionary</i>
     * @param args name of the dump file, output directory for parsed data, ISO language code of the Wiktionary entry language (en/de), boolean value that specifies if existing parsed data should be deleted
     */
        public static void main(String[] args) throws Exception {
            File dumpFile = new File(PATH_TO_DUMP_FILE);
              File outputDirectory = new File(TARGET_DIRECTORY);
              boolean overwriteExisting = OVERWRITE_EXISTING_FILES;

              JWKTL.parseWiktionaryDump(dumpFile, outputDirectory, overwriteExisting);

              IWiktionaryEdition wkt = JWKTL.openEdition(TARGET_DIRECTORY);

              //TODO: Query the data you need.

              // Close the database connection.
              wkt.close();
}
}

但是当我尝试输入dump_file时,行IWiktionaryEdition wkt = JWKTL.openEdition(TARGET_DIRECTORY);会抛出错误:The method openEdition(File) in the type JWKTL is not applicable for the arguments (String) 的java.io.File

程序抛出以下错误:

Exception in thread "main" de.tudarmstadt.ukp.jwktl.api.WiktionaryException: Unable to establish a db connection
    at de.tudarmstadt.ukp.jwktl.api.entry.BerkeleyDBWiktionaryEdition.<init>(BerkeleyDBWiktionaryEdition.java:228)
    at de.tudarmstadt.ukp.jwktl.api.entry.BerkeleyDBWiktionaryEdition.<init>(BerkeleyDBWiktionaryEdition.java:205)
    at de.tudarmstadt.ukp.jwktl.JWKTL.openEdition(JWKTL.java:98)
    at de.tudarmstadt.ukp.jwktl.JWKTL.openEdition(JWKTL.java:89)
    at main.Main.main(Main.java:31)
Caused by: java.lang.IllegalArgumentException: Malformed \uxxxx encoding.
    at java.util.Properties.loadConvert(Unknown Source)
    at java.util.Properties.load0(Unknown Source)
    at java.util.Properties.load(Unknown Source)
    at com.sleepycat.je.dbi.DbConfigManager.applyFileConfig(DbConfigManager.java:388)
    at com.sleepycat.je.Environment.setupHandleConfig(Environment.java:323)
    at com.sleepycat.je.Environment.<init>(Environment.java:260)
    at com.sleepycat.je.Environment.<init>(Environment.java:212)
    at de.tudarmstadt.ukp.jwktl.api.entry.BerkeleyDBWiktionaryEdition.connect(BerkeleyDBWiktionaryEdition.java:241)
    at de.tudarmstadt.ukp.jwktl.api.entry.BerkeleyDBWiktionaryEdition.<init>(BerkeleyDBWiktionaryEdition.java:224)
    ... 4 more

有人知道如何解决这个问题吗?

我在Eclipse Mars中使用Java 8。

我安装了这些库:

  • jwktl-1.0.1.jar
  • JE-6.4.25.jar
  • 阿帕奇-ANT-1.8.2.jar

谢谢!

1 个答案:

答案 0 :(得分:0)

我解决了...... 这太简单了:

结论是:

File f = new File(TARGET_DIRECTORY);

IWiktionaryEdition wkt = JWKTL.openEdition(f);

祝你好运!