【问题标题】:Algorithm Extract Linked Data Patterns算法提取关联数据模式
【发布时间】:2016-12-13 01:55:05
【问题描述】:

如何在java中实现这个算法?

SPARQL query extracts the patterns
with length one and their frequencies from the linked data:
SELECT DISTINCT ?c1 ?p ?c2 (COUNT(*) as ?count)
WHERE { ?x ?p ?y. ?x rdf:type ?c1. ?y rdf:type ?c2. }
GROUP BY ?c1 ?p ?c2

输入:LD(链接的数据存储库),k(模式的最大长度)

输出:一组 LD 模式

1: P1 <- extract patterns of length one from LD
2: P <- P1, i <-1
3: while i < k do
4: for each pattern pi -> Pi do
5: for each ontology class c in pi do
6: P1,c all the patterns in P1 that include c
7: for each pattern p1,c 2 P1,c do
8: pjoin construct a pattern by joining pi and p1,c on node c
9: if pjoin exists in LD then
10: Pi+1 Pi+1 [ pjoin
11: end if
12: end for
13: end for
14: end for
15: P P [ Pi+1, i i + 1
16: end while
return P

【问题讨论】:

  • 展示你的努力!
  • while (results.hasNext()) { QuerySolution qs = results.next(); System.out.println(qs); //显示结果 //提取LD模式的递归算法 List LD = new ArrayList();诠释 i = 1;诠释 k = 2; //ResultSet P1 = 结果; //ResultSet = Pi, qs = p //ResultSet P = P1; while (i Pi

标签: java arrays algorithm sparql recursive-datastructures


【解决方案1】:

//将文件读入模型 模型模型 = ModelFactory.createOntologyModel(); InputStream in = FileManager.get().open("/Users/nurulfirdaus/Documents/University0_0.owl"); model.read(in,null, "RDF/XML");

    //Put the query as string
    String sparqlQuery =
           "PREFIX ub:<http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#>\n" +
           "PREFIX owl:<http://www.w3.org/2002/07/owl#>\n" +
           "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
           "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n" +
           "\n" +     
           "select distinct ?c1 ?p ?c2 (COUNT(*) as ?count) \n"+ //extract length 1
           "where { \n" +
           "?x ?p ?y. \n" + //List all the resources with the property "?p"
           "?x rdf:type ?c1. \n" +
           "?y rdf:type ?c2. \n" +
           "} \n" +
           "group by ?c1 ?p ?c2 ";

   //Execute the query
   Query query = QueryFactory.create(sparqlQuery);
   QueryExecution qe = QueryExecutionFactory.create(query, model);
   ResultSet results = qe.execSelect();

【讨论】:

  • 这是您问题的答案吗?我的意思是这只是展示了如何通过 Apache Jena API 运行 SPARQL 查询。
  • 不,我只是从 sparql 查询中提取长度 1。我不知道如何实现该算法。你能帮助我吗? AKSW
  • 我不明白。您有伪代码中的算法,它基本上是在 Java 中执行的 - 一些循环 + 通过字符串连接构建查询 + 查询执行。没有魔法。
猜你喜欢
  • 1970-01-01
  • 2015-08-16
  • 2014-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-03
  • 1970-01-01
相关资源
最近更新 更多