1

select * {?s ?p ?o}我正在使用底层方法将 RDF 数据发布到 Bazegraph,但不幸的是,当我在 Blazegraph UI 上进行查询时,我无法找到任何数据。

发布请求的 curl 命令:

curl -X POST -H 'Content-Type:text/x-nquads' --data-binary '@data-1.nq' 
http://localhost:8080/bigdata/sparql

我在 Java 中发布的代码:

String url = "http://localhost:9999/bigdata/sparql";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();

//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);

con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
con.setRequestProperty("Content-Type","text/x-nquads");

byte[] array = Files.readAllBytes(new File("my.nq").toPath());
System.out.println(array);
con.setRequestProperty("Content-Length", String.valueOf(array.length));

// Send post request
con.setDoOutput(true);

DataOutputStream wr = new DataOutputStream( con.getOutputStream()) ;
    wr.write( array );
    wr.flush();
    wr.close();

int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Response Code : " + responseCode);

BufferedReader in = new BufferedReader(
        new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();

//print result
System.out.println(response.toString());

文件my.nq包含:

@prefix f:    <http://example.org#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
f:john a foaf:Person .
f:bill a foaf:Person .
f:mary a foaf:Person .
f:jane a foaf:Person .
f:john f:age "25"^^xsd:int .
f:bill f:age "30"^^xsd:int .
f:mary f:age "24"^^xsd:int .
f:jane f:age "26"^^xsd:int .
f:john f:loves f:mary .
f:bill f:loves f:jane .
f:john f:hasFriend f:bill.
f:john f:name "John Roy" .
f:bill f:name "Bill Jou" .
f:mary f:name "Mary Lestern" .
f:jane f:name "Jane Caiton" .
f:bill foaf:name "Bill" .
f:john foaf:name "John" .
f:mary foaf:name "Mary" .
f:jane foaf:name "Jane" .
4

0 回答 0