我正在尝试将一个Turtle文件加载到Android studio中,并使用Androjena库对该Turtle文件运行查询。我可以用JavaFX在Eclipse中做到这一点,没有任何问题。然而,在Intellij IDE中,我得到了一个致命的错误,这显然会使我的应用程序崩溃。我有一个名为runQuery()的方法,调用该方法是为了对文件运行查询:
public String runQuery(){
String stringQuery = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n" +
"PREFIX dbo: <http://dbpedia.org/ontology/> \n" +
"SELECT ?birthDate WHERE { \n" +
"?barack foaf:name \"Barack Obama\"@en .\n" +
"?barack dbo:birthDate ?birthDate \n" +
"}";
String answer = "";
Model model = FileManager.get().loadModel("sample_pres.ttl", "TTL");
Query query = QueryFactory.create(stringQuery);
try {
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
while(results.hasNext()) {
QuerySolution soln = results.nextSolution();
Literal answerLiteral = soln.getLiteral("birthDate");
answer = answerLiteral.toString();
}
}
catch(Exception ignore) {
}
this.answer = answer;
return answer;
}
给我带来问题的代码行是FileManager.get().loadModel()行。下面是我得到的一个例外:
com.hp.hpl.jena.shared.NotFoundException: Not found: sample_pres.ttl
因此,我认为Android没有找到该文件,尽管该文件在我的Assets文件夹中。我假设我不/不能使用AssetManager,因为我不想包含FileInputStream。所以我在这一点上被卡住了。以下是我的项目结构图:
我在项目结构中的app/src/main下添加了assets文件夹。我是Android Studio的新手,我知道在eclipse的JavaFX中,我可以简单地使用文件的绝对路径来访问它,我知道这显然不能在Android Studio中工作。但是,我找不到一个示例来从Android项目(my assets文件夹)中的本地源加载Turtle文件并执行查询。此站点上的每个示例或问题似乎都与通过internet连接从外部终结点运行查询有关。这就是我感到困惑的部分原因。我不确定如何从Android studio中的本地源运行查询,并引用我的assets文件夹中的海龟文件,以避免com.hp.hpl.jena.shared.NotFoundException
https://stackoverflow.com/questions/52802063
复制相似问题