FileNotFoundException,URL连接错误,Babelfy,Java

时间:2015-04-19 10:39:40

标签: java

来自Babelfy的示例程序在一天内正常运行,第二天我运行时遇到此错误:

线程“main”中的异常java.io.FileNotFoundException:http://babelfy.org/rest?text=He%20has%20a%20passion%20for%20music&key=%20&partMatching=false&lang=EN&format=json     at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)     at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)     at it.uniroma1.lcl.babelfy.Babelfy.babelfy(Babelfy.java:95)     在Example.main(Example.java:19)

示例是Java程序的名称。

以下是代码:

import it.uniroma1.lcl.babelfy.Babelfy;
import it.uniroma1.lcl.babelfy.Babelfy.Matching;
import it.uniroma1.lcl.babelfy.Babelfy.AccessType;
import it.uniroma1.lcl.babelfy.data.Annotation;
import it.uniroma1.lcl.babelfy.data.BabelSynsetAnchor;
import it.uniroma1.lcl.babelnet.BabelNet;
import it.uniroma1.lcl.babelnet.BabelSense;
import it.uniroma1.lcl.babelnet.BabelSynset;
import it.uniroma1.lcl.jlt.util.Language;

public class Example 
{
public static void main(String[] args) throws Exception 
{
    Babelfy bfy = Babelfy.getInstance(AccessType.ONLINE);
    BabelNet bn = BabelNet.getInstance();
    String word=" ";
    String inputText = "He has a passion for music";
    Annotation annotations = bfy.babelfy(" ", inputText, Matching.EXACT, Language.EN);
    System.out.println("inputText: "+inputText+"\nannotations:");
    for(BabelSynsetAnchor annotation : annotations.getAnnotations())
    {
        word=annotation.getBabelSynset().getId();
        System.out.println(annotation.getAnchorText()+"\t"+word+"\t"+annotation.getBabelSynset());
        //BabelSynset by = bn.getSynsetFromId(("bn:03083790n"));
    for (BabelSense sense : bn.getSynsetFromId((word))) 
     {
        if(sense.getSource().toString().equals("WN"))
            System.out.println("Sense: " + sense.getLemma()+ "\tSource: " + sense.getSource().toString());
     }
    }

}   
}

我在Eclipse项目的构建路径中添加了0.9和1.0版本Babelfy的库?

有人能找到错误的性质吗?

1 个答案:

答案 0 :(得分:1)

似乎Babelfy-API已经过时了。它会尝试连接到http://babelfy.org/restis not available (anymore)

版本1.0仍然是当前版本,因此请删除您的0.9版本。 Java可能会选择它找到的第一个版本,可能是0.9。

删除0.9.jar后,您应该可以进行正确的API调用。