2016-10-17 2 views
0

RDF/OWL 파일을 Sparql 끝점 (Fuseki에서 제공)에 업로드하려고했습니다. 지금은 하나의 파일을 업로드 할 수 있지만 작업을 반복하려고하면 새 데이터 세트가 이전 파일을 덮어 씁니다. 데이터 세트의 데이터 내용을 방금 업로드 한 rdf 파일의 새로운 내용과 "병합"하는 방법을 찾고 있습니다. 누구든지 나를 도울 수 있습니까? 감사. 엔드 포인트를 조회/업로드하는 코드 (내가 저자 아니에요)Jena Fuseki API 기존 데이터 세트에 새 데이터 추가 [Java]

// Written in 2015 by Thilo Planz 
// To the extent possible under law, I have dedicated all copyright and related and neighboring rights 
// to this software to the public domain worldwide. This software is distributed without any warranty. 
// http://creativecommons.org/publicdomain/zero/1.0/ 

import java.io.File; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.ByteArrayOutputStream; 

import org.apache.jena.query.DatasetAccessor; 
import org.apache.jena.query.DatasetAccessorFactory; 
import org.apache.jena.query.QueryExecution; 
import org.apache.jena.query.QueryExecutionFactory; 
import org.apache.jena.query.QuerySolution; 
import org.apache.jena.query.ResultSet; 
import org.apache.jena.query.ResultSetFormatter; 
import org.apache.jena.rdf.model.Model; 
import org.apache.jena.rdf.model.ModelFactory; 
import org.apache.jena.rdf.model.RDFNode; 


class FusekiExample { 

    public static void uploadRDF(File rdf, String serviceURI) 
      throws IOException { 

     // parse the file 
     Model m = ModelFactory.createDefaultModel(); 
     try (FileInputStream in = new FileInputStream(rdf)) { 
      m.read(in, null, "RDF/XML"); 
     } 

     // upload the resulting model 
     DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceURI); 
     accessor.putModel(m); 

    } 

    public static void execSelectAndPrint(String serviceURI, String query) { 
     QueryExecution q = QueryExecutionFactory.sparqlService(serviceURI, 
       query); 
     ResultSet results = q.execSelect(); 

     // write to a ByteArrayOutputStream 
     ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 
     //convert to JSON format 
     ResultSetFormatter.outputAsJSON(outputStream, results); 
     //turn json to string 
     String json = new String(outputStream.toByteArray()); 
     //print json string 
     System.out.println(json); 

    } 

    public static void execSelectAndProcess(String serviceURI, String query) { 
     QueryExecution q = QueryExecutionFactory.sparqlService(serviceURI, 
       query); 
     ResultSet results = q.execSelect(); 

     while (results.hasNext()) { 
      QuerySolution soln = results.nextSolution(); 
      // assumes that you have an "?x" in your query 
      RDFNode x = soln.get("x"); 
      System.out.println(x); 
     } 
    } 

    public static void main(String argv[]) throws IOException { 
     // uploadRDF(new File("test.rdf"),); 

     uploadRDF(new File("test.rdf"), "http://localhost:3030/MyEndpoint/data"); 


    } 
} 

답변

3

사용 accessor.add(m) 대신 putModel(m)에 따라

. the Javadoc에서 볼 수 있듯이 은 기존 데이터 인을 대체합니다.

관련 문제