本文整理汇总了Java中org.openrdf.query.algebra.TupleExpr.visit方法的典型用法代码示例。如果您正苦于以下问题:Java TupleExpr.visit方法的具体用法?Java TupleExpr.visit怎么用?Java TupleExpr.visit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.query.algebra.TupleExpr
的用法示例。
在下文中一共展示了TupleExpr.visit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rewrite
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
/**
* Rewrite a given query to add inference.
*
* @param ql the query language used for the query
* @param query the query to rewrite
* @param baseuri a base URI to use for the query
* @return rewritten query that includes inference
* @throws MalformedQueryException if the query is malformed
* @throws RepositoryException if there was a problem while rewriting
*/
public Query rewrite(QueryLanguage ql, String query, String baseuri)
throws MalformedQueryException, RepositoryException {
// parse query using Sesame
QueryParserFactory f = QueryParserRegistry.getInstance().get(ql);
QueryParser parser = f.getParser();
ParsedQuery parsed = parser.parseQuery(query, baseuri);
// get SPARQL algebra expression from parsed query
TupleExpr expr = parsed.getTupleExpr();
// rewrite query using visitor pattern
RuleTransformationVisitor visitor
= new RuleTransformationVisitor(rules);
expr.visit(visitor);
// return new query based on rewritten algebra expression
return getExprQuery(parsed, expr);
}
示例2: getJoinSelect
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
public double getJoinSelect(RdfCloudTripleStoreConfiguration conf, TupleExpr te1, TupleExpr te2) throws TableNotFoundException {
SpExternalCollector spe = new SpExternalCollector();
te2.visit(spe);
List<QueryModelNode> espList = spe.getSpExtTup();
double min = Double.MAX_VALUE;
for (QueryModelNode node : espList) {
double select = getSelectivity(conf, te1, node);
if (min > select) {
min = select;
}
}
return min;
}
示例3: meet
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
@Override
public void meet(Join node) {
List<TupleExpr> reOrder = reOrderMap.get(node);
if (reOrder != null) {
List<Filter> filterList = Lists.newArrayList(filterArgs.get(node));
node.replaceWith(getNewJoin(reOrder, getFilterChain(filterList)));
for (TupleExpr te : reOrder) {
if (!(te instanceof StatementPattern) && !(te instanceof ExternalTupleSet)) {
te.visit(this);
}
}
}
super.meet(node);
}
示例4: evaluate
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
static CloseableIteration<BindingSet, QueryEvaluationException> evaluate(
final TripleTransaction transaction, final TupleExpr expr,
@Nullable final Dataset dataset, @Nullable final BindingSet bindings,
@Nullable final Long timeout) throws QueryEvaluationException {
Preconditions.checkNotNull(transaction);
final AtomicBoolean delegate = new AtomicBoolean(false);
expr.visit(new QueryModelVisitorBase<RuntimeException>() {
@Override
public void meet(final StatementPattern node) throws RuntimeException {
delegate.set(true);
}
});
final EvaluationStrategy strategy = delegate.get() ? new DelegatingEvaluationStrategy(
transaction, dataset, timeout, false) : new LocalEvaluationStrategy(transaction,
dataset, timeout);
return strategy
.evaluate(expr, bindings != null ? bindings : EmptyBindingSet.getInstance());
}
示例5: meet
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
@Override
public void meet(Join node) {
try {
if (node.getLeftArg() instanceof FixedStatementPattern && node.getRightArg() instanceof DoNotExpandSP) {
return;
}
List<TupleExpr> joinArgs = getJoinArgs(node, new ArrayList<TupleExpr>());
HashMultimap<String, StatementPattern> varMap = getVarBins(joinArgs);
while (!varMap.keySet().isEmpty()) {
String s = getHighestPriorityKey(varMap);
constructTuple(varMap, joinArgs, s);
}
List<TupleExpr> filterChain = getFilterChain(joinArgs);
for (TupleExpr te : joinArgs) {
if (!(te instanceof StatementPattern) || !(te instanceof EntityTupleSet)) {
te.visit(this);
}
}
// Replace old join hierarchy
node.replaceWith(getNewJoin(joinArgs, filterChain));
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: optimize
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
@Override
public void optimize(final TupleExpr tupleExpr, final Dataset dataset, final BindingSet bindings) {
// use native support for range queries
if (_ranges_indexed) {
tupleExpr.visit(new RangeQueryVisitor(tupleExpr));
tupleExpr.visit(new OrderByVisitor(tupleExpr));
}
// use native cumulus model
tupleExpr.visit(new CumulusNativeModelVisitor());
}
示例7: setVarOrderAndQueryType
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
private void setVarOrderAndQueryType(final QueryMetadata.Builder builder, final TupleExpr te) {
final QueryMetadataLocator locator = new QueryMetadataLocator();
try {
te.visit(locator);
} catch (final Exception e) {
throw new RuntimeException(e);
}
builder.setVarOrder(locator.getVarOrder());
builder.setQueryType(locator.getQueryType());
}
示例8: processPropertySearches
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
private void processPropertySearches(final TupleExpr tupleExpr, final Collection<Var> searchProperties) {
final MatchStatementVisitor matchStatements = new MatchStatementVisitor(searchProperties);
tupleExpr.visit(matchStatements);
for (final StatementPattern matchStatement: matchStatements.matchStatements) {
final Var subject = matchStatement.getSubjectVar();
if (subject.hasValue() && !(subject.getValue() instanceof Resource)) {
throw new IllegalArgumentException("Query error: Found " + subject.getValue() + ", expected an URI or BNode");
}
Validate.isTrue(subject.hasValue() || subject.getName() != null);
Validate.isTrue(!matchStatement.getObjectVar().hasValue() && matchStatement.getObjectVar().getName() != null);
buildQuery(tupleExpr, matchStatement);
}
}
示例9: testPeriodicNodeLocation
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
@Test
public void testPeriodicNodeLocation() throws MalformedQueryException {
String query = "prefix function: <http://org.apache.rya/function#> " //n
+ "prefix time: <http://www.w3.org/2006/time#> " //n
+ "prefix fn: <http://www.w3.org/2006/fn#> " //n
+ "select ?obs ?time ?lat where {" //n
+ "Filter(function:periodic(?time, 1,.5,time:hours)) " //n
+ "Filter(fn:test(?lat, 25)) " //n
+ "?obs <uri:hasTime> ?time. " //n
+ "?obs <uri:hasLattitude> ?lat }"; //n
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
TupleExpr te = pq.getTupleExpr();
te.visit(new PeriodicQueryNodeVisitor());
PeriodicNodeCollector collector = new PeriodicNodeCollector();
te.visit(collector);
Assert.assertEquals(2, collector.getPos());
te.visit(new PeriodicQueryNodeRelocator());
collector.resetCount();
te.visit(collector);
Assert.assertEquals(1, collector.getPos());
double window = 1*60*60*1000;
double period = .5*3600*1000;
PeriodicQueryNode node2 = new PeriodicQueryNode((long) window, (long) period, TimeUnit.MILLISECONDS, "time", new Join());
Assert.assertEquals(true, periodicNodesEqualIgnoreArg(node2, collector.getPeriodicQueryNode()));
}
示例10: moveFiltersToTop
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
/**
*
* This method moves the Filters of a specified {@link TupleExpr} to the top
* of the TupleExpr.
*
* @param query
* - query whose filters will be relocated
* @return - TupleExpr with filters relocated to top
*/
public static TupleExpr moveFiltersToTop(TupleExpr query) {
ProjectionAndFilterGatherer fg = new ProjectionAndFilterGatherer();
query.visit(fg);
List<ValueExpr> filterCond = new ArrayList<>(fg.filterCond);
Projection projection = fg.projection;
if (filterCond.size() == 0) {
return query;
}
Filter first = new Filter();
first.setCondition(filterCond.remove(0));
Filter current = first;
for (ValueExpr cond : filterCond) {
Filter filter = new Filter(null, cond);
current.setArg(filter);
current = filter;
}
TupleExpr te = projection.getArg();
projection.setArg(first);
current.setArg(te);
return query;
}
示例11: process
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
@Override
public Double process(TupleExpr expr) {
synchronized (this) {
expr.visit(this);
return cardIndex.get(expr);
}
}
示例12: optimize
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) {
parent = null;
tupleExpr.visit(this);
}
示例13: optimize
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) {
tupleExpr.visit(this);
}
示例14: getCost
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
public Double getCost(TupleExpr expr) {
cost = 0;
expr.visit(this);
return cost;
}
示例15: tupleContainsLeftJoins
import org.openrdf.query.algebra.TupleExpr; //导入方法依赖的package包/类
public static boolean tupleContainsLeftJoins(final TupleExpr node) {
final LeftJoinVisitor lj = new LeftJoinVisitor();
node.visit(lj);
return lj.containsLeftJoin;
}