我目前正在构建一个音乐推荐系统。第一步我想使用 FOAF(朋友的朋友)构建个人用户配置文件,但是在使用 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: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();
}
编辑 我修复了错误。在此之前,我在 SPARQL 查询中犯了错误。非常感谢。