本文整理汇总了Java中org.apache.jena.query.Dataset.addNamedModel方法的典型用法代码示例。如果您正苦于以下问题:Java Dataset.addNamedModel方法的具体用法?Java Dataset.addNamedModel怎么用?Java Dataset.addNamedModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.query.Dataset
的用法示例。
在下文中一共展示了Dataset.addNamedModel方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public Model validate(Model dataModel, Model shapesModel) throws Exception {
Model shaclModel = SHACLSystemModel.getSHACLModel();
MultiUnion unionGraph = new MultiUnion(new Graph[] {
shaclModel.getGraph(),
dataModel.getGraph(),
shapesModel.getGraph()
});
Model all = ModelFactory.createModelForGraph(unionGraph);
// Make sure all sh:Functions are registered
SHACLFunctions.registerFunctions(all);
URI shapesGraphURI = URI.create("urn:x-shacl-shapes-graph:" + UUID.randomUUID().toString());
Dataset dataset = ARQFactory.get().getDataset(dataModel);
dataset.addNamedModel(shapesGraphURI.toString(), all);
Model results = new ModelConstraintValidator().validateModel(dataset, shapesGraphURI, null, true, null, null).getModel();
results.setNsPrefixes(all);
return results;
}
示例2: validate
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
/***************************************************************************
* Public Methods
**************************************************************************/
public Model validate(Model data)
{
// (here, using a temporary URI for the shapes graph)
String uuid = UUID.randomUUID().toString();
URI shapesURI = URI.create("urn:x-shacl-shapes-graph:" + uuid);
Dataset dataset = ARQFactory.get().getDataset(data);
dataset.addNamedModel(shapesURI.toString(), _validationModel);
Model results = null;
long time = System.currentTimeMillis();
try {
results = _validator.validateModel(dataset, shapesURI
, null, false, null);
}
catch (InterruptedException e) {}
long elapsed = System.currentTimeMillis() - time;
System.out.println("Validator executed in " + elapsed + "ms");
results.setNsPrefix(SHACL_PREFIX, SHACL_NS);
return results;
}
示例3: ServiceNodeWriter
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
/**
* ServiceNodeWriter.
*
* @param serviceURI String
* @param servicePredicate String
* @param serviceType String
*/
ServiceNodeWriter(final String serviceURI, final String servicePredicate,
final String serviceType) {
final Model model = ModelFactory.createDefaultModel();
final Resource s = model.createResource(getIdentitySubject());
final Property p = model.createProperty(servicePredicate);
final Resource o = model.createResource(serviceURI);
model.add(s, p, o);
final Dataset dataset = DatasetFactory.create(model);
dataset.addNamedModel("http://iiif.service", model);
this.serviceNode = new ByteArrayOutputStream();
RDFDataMgr.write(this.serviceNode, model, Lang.NTRIPLES);
}
示例4: createExpModelForChallengeTask
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
private Model createExpModelForChallengeTask(Model model, String challengeTaskUri, String systemUri) {
Dataset dataset = DatasetFactory.create();
dataset.addNamedModel("http://temp.org/challenge", model);
String query = SparqlQueries.getCreateExperimentFromTaskQuery(Constants.NEW_EXPERIMENT_URI, challengeTaskUri,
systemUri, "http://temp.org/challenge");
if (query == null) {
LOGGER.error("Couldn't load SPARQL query to create an RDF model for a new experiment. Returning null.");
return null;
}
QueryExecution qe = QueryExecutionFactory.create(query, dataset);
return qe.execConstruct();
}
示例5: validateModel
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
/**
* Validates a given data Model against all shapes from a given shapes Model.
* If the shapesModel does not include the system graph triples then these will be added.
* Entailment regimes are applied prior to validation.
* @param dataModel the data Model
* @param shapesModel the shapes Model
* @param validateShapes true to also validate any shapes in the data Model (false is faster)
* @return an instance of sh:ValidationReport in a results Model
*/
public static Resource validateModel(Model dataModel, Model shapesModel, boolean validateShapes) {
// Ensure that the SHACL, DASH and TOSH graphs are present in the shapes Model
if(!shapesModel.contains(TOSH.hasShape, RDF.type, (RDFNode)null)) { // Heuristic
Model unionModel = SHACLSystemModel.getSHACLModel();
MultiUnion unionGraph = new MultiUnion(new Graph[] {
unionModel.getGraph(),
shapesModel.getGraph()
});
shapesModel = ModelFactory.createModelForGraph(unionGraph);
}
// Make sure all sh:Functions are registered
SHACLFunctions.registerFunctions(shapesModel);
// Create Dataset that contains both the data model and the shapes model
// (here, using a temporary URI for the shapes graph)
URI shapesGraphURI = URI.create("urn:x-shacl-shapes-graph:" + UUID.randomUUID().toString());
Dataset dataset = ARQFactory.get().getDataset(dataModel);
dataset.addNamedModel(shapesGraphURI.toString(), shapesModel);
ShapesGraph shapesGraph = new ShapesGraph(shapesModel);
if(!validateShapes) {
shapesGraph.setShapeFilter(new ExcludeMetaShapesFilter());
}
ValidationEngine engine = ValidationEngineFactory.get().create(dataset, shapesGraphURI, shapesGraph, null);
try {
engine.applyEntailments();
return engine.validateAll();
}
catch(InterruptedException ex) {
return null;
}
}
示例6: post
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public RESTResource post(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
String data = "";
String ontologyUri = null;
try {
data = ThingDescriptionUtils.streamToString(payload);
ontologyUri = new URI(data).toString();
data = null;
} catch (IOException e1) {
e1.printStackTrace();
throw new BadRequestException();
} catch (URISyntaxException e2) {
// do nothing
}
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.WRITE);
try {
String rootId = null;
OntModel ontology = ModelFactory.createOntologyModel();
if (data == null) {
ontology.read(ontologyUri.toString(), "Turtle");
} else {
ontologyUri = "http://example.org/"; // TODO
ontology.read(new ByteArrayInputStream(data.getBytes("UTF-8")), ontologyUri, "Turtle");
}
Model tdb = dataset.getDefaultModel();
ExtendedIterator<Ontology> it = ontology.listOntologies();
if (!it.hasNext()) {
throw new BadRequestException();
}
while (it.hasNext()) {
Ontology o = it.next();
String prefix = ontology.getNsURIPrefix(o.getURI());
// if no prefix found, generates id
String id = (prefix != null && !prefix.isEmpty()) ? prefix : generateID();
URI resourceUri = URI.create(normalize(uri) + "/" + id);
OntModel axioms;
if (isRootOntology(o.getURI(), ontology)) {
rootId = id;
axioms = ontology;
} else {
axioms = ontology.getImportedModel(o.getURI());
}
// TODO Check if the vocab isn't already registered in the dataset
dataset.addNamedModel(resourceUri.toString(), axioms);
Date currentDate = new Date(System.currentTimeMillis());
DateFormat f = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
tdb.getResource(resourceUri.toString()).addProperty(DCTerms.source, ontologyUri);
tdb.getResource(resourceUri.toString()).addProperty(DCTerms.created, f.format(currentDate));
addToAll("/vocab/" + id, new VocabularyHandler(id, instances));
ThingDirectory.LOG.info(String.format("Registered RDFS/OWL vocabulary %s (id: %s)", o.getURI(), id));
}
dataset.commit();
RESTResource resource = new RESTResource("/vocab/" + rootId, new VocabularyHandler(rootId, instances));
return resource;
} catch (Exception e) {
e.printStackTrace();
throw new RESTException();
} finally {
dataset.end();
}
}
示例7: exec
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public QueryIterator exec(Binding binding, PropFuncArg argSubject,
Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
argSubject = Substitute.substitute(argSubject, binding);
argObject = Substitute.substitute(argObject, binding);
if(!argObject.getArg().isVariable()) {
throw new ExprEvalException("Right hand side of tosh:exprEval must be a variable");
}
Node exprNode = argSubject.getArgList().get(0);
Node focusNode = argSubject.getArgList().get(1);
Model model = ModelFactory.createModelForGraph(execCxt.getActiveGraph());
Dataset dataset = ARQFactory.get().getDataset(model);
URI shapesGraphURI = URI.create("urn:x-topbraid:dummyShapesGraph");
dataset.addNamedModel(shapesGraphURI.toString(), model);
ShapesGraph[] shapesGraph = new ShapesGraph[1];
NodeExpression n = NodeExpressionFactory.get().create(model.asRDFNode(exprNode));
List<RDFNode> results = n.eval(model.asRDFNode(focusNode), new NodeExpressionContext() {
@Override
public URI getShapesGraphURI() {
return shapesGraphURI;
}
@Override
public ShapesGraph getShapesGraph() {
if(shapesGraph[0] == null) {
shapesGraph[0] = new ShapesGraph(model);
}
return shapesGraph[0];
}
@Override
public Dataset getDataset() {
return dataset;
}
});
List<Node> nodes = new LinkedList<>();
for(RDFNode rdfNode : results) {
nodes.add(rdfNode.asNode());
}
return new QueryIterExtendByVar(binding, (Var) argObject.getArg(), nodes.iterator(), execCxt);
}
示例8: withShapesGraph
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public static URI withShapesGraph(Dataset dataset) {
URI shapesGraphURI = URI.create(URN_X_SHACL + UUID.randomUUID());
Model shapesModel = createShapesModel(dataset);
dataset.addNamedModel(shapesGraphURI.toString(), shapesModel);
return shapesGraphURI;
}
示例9: run
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
private void run() {
// Make some triples
dsg.clear();
Dataset dataset = dsg.toDataset();
String modelName = "http://example.org/graphs/charles";
String turtle = "@prefix foaf: <http://xmlns.com/foaf/0.1/> ."
+ "@prefix : <http://example.org/> ."
+":charles a foaf:Person ; "
+ " foaf:name \"Charles\" ;"
+ " foaf:knows :jim ."
+ ":jim a foaf:Person ;"
+ " foaf:name \"Jim\" ;"
+ " foaf:knows :charles .";
System.out.println("Make a model and load the turtle into it (client-side)");
Model model = ModelFactory.createDefaultModel();
RDFDataMgr.read(model, new StringReader(turtle), "", Lang.TURTLE);
System.out.println("Store the model in MarkLogic.");
dataset.addNamedModel(modelName, model);
System.out.println("Make a triple by hand.");
Model moreTriples = ModelFactory.createDefaultModel();
Statement statement = ResourceFactory.createStatement(
ResourceFactory.createResource("http://example.org/charles"),
ResourceFactory.createProperty("http://example.org/hasDog"),
ResourceFactory.createResource("http://example.org/vashko")
);
moreTriples.add( statement );
System.out.println("Combine models and save");
model.add(moreTriples);
dataset.addNamedModel(modelName, model);
System.out.println("Get it back into a new model (union of two original ones)");
Model retrievedModel = dataset.getNamedModel(modelName);
System.out.println("Remove model from MarkLogic");
dataset.removeNamedModel(modelName);
}
示例10: annotationDatasetFor
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public Dataset annotationDatasetFor(Child<?> workflowBean) {
Dataset dataset = DatasetFactory.createMem();
for (Annotation ann : scufl2Tools.annotationsFor(workflowBean)) {
WorkflowBundle bundle = ann.getParent();
URI annUri = uritools.uriForBean(ann);
String bodyUri = bundle.getGlobalBaseURI().resolve(ann.getBody())
.toASCIIString();
if (ann.getBody().isAbsolute()) {
logger.info("Skipping absolute annotation body URI: "
+ ann.getBody());
// TODO: Optional loading of external annotation bodies
continue;
}
String path = ann.getBody().getPath();
ResourceEntry resourceEntry = bundle.getResources()
.getResourceEntry(path);
if (resourceEntry == null) {
logger.warning("Can't find annotation body: " + path);
continue;
}
String contentType = resourceEntry.getMediaType();
Lang lang = RDFLanguages.contentTypeToLang(contentType);
if (lang == null) {
lang = RDFLanguages.filenameToLang(path);
}
if (lang == null) {
logger.warning("Can't find media type of annotation body: "
+ ann.getBody());
continue;
}
Model model = ModelFactory.createDefaultModel();
try (InputStream inStream = bundle.getResources()
.getResourceAsInputStream(path)) {
RDFDataMgr.read(model, inStream, bodyUri, lang);
} catch (IOException e) {
logger.warning("Can't read annotation body: " + path);
continue;
}
dataset.addNamedModel(annUri.toString(), model);
}
return dataset;
}
示例11: add
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
public void add(Model model, String name, Location location) {
Dataset dataset = TDBFactory.createDataset(location);
dataset.addNamedModel(name, model);
}
示例12: post
import org.apache.jena.query.Dataset; //导入方法依赖的package包/类
@Override
public RESTResource post(URI uri, Map<String, String> parameters, InputStream payload) throws RESTException {
String data = "";
String ontologyUri = null;
try {
data = ThingDescriptionUtils.streamToString(payload);
ontologyUri = new URI(data).toString();
data = null;
} catch (IOException e1) {
e1.printStackTrace();
throw new BadRequestException();
} catch (URISyntaxException e2) {
// do nothing
}
Dataset dataset = Repository.get().dataset;
dataset.begin(ReadWrite.WRITE);
try {
String rootId = null;
OntModel ontology = ModelFactory.createOntologyModel();
if (data == null) {
ontology.read(ontologyUri.toString(), "Turtle");
} else {
ontologyUri = "http://example.org/"; // TODO
ontology.read(new ByteArrayInputStream(data.getBytes("UTF-8")), ontologyUri, "Turtle");
}
Model tdb = dataset.getDefaultModel();
ExtendedIterator<Ontology> it = ontology.listOntologies();
if (!it.hasNext()) {
throw new BadRequestException();
}
while (it.hasNext()) {
Ontology o = it.next();
String prefix = ontology.getNsURIPrefix(o.getURI());
// if no prefix found, generates id
String id = (prefix != null && !prefix.isEmpty()) ? prefix : generateID();
URI resourceUri = URI.create(normalize(uri) + "/" + id);
OntModel axioms;
if (isRootOntology(o.getURI(), ontology)) {
rootId = id;
axioms = ontology;
} else {
axioms = ontology.getImportedModel(o.getURI());
}
// TODO Check if the vocab isn't already registered in the dataset
dataset.addNamedModel(resourceUri.toString(), axioms);
Date currentDate = new Date(System.currentTimeMillis());
DateFormat f = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
tdb.getResource(resourceUri.toString()).addProperty(DCTerms.source, ontologyUri);
tdb.getResource(resourceUri.toString()).addProperty(DCTerms.created, f.format(currentDate));
addToAll("/vocab/" + id, new VocabularyHandler(id, instances));
Repository.LOG.info(String.format("Registered RDFS/OWL vocabulary %s (id: %s)", o.getURI(), id));
}
dataset.commit();
RESTResource resource = new RESTResource("/vocab/" + rootId, new VocabularyHandler(rootId, instances));
return resource;
} catch (Exception e) {
e.printStackTrace();
throw new RESTException();
} finally {
dataset.end();
}
}