本文整理汇总了Java中org.apache.jena.query.Dataset.begin方法的典型用法代码示例。如果您正苦于以下问题:Java Dataset.begin方法的具体用法?Java Dataset.begin怎么用?Java Dataset.begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.query.Dataset
的用法示例。
在下文中一共展示了Dataset.begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listVocabularies
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public static Set<String> listVocabularies() {
Set<String> tds = new HashSet<>();
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?o a <http://www.w3.org/2002/07/owl#Ontology> } }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
} catch (Exception e) {
throw e;
} finally {
dataset.end();
}
return tds;
}
示例2: get
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(uri.toString(),this);
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
Model result = dataset.getNamedModel(uri.toString());
if (!result.isEmpty()) {
resource.contentType = "text/turtle";
ByteArrayOutputStream out = new ByteArrayOutputStream();
result.write(out, "Turtle");
resource.content = out.toString();
} else {
throw new RESTException();
}
} finally {
dataset.end();
}
return resource;
}
示例3: delete
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public void delete(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.WRITE);
try {
dataset.getDefaultModel().getResource(uri.toString()).removeProperties();
dataset.removeNamedModel(uri.toString());
deleteToAll(uri.getPath());
dataset.commit();
} catch (Exception e) {
// TODO distinguish between client and server errors
throw new RESTException();
} finally {
dataset.end();
}
}
示例4: get
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(uri.toString(),this);
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?str WHERE { <" + uri + "> <" + DC.source + "> ?str }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
if (result.hasNext()) {
resource.contentType = "application/ld+json";
resource.content = result.next().get("str").asLiteral().getLexicalForm();
} else {
throw new RESTException();
}
} finally {
dataset.end();
}
return resource;
}
示例5: delete
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public void delete(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.WRITE);
try {
dataset.getDefaultModel().createResource(uri.toString()).removeProperties();
dataset.removeNamedModel(uri.toString());
deleteToAll(uri.getPath());
dataset.commit();
// Remove from priority queue
ThingDescription td = new ThingDescription(uri.toString());
ThingDirectory.get().tdQueue.remove(td);
ThingDirectory.get().setTimer();
} catch (Exception e) {
// TODO distinguish between client and server errors
throw new RESTException();
} finally {
dataset.end();
}
}
示例6: listThingDescriptions
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public static List<String> listThingDescriptions(String query) {
List<String> tds = new ArrayList<>();
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { " + query + " FILTER NOT EXISTS { ?ontology a <http://www.w3.org/2002/07/owl#Ontology> } } }";
try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
}
catch (Exception e) {
throw e;
}
} finally {
dataset.end();
}
return tds;
}
示例7: getThingDescriptionIdFromUri
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
/**
* Returns the ID of a thing description stored in the database given its URI.
* @param uri URI of the thing description we want to return.
* @return the ID of the thing description.
*/
public static String getThingDescriptionIdFromUri(String uri) {
String query = "?td <http://iot.linkeddata.es/def/wot#baseURI> <" + uri + ">";
String id = "NOT FOUND";
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?g_id WHERE { GRAPH ?g_id { " + query + " }}";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
id = result.next().get("g_id").toString();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dataset.end();
}
return id;
}
示例8: listThingDescriptionsUri
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
/**
* Returns a list of the thing descriptions URIs.
* @return a list of URIs stored in the database.
*/
public static List<String> listThingDescriptionsUri() {
List<String> tds = new ArrayList<>();
String query = "?td <http://iot.linkeddata.es/def/wot#baseURI> ?uri";
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?uri WHERE { GRAPH ?g_id { " + query + " }}";
try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("uri").toString());
}
}
catch (Exception e) {
throw e;
}
} finally {
dataset.end();
}
return tds;
}
示例9: queryData
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public static List<String> queryData(String query){
Dataset db = TDBFactory.createDataset("temp/dataset");
db.begin(ReadWrite.READ);
Model model = db.getDefaultModel();
Query q = QueryFactory.create(query);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
List<String> answer = new ArrayList<String>();
while(results.hasNext()){
QuerySolution t = results.nextSolution();
RDFNode x = t.get("x");
String s = x.toString();
System.out.println(s);
answer.add(s.substring(7));
}
qexec.close();
db.close();
return answer;
}
示例10: listVocabularies
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public static Set<String> listVocabularies() {
Set<String> tds = new HashSet<>();
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?o a <http://www.w3.org/2002/07/owl#Ontology> } }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
} catch (Exception e) {
throw e;
} finally {
dataset.end();
}
return tds;
}
示例11: get
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(uri.toString(),this);
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.READ);
try {
Model result = dataset.getNamedModel(uri.toString());
if (!result.isEmpty()) {
resource.contentType = "text/turtle";
ByteArrayOutputStream out = new ByteArrayOutputStream();
result.write(out, "Turtle");
resource.content = out.toString();
} else {
throw new RESTException();
}
} finally {
dataset.end();
}
return resource;
}
示例12: delete
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public void delete(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.WRITE);
try {
dataset.getDefaultModel().getResource(uri.toString()).removeProperties();
dataset.removeNamedModel(uri.toString());
deleteToAll(uri.getPath());
dataset.commit();
} catch (Exception e) {
// TODO distinguish between client and server errors
throw new RESTException();
} finally {
dataset.end();
}
}
示例13: get
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(uri.toString(),this);
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT ?str WHERE { <" + uri + "> <" + DC.source + "> ?str }";
QueryExecution qexec = QueryExecutionFactory.create(q, dataset);
ResultSet result = qexec.execSelect();
if (result.hasNext()) {
resource.contentType = "application/ld+json";
resource.content = result.next().get("str").asLiteral().getLexicalForm();
} else {
throw new RESTException();
}
} finally {
dataset.end();
}
return resource;
}
示例14: delete
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public void delete(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.WRITE);
try {
dataset.getDefaultModel().createResource(uri.toString()).removeProperties();
dataset.removeNamedModel(uri.toString());
deleteToAll(uri.getPath());
dataset.commit();
// Remove from priority queue
ThingDescription td = new ThingDescription(uri.toString());
Repository.get().tdQueue.remove(td);
Repository.get().setTimer();
} catch (Exception e) {
// TODO distinguish between client and server errors
throw new RESTException();
} finally {
dataset.end();
}
}
示例15: listThingDescriptions
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public static List<String> listThingDescriptions(String query) {
List<String> tds = new ArrayList<>();
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String q = "SELECT DISTINCT ?g WHERE { GRAPH ?g { " + query + " FILTER NOT EXISTS { ?ontology a <http://www.w3.org/2002/07/owl#Ontology> } } }";
try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
tds.add(result.next().get("g").asResource().getURI());
}
}
catch (Exception e) {
throw e;
}
} finally {
dataset.end();
}
return tds;
}