use of com.bigdata.rdf.sparql.ast.IGroupMemberNode in project wikidata-query-rdf by wikimedia.
the class MWApiServiceFactory method serviceParamsFromNode.
/**
* Get service params from Service Node.
* FIXME: copypaste from ServiceParams.java, should be integrated there
*/
private ServiceParams serviceParamsFromNode(final ServiceNode serviceNode) {
requireNonNull(serviceNode, "Service node is null?");
final GraphPatternGroup<IGroupMemberNode> group = serviceNode.getGraphPattern();
requireNonNull(group, "Group node is null?");
final ServiceParams serviceParams = new ServiceParams();
for (IGroupMemberNode node : group) {
if (node instanceof StatementPatternNode) {
final StatementPatternNode sp = (StatementPatternNode) node;
final TermNode s = sp.s();
if (s.isConstant() && BD.SERVICE_PARAM.equals(s.getValue())) {
if (sp.p().isVariable()) {
throw new RuntimeException("not a valid service param triple pattern, " + "predicate must be constant: " + sp);
}
final URI param = (URI) sp.p().getValue();
serviceParams.add(param, sp.o());
}
}
}
return serviceParams;
}
use of com.bigdata.rdf.sparql.ast.IGroupMemberNode in project wikidata-query-rdf by wikimedia.
the class EmptyLabelServiceOptimizer method getProjectionNode.
@SuppressFBWarnings(value = "OCP_OVERLY_CONCRETE_PARAMETER", justification = "We only process ServiceNode's so that's the appropriate type")
private ProjectionNode getProjectionNode(ServiceNode service) {
IGroupNode<IGroupMemberNode> parent = service.getParent();
while (parent != null) {
ProjectionNode projection = (ProjectionNode) parent.annotations().get(LABEL_SERVICE_PROJECTION);
if (projection != null) {
return projection;
}
parent = parent.getParent();
}
return null;
}
use of com.bigdata.rdf.sparql.ast.IGroupMemberNode 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;
}
Aggregations