本文整理汇总了Java中org.apache.jena.sparql.core.BasicPattern类的典型用法代码示例。如果您正苦于以下问题:Java BasicPattern类的具体用法?Java BasicPattern怎么用?Java BasicPattern使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BasicPattern类属于org.apache.jena.sparql.core包,在下文中一共展示了BasicPattern类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: visit
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
@Override
public void visit(ElementTriplesBlock el) {
final BasicPattern bgp = el.getPattern();
final ElementTriplesBlock nzed = new ElementTriplesBlock();
final NodeExprNormalizer nenzer = new NodeExprNormalizer();
bgp.forEach((t) -> {
t.getSubject().visitWith(nenzer);
Node s = nenzer.getResult();
t.getPredicate().visitWith(nenzer);
Node p = nenzer.getResult();
t.getObject().visitWith(nenzer);
Node o = nenzer.getResult();
nzed.addTriple(new Triple(s, p, o));
});
endVisit(nzed, nenzer);
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:17,代码来源:ElementNormalizer.java
示例2: setWidths
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
private void setWidths(BasicPattern triples) {
subjectWidth = -1;
predicateWidth = -1;
for (Triple t : triples) {
String s = slotToString(t.getSubject());
if (s.length() > subjectWidth) {
subjectWidth = s.length();
}
String p = slotToString(t.getPredicate());
if (p.length() > predicateWidth) {
predicateWidth = p.length();
}
}
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:17,代码来源:SPARQLGenerateFormatterElement.java
示例3: reorder
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
private static BasicPattern reorder(BasicPattern pattern, QueryIterPeek peek, ReorderTransformation transform)
{
if ( transform != null )
{
// This works by getting one result from the peek iterator,
// and creating the more gounded BGP. The tranform is used to
// determine the best order and the transformation is returned. This
// transform is applied to the unsubstituted pattern (which will be
// substituted as part of evaluation.
if ( ! peek.hasNext() )
throw new ARQInternalErrorException("Peek iterator is already empty") ;
BasicPattern pattern2 = Substitute.substitute(pattern, peek.peek() ) ;
// Calculate the reordering based on the substituted pattern.
ReorderProc proc = transform.reorderIndexes(pattern2) ;
// Then reorder original patten
pattern = proc.reorder(pattern) ;
}
return pattern ;
}
开发者ID:LinkedDataFragments,项目名称:Client.Java,代码行数:22,代码来源:OpExecutorLDF.java
示例4: execute
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
@Override
public QueryIterator execute(BasicPattern pattern,
QueryIterator input,
ExecutionContext execCxt)
{
// Just want to pick out some BGPs (e.g. on a particualr graph)
// Test :: execCxt.getActiveGraph()
if ( ! ( execCxt.getActiveGraph() instanceof GraphBase ) )
// Example: pass on up to the original StageGenerator if
// not based on GraphBase (which most Graph implementations are).
return other.execute(pattern, input, execCxt) ;
System.err.println("MyStageGenerator.compile:: triple patterns = "+pattern.size()) ;
// Stream the triple matches together, one triple matcher at a time.
QueryIterator qIter = input ;
for (Triple triple : pattern.getList())
qIter = new QueryIterTriplePattern(qIter, triple, execCxt) ;
return qIter ;
}
开发者ID:xcurator,项目名称:xcurator,代码行数:21,代码来源:StageGeneratorAlt.java
示例5: formatPattern
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
public static void formatPattern(IndentedWriter out, BasicPattern pattern, SerializationContext sCxt) {
boolean first = true;
for (Triple triple : pattern) {
if (!first) {
out.print("\n");
}
printTriple(out, triple, sCxt);
out.print(" .");
first = false;
}
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:12,代码来源:SPARQLGenerateFmtUtils.java
示例6: format
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
@Override
public void format(Template template) {
out.print("{");
out.incIndent(INDENT);
out.pad();
List<Quad> quads = template.getQuads();
for (Quad quad : quads) {
BasicPattern bgp = new BasicPattern();
bgp.add(quad.asTriple());
out.newline();
if (!Quad.defaultGraphNodeGenerated.equals(quad.getGraph())) {
out.print("GRAPH");
out.print(" ");
out.print(slotToString(quad.getGraph()));
out.print(" ");
out.newline();
out.incIndent(INDENT);
out.pad();
out.print("{");
out.incIndent(INDENT);
out.pad();
}
formatTriples(bgp);
if (!Quad.defaultGraphNodeGenerated.equals(quad.getGraph())) {
out.decIndent(INDENT);
out.print("}");
out.decIndent(INDENT);
}
}
out.newline();
out.decIndent(INDENT);
out.print("}");
out.newline();
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:40,代码来源:SPARQLGenerateFormatterTemplate.java
示例7: MarkLogicQueryEngine
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
/**
* Constructor.
* @param query A Jena Query. This engine does not use all parts of the Query hierarchy.
* @param datasetGraph The MarkLogic instance viewed through Jena. Must be a MarkLogicDatasetGraph.
* @param initial Bindings for the query.
* @param context
*/
private MarkLogicQueryEngine(Query query, DatasetGraph datasetGraph,
Binding initial, Context context) {
super(query, datasetGraph, initial, context);
bgp = new BasicPattern();
bgp.add(new Triple(
Var.alloc("s"),
Var.alloc("p"),
Var.alloc("o")));
template = new Template(bgp);
this.markLogicDatasetGraph = (MarkLogicDatasetGraph) datasetGraph;
this.initial = initial;
}
开发者ID:marklogic,项目名称:marklogic-jena,代码行数:20,代码来源:MarkLogicQueryEngine.java
示例8: eval1
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
/** One round of rule evaluation */
private static void eval1(Graph source, StreamTriple out, Rule rule) {
BasicPattern pattern = BasicPattern.wrap(rule.getBody()) ;
ExecutionContext execContext = new ExecutionContext(ARQ.getContext(), source, null, null) ;
// Create a chain of triple iterators.
QueryIterator iter = match(source, pattern) ;
iter.forEachRemaining(b->{
Triple t = Substitute.substitute(rule.getHead(), b) ;
if ( t.isConcrete() && ! source.contains(t) )
out.triple(t);
}) ;
}
开发者ID:afs,项目名称:jena-inf-engine,代码行数:13,代码来源:Forwards.java
示例9: match
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
/** Evaluate a BGP : encapsulate for a better/different version */
private static QueryIterator match(Graph source, BasicPattern pattern) {
ExecutionContext execContext = new ExecutionContext(ARQ.getContext(), source, null, null) ;
// Create a chain of triple iterators.
QueryIterator chain = QueryIterSingleton.create(BindingFactory.root(), execContext) ;
for (Triple triple : pattern)
chain = new QueryIterTriplePattern(chain, triple, execContext) ;
return chain ;
}
开发者ID:afs,项目名称:jena-inf-engine,代码行数:10,代码来源:Forwards.java
示例10: ElementGenerateTriplesBlock
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
public ElementGenerateTriplesBlock() {
pattern = new BasicPattern();
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:4,代码来源:ElementGenerateTriplesBlock.java
示例11: getPattern
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
public BasicPattern getPattern() {
return pattern;
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:4,代码来源:ElementGenerateTriplesBlock.java
示例12: visit
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
@Override
public void visit(ElementPathBlock el) {
// Write path block - don't put in a final trailing "."
if (el.isEmpty()) {
out.println("# Empty BGP");
return;
}
// Split into BGP-path-BGP-...
// where the BGPs may be empty.
PathBlock pBlk = el.getPattern();
BasicPattern bgp = new BasicPattern();
boolean first = true; // Has anything been output?
for (TriplePath tp : pBlk) {
if (tp.isTriple()) {
bgp.add(tp.asTriple());
continue;
}
if (!bgp.isEmpty()) {
if (!first) {
out.println(" .");
}
flush(bgp);
first = false;
}
if (!first) {
out.println(" .");
}
// Path
printSubject(tp.getSubject());
out.print(" ");
SPARQLGeneratePathWriter.write(out, tp.getPath(), context);
out.print(" ");
printObject(tp.getObject());
first = false;
}
// Flush any stored triple patterns.
if (!bgp.isEmpty()) {
if (!first) {
out.println(" .");
}
flush(bgp);
first = false;
}
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:47,代码来源:SPARQLGenerateFormatterElement.java
示例13: flush
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
private void flush(BasicPattern bgp) {
formatTriples(bgp);
bgp.getList().clear();
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:5,代码来源:SPARQLGenerateFormatterElement.java
示例14: formatTriples
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
@Override
protected void formatTriples(BasicPattern triples) {
if (!PRETTY_PRINT) {
super.formatTriples(triples);
return;
}
// TODO RDF Collections - spot the parsers pattern
if (triples.isEmpty()) {
return;
}
setWidths(triples);
if (subjectWidth > TRIPLES_SUBJECT_COLUMN) {
subjectWidth = TRIPLES_SUBJECT_COLUMN;
}
if (predicateWidth > TRIPLES_PROPERTY_COLUMN) {
predicateWidth = TRIPLES_PROPERTY_COLUMN;
}
// Loops:
List<Triple> subjAcc = new ArrayList<>(); // Accumulate all triples
// with the same subject.
Node subj = null; // Subject being accumulated
boolean first = true; // Print newlines between blocks.
int indent = -1;
for (Triple t : triples) {
if (subj != null && t.getSubject().equals(subj)) {
subjAcc.add(t);
continue;
}
if (subj != null) {
if (!first) {
out.println(" .");
}
formatSameSubject(subj, subjAcc);
first = false;
// At end of line of a block of triples with same subject.
// Drop through and start new block of same subject triples.
}
// New subject
subj = t.getSubject();
subjAcc.clear();
subjAcc.add(t);
}
// Flush accumulator
if (subj != null && subjAcc.size() != 0) {
if (!first) {
out.println(" .");
}
first = false;
formatSameSubject(subj, subjAcc);
}
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:60,代码来源:SPARQLGenerateFormatterElement.java
示例15: formatTriples
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
protected void formatTriples(BasicPattern pattern) {
SPARQLGenerateFmtUtils.formatPattern(out, pattern, context);
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:4,代码来源:SPARQLGenerateFormatterBase.java
示例16: execute
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
@Override
public QueryIterator execute(BasicPattern pattern, QueryIterator input,
ExecutionContext execCxt) {
return QueryIterBlockTriples.create(input, pattern, execCxt);
}
开发者ID:TopQuadrant,项目名称:shacl,代码行数:6,代码来源:CurrentThreadFunctionRegistry.java
示例17: main
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
public static void main (String[] argv)
{
String BASE = "http://example/" ;
BasicPattern bp = new BasicPattern() ;
Var var_x = Var.alloc("x") ;
Var var_z = Var.alloc("z") ;
// ---- Build expression
bp.add(new Triple(var_x, NodeFactory.createURI(BASE+"p"), var_z)) ;
Op op = new OpBGP(bp) ;
//Expr expr = ExprUtils.parse("?z < 2 ") ;
Expr expr = new E_LessThan(new ExprVar(var_z), NodeValue.makeNodeInteger(2)) ;
op = OpFilter.filter(expr, op) ;
// ---- Example setup
Model m = makeModel() ;
m.write(System.out, "TTL") ;
System.out.println("--------------") ;
System.out.print(op) ;
System.out.println("--------------") ;
// ---- Execute expression
QueryIterator qIter = Algebra.exec(op, m.getGraph()) ;
// -------- Either read the query iterator directly ...
if ( false )
{
for ( ; qIter.hasNext() ; )
{
Binding b = qIter.nextBinding() ;
Node n = b.get(var_x) ;
System.out.println(NodeFmtLib.displayStr(n)) ;
System.out.println(b) ;
}
qIter.close() ;
}
else
{
// -------- Or make ResultSet from it (but not both - reading an
// iterator consumes the current solution)
List<String> varNames = new ArrayList<String>() ;
varNames.add("x") ;
varNames.add("z") ;
ResultSet rs = new ResultSetStream(varNames, m, qIter);
ResultSetFormatter.out(rs) ;
qIter.close() ;
}
System.exit(0) ;
}
开发者ID:xcurator,项目名称:xcurator,代码行数:50,代码来源:AlgebraExec.java
示例18: exec
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
@Override
public QueryIterator exec(QueryIterator input, PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt)
{
// No real need to check the pattern arguments because
// the replacement triple pattern and regex will cope
// but we illustrate testing here.
Node nodeVar = argSubject.getArg() ;
String pattern = NodeUtils.stringLiteral(argObject.getArg()) ;
if ( pattern == null )
{
Log.warn(this, "Pattern must be a plain literal or xsd:string: "+argObject.getArg()) ;
return QueryIterNullIterator.create(execCxt) ;
}
if ( false )
// Old (ARQ 1) way - not recommended.
return buildSyntax(input, nodeVar, pattern, execCxt) ;
// Better
// Build a SPARQL algebra expression
Var var2 = createNewVar() ; // Hidden variable
BasicPattern bp = new BasicPattern() ;
Triple t = new Triple(nodeVar, RDFS.label.asNode(), var2) ;
bp.add(t) ;
OpBGP op = new OpBGP(bp) ;
Expr regex = new E_Regex(new ExprVar(var2.getName()), pattern, "i") ;
Op filter = OpFilter.filter(regex, op) ;
// ---- Evaluation
if ( true )
{
// Use the reference query engine
// Create a table for the input stream (so it uses working memory at this point,
// which is why this is not the preferred way).
// Then join to expression for this stage.
Table table = TableFactory.create(input) ;
Op op2 = OpJoin.create(OpTable.create(table), filter) ;
return Algebra.exec(op2, execCxt.getDataset()) ;
}
// Use the default, optimizing query engine.
return QC.execute(filter, input, execCxt) ;
}
开发者ID:xcurator,项目名称:xcurator,代码行数:47,代码来源:labelSearch.java
示例19: GenerateTriplesPlanImpl
import org.apache.jena.sparql.core.BasicPattern; //导入依赖的package包/类
/**
* Constructor.
*
* @param basicGraphPattern - the basic pattern.
*/
public GenerateTriplesPlanImpl(final BasicPattern basicGraphPattern) {
this.bgp = basicGraphPattern;
}
开发者ID:thesmartenergy,项目名称:sparql-generate,代码行数:9,代码来源:GenerateTriplesPlanImpl.java
注:本文中的org.apache.jena.sparql.core.BasicPattern类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论