本文整理汇总了Java中com.hp.hpl.jena.sparql.core.DatasetGraph类的典型用法代码示例。如果您正苦于以下问题:Java DatasetGraph类的具体用法?Java DatasetGraph怎么用?Java DatasetGraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatasetGraph类属于com.hp.hpl.jena.sparql.core包,在下文中一共展示了DatasetGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
/**
* Method to save the nanopub.
* @param f Receives the file.
* @throws Exception It can throw an exception.
*/
public void save(String f) throws Exception {
this.quads = this.getAllQuads();
if (quads == null) {
throw new Exception(
"Quad list is null. Do you call createNanoPub() first?");
}
if (quads.size() == 0) {
throw new Exception("Quad list is empty.");
}
Dataset ds = TDBFactory.createDataset();
DatasetGraph dsg = ds.asDatasetGraph();
for (int i = 0; i < quads.size(); i++) {
dsg.add(quads.get(i));
}
RDFDataMgr.write(new FileOutputStream(new File(f)), dsg,
RDFFormat.NQUADS);
}
示例2: testOp
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
private void testOp(String opString, String datafile) {
Op op = SSE.parseOp(opString) ;
DatasetGraph dsMem = RDFDataMgr.loadDatasetGraph(DIR+"/"+datafile) ;
ResultSetRewindable rsMem = exec(dsMem, op) ;
DatasetGraph dsg = create(datafile).asDatasetGraph() ;
ResultSetRewindable rsQu = exec(dsg, op) ;
boolean b = ResultSetCompare.equalsByTerm(rsMem, rsQu) ;
if ( ! b ) {
PrintStream out = System.out ;
out.println("---- Different (Memory, Quack)") ;
rsMem.reset();
ResultSetFormatter.out(out, rsMem) ;
rsQu.reset();
ResultSetFormatter.out(out, rsQu) ;
out.println("----") ;
fail("Results not equal (Memory, Quack)") ;
}
}
示例3: addToDatasetAndPersist
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
public static void addToDatasetAndPersist(Statement statement,
DatasetGraph datasetGraph,
PersistAndNotifyProvider persistAndNotifyProvider)
{
datasetGraph.getDefaultGraph().add(new Triple(
NodeFactory.createURI(statement.getSubject().toString()),
NodeFactory.createURI(statement.getPredicate().toString()),
NodeFactory.createURI(statement.getObject().toString())));
persistAndNotifyProvider.persistAndNotify(
Helper.createChangeSetModel(statement.getSubject().stringValue(),
statement.getPredicate().stringValue(),
statement.getObject(),
ChangeTripleService.CHANGETYPE_ADD),
true);
}
示例4: matchSingleTmx
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
static public String matchSingleTmx(Node tmx, DatasetGraph g, Model m){
String sq="";
if (g.contains(null, tmx, typeNode, instantNode)) { // One Instant
sq += "?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasTime> ?t . ?t a <http://www.w3.org/TR/owl-time#Instant> . ";
for (Iterator<Quad> iter = g.find(null, tmx, specificTimeNode, null); iter.hasNext(); ) {
Quad q = iter.next();
sq += "?t <http://www.w3.org/TR/owl-time#inDateTime> <" + q.asTriple().getObject() + "> . ";
}
} else { // One Interval
String intervalQuery = "SELECT ?begin ?end WHERE { <" + tmx + "> <http://www.w3.org/TR/owl-time#hasBeginning> ?begin ; <http://www.w3.org/TR/owl-time#hasEnd> ?end . }";
Query inQuery = QueryFactory.create(intervalQuery);
// Create a single execution of this query, apply to a model
// which is wrapped up as a Dataset
QueryExecution inQexec = QueryExecutionFactory.create(inQuery, m);
try {
// Assumption: it’s a SELECT query.
ResultSet inrs = inQexec.execSelect();
// The order of results is undefined.
for (; inrs.hasNext(); ) {
QuerySolution evrb = inrs.nextSolution();
// Get title - variable names do not include the ’?’
String begin = evrb.get("begin").toString();
String end = evrb.get("end").toString();
String unionQuery = "{ ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasTime> ?t . ?t a <http://www.w3.org/TR/owl-time#Interval> . ?t <http://www.w3.org/TR/owl-time#hasBeginning> <" + begin + "> ; <http://www.w3.org/TR/owl-time#hasEnd> <" + end + "> . } ";
unionQuery += "UNION ";
unionQuery += "{ ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasEarliestBeginTimeStamp> ?t1 . ?t1 a <http://www.w3.org/TR/owl-time#Instant> . ?t1 <http://www.w3.org/TR/owl-time#inDateTime> <" + begin + "> . ?ev <http://semanticweb.cs.vu.nl/2009/11/sem/hasEarliestEndTimeStamp> ?t2 . ?t2 a <http://www.w3.org/TR/owl-time#Instant> . ?t2 <http://www.w3.org/TR/owl-time#inDateTime> <" + end + "> . } ";
sq += unionQuery;
}
} finally {
inQexec.close();
}
}
return sq;
}
示例5: inferIdentityRelations
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
private static void inferIdentityRelations(String sparqlQuery, boolean matchILI, boolean matchLemma, boolean matchMultiple, int iliSize, Node eventId, DatasetGraph g) {
if (matchILI || matchLemma) {
sparqlQuery += "GROUP BY ?ev";
}
HttpAuthenticator authenticator = new SimpleAuthenticator(user, pass.toCharArray());
QueryExecution x = QueryExecutionFactory.sparqlService(serviceEndpoint, sparqlQuery, authenticator);
ResultSet resultset = x.execSelect();
int threshold;
while (resultset.hasNext()) {
QuerySolution solution = resultset.nextSolution();
if (matchILI || matchLemma) {
if (matchILI)
threshold = conceptMatchThreshold;
else
threshold=phraseMatchThreshold;
if (matchMultiple) {
//System.out.println(solution);
if (checkIliLemmaThreshold(iliSize, solution.get("conceptcount").asLiteral().getInt(), solution.get("myconceptcount").asLiteral().getInt(), threshold)) {
insertIdentity(g, eventId, solution.get("ev").asNode());
}
} else {
if (checkIliLemmaThreshold(1, solution.get("conceptcount").asLiteral().getInt(), 1, threshold)) {
insertIdentity(g, eventId, solution.get("ev").asNode());
}
}
} else {
insertIdentity(g, eventId, solution.get("ev").asNode());
}
}
}
示例6: evalDS
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
static Table evalDS(OpDatasetNames opDSN, Evaluator evaluator)
{
Node graphNode = opDSN.getGraphNode() ;
if ( graphNode.isURI() )
{
if ( evaluator.getExecContext().getDataset().containsGraph(graphNode) )
{ return new TableUnit() ; }
else
// WRONG
{ return new TableEmpty() ; }
}
if ( ! Var.isVar(graphNode) )
throw new ARQInternalErrorException("OpDatasetNames: Not a URI or variable: "+graphNode) ;
DatasetGraph dsg = evaluator.getExecContext().getDataset() ;
Iterator<Node> iter = dsg.listGraphNodes() ;
List<Binding> list = new ArrayList<Binding>((int)dsg.size()) ;
for ( ; iter.hasNext(); )
{
Node gn = iter.next();
Binding b = BindingFactory.binding(Var.alloc(graphNode), gn) ;
list.add(b) ;
}
QueryIterator qIter = new QueryIterPlainWrapper(list.iterator(), evaluator.getExecContext()) ;
return TableFactory.create(qIter) ;
}
示例7: load
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
@Override
public void load(
final SolrQueryRequest request,
final SolrQueryResponse response,
final ContentStream stream,
final UpdateRequestProcessor processor) throws Exception {
final PipedRDFIterator<Quad> iterator = new PipedRDFIterator<Quad>();
final StreamRDF inputStream = new PipedQuadsStream(iterator);
executor.submit(new Runnable() {
@Override
public void run() {
try {
RDFDataMgr.parse(
inputStream,
stream.getStream(),
RDFLanguages.contentTypeToLang(stream.getContentType()));
} catch (final IOException exception) {
throw new SolrException(ErrorCode.SERVER_ERROR, exception);
}
}
});
final DatasetGraph dataset = new LocalDatasetGraph(request, response);
while (iterator.hasNext()) {
dataset.add(iterator.next());
}
}
示例8: execute
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
/**
* Executes a given {@link UpdateRequest} against the given {@link DatasetGraph}.
*
* @param updateRequest the update request.
* @param datasetGraph the dataset graph.
* @param graphUris the target graphs (optional).
*/
void execute(final UsingList list, final String updateRequests, final DatasetGraph datasetGraph) {
try {
UpdateAction.parseExecute(
list,
datasetGraph,
new ByteArrayInputStream(updateRequests.getBytes("UTF-8")));
} catch (final Exception exception) {
final String message = MessageFactory.createMessage(
MessageCatalog._00099_INVALID_UPDATE_QUERY,
updateRequests);
LOGGER.error(message, exception);
throw new SolrException(ErrorCode.BAD_REQUEST, message);
}
}
示例9: BDBGraphPatternRouter
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
/**
*The constructor
*@param context
*@param op
*@param ds
*/
public BDBGraphPatternRouter(ExecContext context, Op op, DatasetGraph ds) {
super(context, op);
//this.op=op;
//ModelFactory.createModelForGraph(ds.getDefaultGraph()).write(System.out);
init(ds);
}
示例10: execute
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
static void execute(DatasetGraph dsg, Op op, Context context) {
/*
Algebra.exec(op, dsg)
==>
QueryEngineFactory f = QueryEngineRegistry.findFactory(op, ds, null) ;
Plan plan = f.create(op, ds, BindingRoot.create(), null) ;
return plan.iterator() ;
*/
context = Context.setupContext(context, dsg) ;
OpExecutorFactory factory = QC.getFactory(context) ;
if ( factory == null )
factory = OpExecutor.stdFactory ;
ExecutionContext execCxt = new ExecutionContext(context, dsg.getDefaultGraph(), dsg, factory) ;
QueryIterator qIterRoot = OpExecutor.createRootQueryIterator(execCxt) ;
QueryIterator qIterPlan = QC.execute(op, qIterRoot, execCxt) ;
Plan plan = new PlanOp(op, null, qIterPlan) ;
runPlan(plan) ;
/*
Query query = null ;
Dataset dataset = null ;
QueryEngineFactory qefactory = null ;
@SuppressWarnings("resource")
QueryExecutionBase queryExecutionBase = new QueryExecutionBase(query, dataset, context, qefactory) ;
*/
}
示例11: OpExecutorBlockFilter
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
public OpExecutorBlockFilter(ExecutionContext execCxt) {
super(execCxt) ;
DatasetGraph dsg = execCxt.getDataset() ;
Graph graph = execCxt.getActiveGraph() ;
isForThisExecutor = isForThisExecutor(dsg, graph, execCxt) ;
if ( isForThisExecutor ) {
dataset = initExecutor(dsg, graph, execCxt) ;
} else
dataset = null ;
}
示例12: create
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
@Override
public Plan create(Query query, DatasetGraph dataset, Binding input, Context context)
{
QueryEngineMain engine = new QueryEngineMain2(query, dataset, input, context) ;
QC.setFactory(context, OpExecutorRowsMain.factoryRowsMain) ;
return engine.getPlan() ;
}
示例13: create
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
@Override
public Plan create(Query query, DatasetGraph dataset, Binding input, Context context)
{
// This is the usual route.
DatasetGraphTDB dsgtdb = dsgToQuery(dataset) ;
setup(dsgtdb, context) ;
QueryEngineQuackTDB engine = new QueryEngineQuackTDB(query, dsgtdb, input, context) ;
return engine.getPlan() ;
}
示例14: dsgToQuery
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
protected DatasetGraphTDB dsgToQuery(DatasetGraph dataset)
{
if (dataset instanceof DatasetGraphTDB) return (DatasetGraphTDB)dataset ;
if (dataset instanceof DatasetGraphTransaction)
return ((DatasetGraphTransaction)dataset).getDatasetGraphToQuery() ;
throw new TDBException("Internal inconsistency: trying to execute query on unrecognized kind of DatasetGraph: "+Lib.className(dataset)) ;
}
示例15: createDatasetGraph
import com.hp.hpl.jena.sparql.core.DatasetGraph; //导入依赖的package包/类
public static DatasetGraph createDatasetGraph(Location location, OpExecutorFactory executorFactory) {
LogCtl.setError(FileRef.class) ;
StoreParams sParams = StoreParams.builder()
// Test to see if POS exists but PSO does not.
.tripleIndexes(new String[] { primaryIndexTriples, "POS", "PSO", "OSP" })
//{ primaryIndexQuads, "GPOS", "GOSP", "POSG", "OSPG", "SPOG"} ;
.quadIndexes(new String[] { primaryIndexQuads, "GPOS", "GPSO", "GOSP",
"POSG", "PSOG", "OSPG", "SPOG"})
.build() ;
DatasetGraphTDB dsg = DatasetBuilderStd.stdBuilder().build(location, sParams) ;
QC.setFactory(dsg.getContext(), executorFactory) ;
return dsg ;
}