use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.
the class WikibaseDistanceBOp method get.
@Override
public IV get(IBindingSet bindingSet) {
final IV left = getAndCheckLiteral(0, bindingSet);
final IV right = getAndCheckLiteral(1, bindingSet);
final CoordinateDD leftPoint = getCoordinateFromIV(left);
final CoordinateDD rightPoint = getCoordinateFromIV(right);
// TODO: allow to supply Units
final double distance;
if (leftPoint.equals(rightPoint) || veryClose(leftPoint, rightPoint)) {
distance = 0;
} else {
distance = leftPoint.distance(rightPoint, UNITS.Kilometers);
}
final BigdataLiteral dist = getValueFactory().createLiteral(distance);
return super.asIV(dist, bindingSet);
}
use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.
the class EmptyLabelServiceOptimizer method addResolutions.
/**
* Infer that the user wanted to resolve some variables using the label
* service.
*/
private void addResolutions(AST2BOpContext ctx, JoinGroupNode g, ProjectionNode p) {
if (p == null) {
return;
}
for (AssignmentNode a : p) {
IVariable<IV> v = a.getVar();
if (a.getValueExpression() != v) {
continue;
}
/*
* Try and match a variable name we can resolve via labels. Note
* that we should match AltLabel before Label because Label is a
* suffix of it....
*/
boolean replaced = addResolutionIfSuffix(ctx, g, "AltLabel", SKOS.ALT_LABEL, v) || addResolutionIfSuffix(ctx, g, "Label", RDFS.LABEL, v) || addResolutionIfSuffix(ctx, g, "Description", DESCRIPTION, v);
if (replaced && log.isDebugEnabled()) {
log.debug("Resolving {} using a label lookup.", v);
}
}
}
use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.
the class EmptyLabelServiceOptimizer method addResolutionIfSuffix.
/**
* Add the join group to resolve a variable if it matches a suffix,
* returning true if it matched, false otherwise.
*/
@SuppressFBWarnings(value = "OCP_OVERLY_CONCRETE_PARAMETER", justification = "Using AST2BOpContext makes sense since it is the only type that will ever be passed")
private boolean addResolutionIfSuffix(AST2BOpContext ctx, JoinGroupNode g, String suffix, URI labelType, IVariable<IV> iVar) {
if (!iVar.getName().endsWith(suffix)) {
return false;
}
String source = iVar.getName().substring(0, iVar.getName().length() - suffix.length());
IConstant<IV> labelTypeAsConstant = ctx.getAbstractTripleStore().getVocabulary().getConstant(labelType);
g.addArg(new StatementPatternNode(new VarNode(source), new ConstantNode(labelTypeAsConstant), new VarNode(iVar)));
return true;
}
use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.
the class ApiTemplate method getOutputVars.
/**
* Create map of output variables from template and service params.
*/
public List<OutputVariable> getOutputVars(final ServiceNode serviceNode) {
List<OutputVariable> vars = new ArrayList<>(outputVars.size());
final GraphPatternGroup<IGroupMemberNode> group = serviceNode.getGraphPattern();
requireNonNull(serviceNode, "Group node is null?");
String prefix = paramNameToURI("").stringValue();
group.iterator().forEachRemaining(node -> {
// ?variable wikibase:output "x/path"
if (node instanceof StatementPatternNode) {
final StatementPatternNode sp = (StatementPatternNode) node;
if (sp.s().isVariable() && sp.o().isConstant() && sp.p().isConstant()) {
for (OutputVariable.Type varType : OutputVariable.Type.values()) {
if (varType.predicate.equals(sp.p().getValue())) {
IVariable v = (IVariable) sp.s().getValueExpression();
if (varType == ORDINAL) {
// Ordinal values ignore the object
vars.add(new OutputVariable(varType, v, "."));
break;
}
IV value = sp.o().getValueExpression().get();
if (value.isURI()) {
String paramName = value.stringValue().substring(prefix.length());
vars.add(new OutputVariable(varType, v, outputVars.get(paramName)));
} else {
vars.add(new OutputVariable(varType, v, value.stringValue()));
}
break;
}
}
}
}
});
return vars;
}
use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.
the class CoordinatePartBOp method get.
@Override
public IV get(IBindingSet bindingSet) {
final IV coord = getAndCheckLiteral(0, bindingSet);
final WikibasePoint point = pointFromIV(coord);
final BigdataValue result;
switch(part()) {
case GLOBE:
String globe = point.getGlobe();
if (globe == null) {
result = getValueFactory().createLiteral("");
} else {
result = getValueFactory().createURI(point.getGlobe());
}
break;
case LON:
result = getValueFactory().createLiteral(Double.parseDouble(point.getLongitude()));
break;
case LAT:
result = getValueFactory().createLiteral(Double.parseDouble(point.getLatitude()));
break;
default:
throw new IllegalArgumentException("Unknown part specified");
}
return super.asIV(result, bindingSet);
}
Aggregations