AGSparqlRDFLiterals.java
package com.franz.ag.examples;
import com.franz.ag.*;
import org.openrdf.model.URI;
public class AGSparqlRDFLiterals {
@param
@throws
public static void main(String[] args) throws AllegroGraphException {
AllegroGraphConnection ags = new AllegroGraphConnection();
try {
ags.enable();
} catch (Exception e) {
throw new AllegroGraphException("Server connection problem", e);
}
AllegroGraph ts = ags.renew("sparql", AGPaths.TRIPLE_STORES);
ts.registerNamespace("dt", "http://example.org/datatype#");
ts.registerNamespace("ns", "http://example.org/ns#");
ts.registerNamespace("xsd", "http://www.w3.org/2001/XMLSchema#");
ts.addStatement("!ns:a","!ns:p", "!\"42\"^^xsd:integer");
URI u = (URI)ts.addPart("!xsd:integer");
AGUtils.showURI(u);
ts.addStatement("!ns:b","!ns:p",ts.createLiteral("42", u));
ts.addStatement("!ns:c","!ns:p",ts.createLiteral("42", ts.createURI("http://www.w3.org/2001/XMLSchema#integer")));
ts.addStatement("!ns:d","!ns:p",ts.createLiteral("42", ts.createURI("http://www.w3.org/2001/XMLSchema#int")));
ts.addStatement("!ns:x","!ns:p",ts.createLiteral("cat", "en"));
URI v = (URI)ts.addPart("!dt:specialDatatype");
AGUtils.showURI(v);
ts.addStatement("!ns:z","!ns:p",ts.createLiteral("abc",v));
ts.addStatement("!ns:z2","!ns:p", "!\"abc\"^^dt:specialDatatype");
String query =
"SELECT ?v WHERE { ?v ?p \"cat\" }";
AGUtils.doSparqlSelect(ts, query);
query =
"SELECT ?v WHERE { ?v ?p \"cat\"@en }";
AGUtils.doSparqlSelect(ts, query);
query =
"SELECT ?v WHERE { ?v ?p 'cat'@en }";
AGUtils.doSparqlSelect(ts, query);
query =
"SELECT ?v WHERE { ?v ?p 42 }";
AGUtils.doSparqlSelect(ts, query);
query =
"SELECT ?v WHERE { ?v ?p 'abc'^^<http://example.org/datatype#specialDatatype> }";
AGUtils.doSparqlSelect(ts, query);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next