use of com.bigdata.rdf.sparql.ast.service.ServiceNode in project wikidata-query-rdf by wikimedia.
the class MWApiServiceFactory method create.
@Override
public BigdataServiceCall create(ServiceCallCreateParams params, final ServiceParams serviceParams) {
ServiceNode serviceNode = params.getServiceNode();
requireNonNull(serviceNode, "Missing service node?");
try {
ApiTemplate template = getServiceTemplate(serviceParams);
return new MWApiServiceCall(template, getServiceHost(serviceParams), template.getInputVars(serviceParams), template.getOutputVars(serviceNode), params.getClientConnectionManager(), params.getTripleStore().getLexiconRelation(), requestTimer, getLimitsFromParams(serviceParams));
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Bad endpoint URL", e);
}
}
use of com.bigdata.rdf.sparql.ast.service.ServiceNode in project wikidata-query-rdf by wikimedia.
the class MWApiServiceFactory method getRequiredBound.
@Override
public Set<IVariable<?>> getRequiredBound(final ServiceNode serviceNode) {
ServiceParams params = serviceParamsFromNode(serviceNode);
ApiTemplate api = getServiceTemplate(params);
Map<String, IVariableOrConstant> potentialVars = api.getInputVars(params);
// Extract params that have variables linked to them
return potentialVars.entrySet().stream().filter(entry -> entry.getValue() != null && entry.getValue().isVar()).map(entry -> (IVariable<?>) entry.getValue()).collect(ImmutableSet.toImmutableSet());
}
use of com.bigdata.rdf.sparql.ast.service.ServiceNode in project wikidata-query-rdf by wikimedia.
the class GeoService method create.
@Override
public BigdataServiceCall create(ServiceCallCreateParams params, ServiceParams serviceParams) {
if (params == null)
throw new IllegalArgumentException();
final JoinGroupNode newGroup = buildServiceNode(params, serviceParams);
final BigdataValueFactory vf = params.getTripleStore().getValueFactory();
ServiceNode newServiceNode = new ServiceNode(new DummyConstantNode(vf.asValue(GeoSpatial.SEARCH)), newGroup);
// Transfer hints
newServiceNode.setQueryHints(params.getServiceNode().getQueryHints());
// Call delegate service
HttpClient client = params.getClientConnectionManager();
return (BigdataServiceCall) ServiceRegistry.getInstance().toServiceCall(params.getTripleStore(), client, GeoSpatial.SEARCH, newServiceNode, params.getStats());
}
use of com.bigdata.rdf.sparql.ast.service.ServiceNode in project wikidata-query-rdf by wikimedia.
the class LabelServiceUnitTest method desiredVars.
@SuppressWarnings("unchecked")
@Test
public void desiredVars() {
JoinGroupNode patterns = new JoinGroupNode();
// Label
patterns.addArg(new StatementPatternNode(new VarNode("item"), createURI(RDFS.LABEL), new VarNode("itemLabel")));
// Description
patterns.addArg(new StatementPatternNode(new VarNode("item2"), createURI(SchemaDotOrg.DESCRIPTION), new VarNode("itemDesc")));
// Fixed name
patterns.addArg(new StatementPatternNode(createURI(uris().entityIdToURI("Q123")), createURI(RDFS.LABEL), new VarNode("qLabel")));
// Parameters
patterns.addArg(new StatementPatternNode(createURI(BD.SERVICE_PARAM), createURI(LabelService.LANGUAGE_PARAM), createConstant("en,fr")));
ServiceNode serviceNode = new ServiceNode(createURI(LabelService.SERVICE_KEY), patterns);
final LabelService service = new LabelService();
Set<IVariable<?>> vars = service.getDesiredBound(serviceNode);
assertThat(vars, hasSize(2));
assertThat(vars, hasItems(equalTo(Var.var("item")), equalTo(Var.var("item2"))));
}
use of com.bigdata.rdf.sparql.ast.service.ServiceNode in project wikidata-query-rdf by wikimedia.
the class ApiTemplateUnitTest method testServiceOutput.
@Test
public void testServiceOutput() throws Exception {
JsonNode json = parseJson(JSON_CONFIG);
ApiTemplate template = ApiTemplate.fromJSON(json);
assertThat(template.getItemsPath(), equalTo("/api/query/pages/page/categories/cl"));
JoinGroupNode patterns = new JoinGroupNode();
// predefined variable
patterns.addArg(new StatementPatternNode(new VarNode("somevar"), createURI(ApiTemplate.OutputVariable.Type.STRING.predicate()), createURI(paramNameToURI("category"))));
// User-defined variable
patterns.addArg(new StatementPatternNode(new VarNode("var2"), createURI(ApiTemplate.OutputVariable.Type.URI.predicate()), createConstant("@somedata")));
// User-defined path variable
patterns.addArg(new StatementPatternNode(new VarNode("var3"), createURI(ApiTemplate.OutputVariable.Type.ITEM.predicate()), createConstant("item/@wikibase_id")));
// Variable with ordinal
patterns.addArg(new StatementPatternNode(new VarNode("var4"), createURI(ApiTemplate.OutputVariable.Type.ORDINAL.predicate()), createConstant("goat")));
ServiceNode serviceNode = new ServiceNode(createConstant("test"), patterns);
List<OutputVariable> outputs = template.getOutputVars(serviceNode);
assertThat(outputs.size(), equalTo(4));
// Pre-defined variable
OutputVariable var = outputs.get(0);
assertThat(var.getName(), equalTo("somevar"));
assertThat(var.getPath(), equalTo("@title"));
assertFalse(var.isOrdinal());
// User-defined variable
var = outputs.get(1);
assertThat(var.getName(), equalTo("var2"));
assertThat(var.getPath(), equalTo("@somedata"));
assertTrue(var.isURI());
assertFalse(var.isOrdinal());
assertThat(var.getURI("http://test.com/"), instanceOf(URI.class));
// URI keeps the case
assertThat(var.getURI("http://test.com/test").toString(), endsWith("test"));
// User-defined variable which is an item
var = outputs.get(2);
assertThat(var.getName(), equalTo("var3"));
assertThat(var.getPath(), equalTo("item/@wikibase_id"));
assertTrue(var.isURI());
assertFalse(var.isOrdinal());
assertThat(var.getURI("test"), instanceOf(URI.class));
// T172642: Item URIs will be uppercased
assertThat(var.getURI("test").toString(), endsWith("TEST"));
// Ordinal
var = outputs.get(3);
assertThat(var.getName(), equalTo("var4"));
assertThat(var.getPath(), equalTo("."));
assertFalse(var.isURI());
assertTrue(var.isOrdinal());
}
Aggregations