Android 获取foaf:用户配置文件的兴趣
我目前正在建立一个音乐推荐系统。第一步,我想使用FOAF-friend-of-friend构建一个个人用户配置文件,但是当使用SPARQL时,我无法获得FOAF:文件的兴趣是用户配置文件Android 获取foaf:用户配置文件的兴趣,android,sparql,foaf,Android,Sparql,Foaf,我目前正在建立一个音乐推荐系统。第一步,我想使用FOAF-friend-of-friend构建一个个人用户配置文件,但是当使用SPARQL时,我无法获得FOAF:文件的兴趣是用户配置文件 <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:foa
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:admin="http://webns.net/mvcb/">
<foaf:PersonalProfileDocument rdf:about="">
<foaf:maker rdf:resource="#me"/>
<foaf:primaryTopic rdf:resource="#me"/>
<admin:generatorAgent rdf:resource="http://www.ldodds.com/foaf/foaf-a-matic"/>
<admin:errorReportsTo rdf:resource="mailto:leigh@ldodds.com"/>
</foaf:PersonalProfileDocument>
<foaf:Person rdf:ID="me">
<foaf:name>Pham Hai</foaf:name>
<foaf:title>Mr</foaf:title>
<foaf:givenname>Pham</foaf:givenname>
<foaf:family_name>Hai</foaf:family_name>
<foaf:nick>HaiLeader</foaf:nick>
<foaf:mbox_sha1sum>c900f594220ceebb386c02ad2e157cef0fb397b2</foaf:mbox_sha1sum>
<foaf:homepage rdf:resource="http://facebook.com.vn"/>
<foaf:depiction rdf:resource="http://cms.kienthuc.net.vn/zoom/1000/uploaded/manhtu/2016_03_17/hg/anh-noi-y-giuong-chieu-nong-bong-cua-hot-girl-sai-thanh.jpg"/>
<foaf:phone rdf:resource="tel:0962354550"/>
<foaf:interest rdf:resource="http://www.w3.org/2001/sw/"/>
</foaf:Person>
这是我的问题
Model model = FileManager.get().loadModel(FILE_NAME);
showLogAndToast(model.toString());
String queryString =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"SELECT * WHERE { " +
" ?p foaf:interest ?interest ." +
"}";
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = qexec.execSelect();
while (results.hasNext()){
QuerySolution solution = results.nextSolution();
showLogAndToast(solution.toString());
//Literal name = solution.getLiteral("interest");
//showLogAndToast(name.getString());
}
} finally {
qexec.close();
}
编辑
我已经修复了bug。在此之前,我在SPARQL查询中出错了。
非常感谢。适用于我的Apache Jena 3.1.0 在命令行上使用
./sparql --data /tmp/so.rdf --query /tmp/so.query
返回:
------------------------------------------------
| p | interest |
================================================
| <foaf.rdf#me> | <http://www.w3.org/2001/sw/> |
------------------------------------------------
您的Java代码看起来不错,所以不清楚
如果数据加载正确->调用System.out.printlnmodel.size;
如果日志输出显示正确->调用System.out.printlnqs;
此外,兴趣将是一种资源,因此,不要调用qs.getLiteralinterest,而是调用qs.getResourceinterest您使用哪种API?哪个SPARQL查询不起作用?请出示查询。谢谢回答。我已经更新了我的查询,所以你解决了你的问题?该解决方案是否对其他人有用,或者您在此处发布的查询是否存在问题?非常感谢。我使用androjena在Android上开发应用程序。还让我问一下:我想使用xmlns:mo=来具体化我的概要文件中的内容。但安德罗耶纳似乎不支持这一点。我如何为音乐创建用户配置文件?你说androjena不支持这是什么意思?是的,我认为androijena不支持xmlns:mo=purl.org/ontology/mo/;所以你没有办法使用foaf:interest为音乐应用程序构建配置文件使用数据LOD?我不明白。xmlns:mo=purl.org/ontology/mo/只是RDF文件中的名称空间声明。这与允许处理任意RDF数据的API有什么关系?在您的上下文中,什么是支持?什么不起作用?如何认识到你所说的一切都不起作用?顺便说一句,至少在项目页面上,它已经完全过时了——最后一次有意义的承诺已经6年了。