本文整理汇总了Java中org.openrdf.query.algebra.ValueConstant类的典型用法代码示例。如果您正苦于以下问题:Java ValueConstant类的具体用法?Java ValueConstant怎么用?Java ValueConstant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValueConstant类属于org.openrdf.query.algebra包,在下文中一共展示了ValueConstant类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: meet
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
@Override
public void meet(final Filter node) throws Exception {
super.meet(node);
final ValueExpr arg = node.getCondition();
if (arg instanceof FunctionCall) {
final FunctionCall fc = (FunctionCall) arg;
if (RANGE.stringValue().equals(fc.getURI())) {
//range(?var, start, end)
final List<ValueExpr> valueExprs = fc.getArgs();
if (valueExprs.size() != 3) {
throw new QueryEvaluationException("org.apache:range must have 3 parameters: variable, start, end");
}
final Var var = (Var) valueExprs.get(0);
final ValueConstant startVc = (ValueConstant) valueExprs.get(1);
final ValueConstant endVc = (ValueConstant) valueExprs.get(2);
final Value start = startVc.getValue();
final Value end = endVc.getValue();
rangeValues.put(var, new RangeValue(start, end));
node.setCondition(new ValueConstant(BooleanLiteralImpl.TRUE));
}
}
}
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:FilterRangeVisitor.java
示例2: testUnsupportedExtension
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
@Test
public void testUnsupportedExtension() throws Exception {
StatementPattern sp = new StatementPattern(new Var("x"), constant(TAKES), new Var("c"));
List<ExtensionElem> elements = Arrays.asList(new ExtensionElem(new Var("x"), "renamed"),
new ExtensionElem(new Not(new ValueConstant(VF.createLiteral(true))), "notTrue"),
new ExtensionElem(new ValueConstant(TAKES), "constant"));
Extension extensionNode = new Extension(sp, elements);
QueryRoot queryTree = new QueryRoot(extensionNode);
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof Extension);
Assert.assertEquals(elements, ((Extension) queryTree.getArg()).getElements());
TupleExpr innerQuery = ((Extension) queryTree.getArg()).getArg();
Assert.assertTrue(innerQuery instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) innerQuery;
Assert.assertEquals(Sets.newHashSet("x", "c"), pipelineNode.getAssuredBindingNames());
}
开发者ID:apache,项目名称:incubator-rya,代码行数:18,代码来源:SparqlToPipelineTransformVisitorTest.java
示例3: getTimeUnit
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
private static TimeUnit getTimeUnit(ValueConstant val) {
Preconditions.checkArgument(val.getValue() instanceof URI);
URI uri = (URI) val.getValue();
Preconditions.checkArgument(uri.getNamespace().equals(temporalNameSpace));
switch (uri.getLocalName()) {
case "days":
return TimeUnit.DAYS;
case "hours":
return TimeUnit.HOURS;
case "minutes":
return TimeUnit.MINUTES;
default:
throw new IllegalArgumentException("Invalid time unit for Periodic Function.");
}
}
开发者ID:apache,项目名称:incubator-rya,代码行数:17,代码来源:PeriodicQueryUtil.java
示例4: meetNAryValueOperator
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
@Override
public void meetNAryValueOperator(NAryValueOperator node) {
List<ValueExpr> oldValues = node.getArguments();
List<ValueExpr> newValues = Lists.newArrayList();
for (ValueExpr v : oldValues) {
if (v instanceof Var) {
Var var = (Var) v;
if (!(var.isConstant() && hMap.containsKey(var.getName()))) {
String val = hMap.get(var.getName());
if (val.startsWith("-const-")) {
newValues.add(new ValueConstant(valMap.get(val)));
} else {
var.setName(val);
newValues.add(var);
}
}
} else {
newValues.add(v);
}
}
node.setArguments(newValues);
}
开发者ID:apache,项目名称:incubator-rya,代码行数:27,代码来源:QueryVariableNormalizer.java
示例5: extractArguments
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
private Value[] extractArguments(final String matchName, final FunctionCall call) {
final Value args[] = new Value[call.getArgs().size() - 1];
int argI = 0;
for (int i = 0; i != call.getArgs().size(); ++i) {
final ValueExpr arg = call.getArgs().get(i);
if (argI == i && arg instanceof Var && matchName.equals(((Var)arg).getName())) {
continue;
}
if (arg instanceof ValueConstant) {
args[argI] = ((ValueConstant)arg).getValue();
} else if (arg instanceof Var && ((Var)arg).hasValue()) {
args[argI] = ((Var)arg).getValue();
} else {
throw new IllegalArgumentException("Query error: Found " + arg + ", expected a Literal, BNode or URI");
}
++argI;
}
return args;
}
开发者ID:apache,项目名称:incubator-rya,代码行数:20,代码来源:FilterFunctionOptimizer.java
示例6: extractArguments
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
/**
* Extracts the arguments used in a {@link FunctionCall}.
* @param matchName - The variable name to match to arguments used in the {@link FunctionCall}.
* @param call - The {@link FunctionCall} to match against.
* @return - The {@link Value}s matched.
*/
public static Object[] extractArguments(final String matchName, final FunctionCall call) {
final Object[] args = new Object[call.getArgs().size() - 1];
int argI = 0;
for (int i = 0; i != call.getArgs().size(); ++i) {
final ValueExpr arg = call.getArgs().get(i);
if (argI == i && arg instanceof Var && matchName.equals(((Var)arg).getName())) {
continue;
}
if (arg instanceof ValueConstant) {
args[argI] = ((ValueConstant)arg).getValue();
} else if (arg instanceof Var && ((Var)arg).hasValue()) {
args[argI] = ((Var)arg).getValue();
} else {
args[argI] = arg;
}
++argI;
}
return args;
}
开发者ID:apache,项目名称:incubator-rya,代码行数:26,代码来源:GeoParseUtils.java
示例7: testConcreteSP
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
@Test
public void testConcreteSP() {
Extension extension = new Extension(new SingletonSet(),
new ExtensionElem(new ValueConstant(FOAF.PERSON), "x"),
new ExtensionElem(new ValueConstant(RDF.TYPE), "y"),
new ExtensionElem(new ValueConstant(OWL.CLASS), "z"));
Projection projection = new Projection(extension, new ProjectionElemList(
new ProjectionElem("x", "subject"),
new ProjectionElem("y", "predicate"),
new ProjectionElem("z", "object")));
ConstructConsequentVisitor visitor = new ConstructConsequentVisitor();
projection.visit(visitor);
Set<StatementPattern> expected = Sets.newHashSet(
new StatementPattern(s(FOAF.PERSON), p(RDF.TYPE), o(OWL.CLASS)));
Assert.assertEquals(expected, visitor.getConsequents());
}
开发者ID:apache,项目名称:incubator-rya,代码行数:17,代码来源:ConstructConsequentVisitorTest.java
示例8: extractNegatedProperties
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
private void extractNegatedProperties(final ValueExpr condition,
final Set<URI> negatedProperties) {
if (condition instanceof And) {
final And and = (And) condition;
extractNegatedProperties(and.getLeftArg(), negatedProperties);
extractNegatedProperties(and.getRightArg(), negatedProperties);
} else if (condition instanceof Compare) {
final Compare compare = (Compare) condition;
Preconditions.checkArgument(compare.getOperator() == CompareOp.NE);
if (compare.getLeftArg() instanceof ValueConstant) {
Preconditions.checkArgument(compare.getRightArg() instanceof Var);
negatedProperties.add((URI) ((ValueConstant) compare.getLeftArg()).getValue());
} else if (compare.getRightArg() instanceof ValueConstant) {
Preconditions.checkArgument(compare.getLeftArg() instanceof Var);
negatedProperties
.add((URI) ((ValueConstant) compare.getRightArg()).getValue());
} else {
fail("Unsupported path expression. Check condition node: ", condition);
}
}
}
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:23,代码来源:SPARQLRenderer.java
示例9: extractConstructVar
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
private static Var extractConstructVar(final Map<String, ExtensionElem> extensions,
final ProjectionElem projection) {
final ExtensionElem extension = extensions.get(projection.getSourceName());
String name = projection.getSourceName();
if (name.startsWith("-anon-")) {
name += "-construct";
}
if (extension == null || extension.getExpr() instanceof BNodeGenerator) {
final Var var = new Var(name);
var.setAnonymous(name.startsWith("-anon-"));
return var;
} else if (extension.getExpr() instanceof ValueConstant) {
final ValueConstant constant = (ValueConstant) extension.getExpr();
return new Var(name, constant.getValue());
} else {
throw new UnsupportedOperationException(
"Unsupported extension in construct query: " + extension);
}
}
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:20,代码来源:SPARQLRenderer.java
示例10: valueFieldExpr
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
/**
* Get an object representing the value field of some value expression, or
* return null if the expression isn't supported.
*/
private Object valueFieldExpr(ValueExpr expr) {
if (expr instanceof Var) {
return valueFieldExpr(((Var) expr).getName());
}
else if (expr instanceof ValueConstant) {
return new Document("$literal", ((ValueConstant) expr).getValue().stringValue());
}
else {
return null;
}
}
开发者ID:apache,项目名称:incubator-rya,代码行数:16,代码来源:AggregationPipelineQueryNode.java
示例11: testExtend
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
@Test
public void testExtend() {
final AggregationPipelineQueryNode base = new AggregationPipelineQueryNode(
collection,
new LinkedList<>(),
Sets.newHashSet("x", "y"),
Sets.newHashSet("x", "y", "opt"),
HashBiMap.create());
// Extend with a mix of variables and constants
List<ExtensionElem> extensionElements = Arrays.asList(
new ExtensionElem(new Var("x"), "subject"),
new ExtensionElem(new ValueConstant(RDF.TYPE), "predicate"),
new ExtensionElem(new Var("y"), "object"));
AggregationPipelineQueryNode node = base.clone();
boolean success = node.extend(extensionElements);
Assert.assertTrue(success);
Assert.assertEquals(1, node.getPipeline().size());
Assert.assertEquals(Sets.newHashSet("x", "y", "subject", "predicate", "object"),
node.getAssuredBindingNames());
Assert.assertEquals(Sets.newHashSet("x", "y", "subject", "predicate", "object", "opt"),
node.getBindingNames());
// Attempt to extend with an unsupported expression
extensionElements = Arrays.asList(
new ExtensionElem(new Var("x"), "subject"),
new ExtensionElem(new Not(new ValueConstant(VF.createLiteral(true))), "notTrue"));
node = base.clone();
success = node.extend(extensionElements);
Assert.assertFalse(success);
Assert.assertEquals(base, node);
}
开发者ID:apache,项目名称:incubator-rya,代码行数:31,代码来源:AggregationPipelineQueryNodeTest.java
示例12: testExtension
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
@Test
public void testExtension() throws Exception {
QueryRoot queryTree = new QueryRoot(new Extension(
new StatementPattern(new Var("x"), constant(TAKES), new Var("c")),
new ExtensionElem(new Var("x"), "renamed"),
new ExtensionElem(new ValueConstant(TAKES), "constant")));
SparqlToPipelineTransformVisitor visitor = new SparqlToPipelineTransformVisitor(collection);
queryTree.visit(visitor);
Assert.assertTrue(queryTree.getArg() instanceof AggregationPipelineQueryNode);
AggregationPipelineQueryNode pipelineNode = (AggregationPipelineQueryNode) queryTree.getArg();
Assert.assertEquals(Sets.newHashSet("x", "c", "renamed", "constant"), pipelineNode.getAssuredBindingNames());
}
开发者ID:apache,项目名称:incubator-rya,代码行数:13,代码来源:SparqlToPipelineTransformVisitorTest.java
示例13: parseAndSetValues
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
/**
*
* @param values - Values extracted from FunctionCall representing the PeriodicQuery Filter
* @param arg - Argument of the PeriodicQueryNode that will be created (PeriodicQueryNode is a UnaryTupleOperator)
* @return - PeriodicQueryNode to be inserted in place of the original FunctionCall
* @throws Exception
*/
private static PeriodicQueryNode parseAndSetValues(List<ValueExpr> values, TupleExpr arg) throws Exception {
// general validation of input
Preconditions.checkArgument(values.size() == 4);
Preconditions.checkArgument(values.get(0) instanceof Var);
Preconditions.checkArgument(values.get(1) instanceof ValueConstant);
Preconditions.checkArgument(values.get(2) instanceof ValueConstant);
Preconditions.checkArgument(values.get(3) instanceof ValueConstant);
// get temporal variable
Var var = (Var) values.get(0);
Preconditions.checkArgument(var.getValue() == null);
String tempVar = var.getName();
// get TimeUnit
TimeUnit unit = getTimeUnit((ValueConstant) values.get(3));
// get window and period durations
double windowDuration = parseTemporalDuration((ValueConstant) values.get(1));
double periodDuration = parseTemporalDuration((ValueConstant) values.get(2));
long windowMillis = convertToMillis(windowDuration, unit);
long periodMillis = convertToMillis(periodDuration, unit);
// period must evenly divide window at least once
Preconditions.checkArgument(windowMillis > periodMillis);
Preconditions.checkArgument(windowMillis % periodMillis == 0, "Period duration does not evenly divide window duration.");
// create PeriodicMetadata.Builder
return new PeriodicQueryNode(windowMillis, periodMillis, TimeUnit.MILLISECONDS, tempVar, arg);
}
开发者ID:apache,项目名称:incubator-rya,代码行数:36,代码来源:PeriodicQueryUtil.java
示例14: parseTemporalDuration
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
private static double parseTemporalDuration(ValueConstant valConst) {
Value val = valConst.getValue();
Preconditions.checkArgument(val instanceof Literal);
Literal literal = (Literal) val;
String stringVal = literal.getLabel();
URI dataType = literal.getDatatype();
Preconditions.checkArgument(dataType.equals(XMLSchema.DECIMAL) || dataType.equals(XMLSchema.DOUBLE)
|| dataType.equals(XMLSchema.FLOAT) || dataType.equals(XMLSchema.INTEGER) || dataType.equals(XMLSchema.INT));
return Double.parseDouble(stringVal);
}
开发者ID:apache,项目名称:incubator-rya,代码行数:11,代码来源:PeriodicQueryUtil.java
示例15: periodicNodeNotPresentTest
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
@Test
public void periodicNodeNotPresentTest() throws Exception {
List<ValueExpr> values = Arrays.asList(new Var("time"), new ValueConstant(vf.createLiteral(12.0)), new ValueConstant(vf.createLiteral(6.0)), new ValueConstant(vf.createURI(PeriodicQueryUtil.temporalNameSpace + "hours")));
FunctionCall func = new FunctionCall("uri:func", values);
Optional<PeriodicQueryNode> node1 = PeriodicQueryUtil.getPeriodicQueryNode(func, new Join());
Assert.assertEquals(false, node1.isPresent());
}
开发者ID:apache,项目名称:incubator-rya,代码行数:9,代码来源:PeriodicQueryUtilTest.java
示例16: periodicNodePresentTest
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
@Test
public void periodicNodePresentTest() throws Exception {
List<ValueExpr> values = Arrays.asList(new Var("time"), new ValueConstant(vf.createLiteral(12.0)), new ValueConstant(vf.createLiteral(6.0)), new ValueConstant(vf.createURI(PeriodicQueryUtil.temporalNameSpace + "hours")));
FunctionCall func = new FunctionCall(PeriodicQueryUtil.PeriodicQueryURI, values);
Optional<PeriodicQueryNode> node1 = PeriodicQueryUtil.getPeriodicQueryNode(func, new Join());
Assert.assertEquals(true, node1.isPresent());
PeriodicQueryNode node2 = new PeriodicQueryNode(12*60*60*1000L, 6*3600*1000L, TimeUnit.MILLISECONDS, "time", new Join());
Assert.assertEquals(true, periodicNodesEqualIgnoreArg(node1.get(), node2));
}
开发者ID:apache,项目名称:incubator-rya,代码行数:13,代码来源:PeriodicQueryUtilTest.java
示例17: periodicNodeFractionalDurationTest
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
@Test
public void periodicNodeFractionalDurationTest() throws Exception {
List<ValueExpr> values = Arrays.asList(new Var("time"), new ValueConstant(vf.createLiteral(1)), new ValueConstant(vf.createLiteral(.5)), new ValueConstant(vf.createURI(PeriodicQueryUtil.temporalNameSpace + "hours")));
FunctionCall func = new FunctionCall(PeriodicQueryUtil.PeriodicQueryURI, values);
Optional<PeriodicQueryNode> node1 = PeriodicQueryUtil.getPeriodicQueryNode(func, new Join());
Assert.assertEquals(true, node1.isPresent());
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(node1.get(), node2));
}
开发者ID:apache,项目名称:incubator-rya,代码行数:16,代码来源:PeriodicQueryUtilTest.java
示例18: meet
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
@Override
public void meet(ValueConstant node) throws RuntimeException {
String key = node.getValue().toString();
if(constantMap.containsKey(key)) {
int count = constantMap.get(key);
count += 1;
constantMap.put(key, count);
} else {
constantMap.put(key,1);
}
}
开发者ID:apache,项目名称:incubator-rya,代码行数:15,代码来源:VarConstantIndexListPruner.java
示例19: filterCommonVars
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
private static List<List<String>> filterCommonVars(List<QueryModelNode> vars1, List<QueryModelNode> vars2) {
List<List<String>> varList = Lists.newArrayList();
List<String> varList1 = Lists.newArrayList();
List<String> varList2 = Lists.newArrayList();
for (int i = 0; i < vars1.size(); i++) {
if ((vars1.get(i) instanceof ValueConstant) && (vars2.get(i) instanceof Var)) {
ValueConstant vc = (ValueConstant) vars1.get(i);
String s = vc.getValue().toString();
if(vc.getValue() instanceof Literal) {
s = s.substring(1, s.length() - 1);
}
s = "-const-" + s;
varList1.add(s);
varList2.add(((Var)vars2.get(i)).getName());
} else if(!(vars1.get(i) instanceof ValueConstant)){
if (!((Var) vars1.get(i)).isConstant() && (vars2.get(i) instanceof Var)
&& !((Var) vars2.get(i)).isConstant()) {
varList1.add(((Var) vars1.get(i)).getName());
varList2.add(((Var) vars2.get(i)).getName());
} else if (((Var) vars1.get(i)).isConstant() && (vars2.get(i) instanceof Var)
&& !((Var) vars2.get(i)).isConstant()) {
varList1.add(((Var) vars1.get(i)).getName());
varList2.add(((Var) vars2.get(i)).getName());
}
}
}
varList.add(varList1);
varList.add(varList2);
return varList;
}
开发者ID:apache,项目名称:incubator-rya,代码行数:41,代码来源:QueryVariableNormalizer.java
示例20: filterCompare
import org.openrdf.query.algebra.ValueConstant; //导入依赖的package包/类
/**
* @param filter1
* @param filter2
* @return true if filter2 is equal to filter1 once variables in filter2 are replaced with variables and constants
* occurring in same position in filter1 (allows filter1 to contain constants where filter2 contains variables)
* @throws Exception
*/
private static boolean filterCompare(Filter filter1, Filter filter2) throws Exception {
NodeCollector nc1 = new NodeCollector();
NodeCollector nc2 = new NodeCollector();
filter1.getCondition().visit(nc1);
filter2.getCondition().visit(nc2);
List<QueryModelNode> nodeList1 = nc1.getNodes();
List<QueryModelNode> nodeList2 = nc2.getNodes();
if (nodeList1.size() != nodeList2.size()) {
return false;
}
for (int i = 0; i < nodeList1.size(); i++) {
if ((nodeList1.get(i) instanceof ValueConstant) && (nodeList2.get(i) instanceof Var)) {
continue;
} else {
if (nodeList1.get(i).getClass() != nodeList2.get(i).getClass()) {
return false;
}
}
}
return true;
}
开发者ID:apache,项目名称:incubator-rya,代码行数:36,代码来源:QueryVariableNormalizer.java
注:本文中的org.openrdf.query.algebra.ValueConstant类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论