本文整理汇总了Java中com.hp.hpl.jena.sparql.algebra.Algebra.exec方法的典型用法代码示例。如果您正苦于以下问题:Java Algebra.exec方法的具体用法?Java Algebra.exec怎么用?Java Algebra.exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.sparql.algebra.Algebra
的用法示例。
在下文中一共展示了Algebra.exec方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.hp.hpl.jena.sparql.algebra.Algebra; //导入方法依赖的package包/类
public static void main(String []args)
{
// Parse
//Query query = QueryFactory.read("file:C:\\SVN\\PigSPARQL_main\\queries\\q8.sparql") ;
Query query = QueryFactory.read("file:queries/SP2Bench/q8mod.sparql") ;
//System.out.println(query) ;
// Generate algebra
Op op = Algebra.compile(query) ;
op = Algebra.optimize(op) ;
//System.out.println(op) ;
// Print Algebra Using SSE
//PrintUtils.printOp(query, true);
//System.out.println();
String dftGraphURI = "file:datasets/SP2BEnch/dblp25M.n3" ;
//String dftGraphURI = "file:D:\\ZerProf\\Uni\\Master\\Masterarbeit\\sp2b\\bin\\dblp50K.n3" ;
Dataset dataset = DatasetFactory.create(dftGraphURI);
// Execute it.
QueryIterator qIter = Algebra.exec(op, dataset) ;
// Results
int results = 0;
for ( ; qIter.hasNext() ; )
{
Binding b = qIter.nextBinding() ;
results++;
System.out.println(b) ;
}
qIter.close() ;
System.out.println("# solution mappings: "+results);
}
示例2: execute
import com.hp.hpl.jena.sparql.algebra.Algebra; //导入方法依赖的package包/类
@Override
/*
* (non-Javadoc)
* @see backtype.storm.task.IBolt#execute(backtype.storm.tuple.Tuple)
* We assume that each tuple here is a set of graphs, result of the windowing bolt.
*/
public void execute(Tuple input) {
ArrayList<Graph> graphList = (ArrayList<Graph>) input.getValue(0);
//Graph graph = (Graph) input.getValue(0);
QueryIterator queryIter = null;
for (Graph g : graphList) {
queryIter = Algebra.exec(this.opBGP, g);
while (queryIter.hasNext()) {
Binding binding = queryIter.nextBinding();
Values values = new Values();
for (String str : this.outputFields) {
Var aux = Var.alloc(str);
// Var obsValue = Var.alloc("obsValue");
// Var time = Var.alloc("time");
// Var location = Var.alloc("location");
Node auxNode = binding.get(aux);
// Node obsValueNode = binding.get(obsValue);
// Node timeNode = binding.get(time);
// Node locationNode = binding.get(location);
// System.out.println(obsId + ": " + FmtUtils.stringForNode(obsIdNode) + ", " +
// obsValue + ": " + FmtUtils.stringForNode(obsValueNode) + ", " + time + ": " + FmtUtils.stringForNode(timeNode)
// + ", " + location + ": " + FmtUtils.stringForNode(locationNode));
values.add(FmtUtils.stringForNode(auxNode));
}
collector.emit(values);
// collector.emit(new Values(FmtUtils.stringForNode(obsIdNode), FmtUtils.stringForNode(obsValueNode),
// FmtUtils.stringForNode(timeNode), FmtUtils.stringForNode(locationNode)));
}
}
collector.ack(input);
}
示例3: runLocalOp
import com.hp.hpl.jena.sparql.algebra.Algebra; //导入方法依赖的package包/类
public ResultSetRewindable runLocalOp(Op op) {
long startTime = System.currentTimeMillis();
Query q = OpAsQuery.asQuery(op);
logger.debug("Running query on the local dataset" + ":"
// + "\n\nORIGINAL OP:\n"
// + op.toString()
// + "\n\nOPTIMIZED OP\n"
// + Algebra.optimize(op)
+ "\n\nSPARQL QUERY\n" + q.toString(Syntax.syntaxARQ));
try {
Integer key = op.toString().hashCode();
if (cache.containsKey(key)) {
logger.debug("The query was cached.");
return cache.get(key);
}
ds.begin(ReadWrite.READ);
QueryIterator qIter = Algebra.exec(op, this.ds);
List<String> vars = new LinkedList<String>();
for (Var var : OpAsQuery.asQuery(op).getProjectVars()) {
vars.add(var.getVarName());
}
ResultSetRewindable results = ResultSetFactory
.copyResults(ResultSetFactory.create(qIter, vars));
long endTime = System.currentTimeMillis();
String timeString = new SimpleDateFormat("mm:ss:SSS")
.format(new Date(endTime - startTime));
// cache disabled
// cache.put(op.toString().hashCode(), results);
logger.info("The query returned after " + timeString + " with "
+ results.size() + " results");
return results;
} finally {
ds.end();
}
}
示例4: loadGraphPattern
import com.hp.hpl.jena.sparql.algebra.Algebra; //导入方法依赖的package包/类
public QueryIterator loadGraphPattern(Op op, Model model){
return Algebra.exec(op, model);
}
示例5: exec
import com.hp.hpl.jena.sparql.algebra.Algebra; //导入方法依赖的package包/类
private ResultSetRewindable exec(DatasetGraph ds, Op op) {
QueryIterator qIter = Algebra.exec(op, ds) ;
List<String> vars = Var.varNames(OpVars.visibleVars(op)) ;
ResultSetRewindable rs = ResultSetFactory.makeRewindable(new ResultSetStream(vars, null, qIter)) ;
return rs ;
}