2016-12-13 2 views
-5

このアルゴリズムを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 
+0

あなたの努力を示してください! –

+0

while(results.hasNext()){ QuerySolution qs = results.next(); System.out.println(qs); //結果を表示 //抽出LDパターンの再帰アルゴリズム\t リスト LD = new ArrayList <>(); int i = 1; int k = 2; //結果セットP1 =結果; // ResultSet = Pi、qs = p //結果セットP = P1; while(i Pi – Fiers

答えて

0

//モデルにファイルを読みます モデルモデル= ModelFactory.createOntologyModel(); InputStream in = FileManager.get()。open( "/ Users/nurulfirdausauses/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(); 
+0

これはあなたの質問に対する答えですか?これはApache Jena APIを介してSPARQLクエリを実行する方法を示しています。 – AKSW

+0

いいえ、私はsparqlクエリから長さ1を抽出します。私はアルゴリズムの実装方法を知らなかった。手伝って頂けますか? AKSW – Fiers

+0

私は分かりません。アルゴリズムは擬似コードであり、基本的にはJavaで実行しています - いくつかのループ+文字列の連結+クエリの実行によるクエリの構築。魔法はありません。 – AKSW

関連する問題