Search in sources :

Example 1 with ServiceNode

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);
    }
}
Also used : ServiceNode(com.bigdata.rdf.sparql.ast.service.ServiceNode) MalformedURLException(java.net.MalformedURLException)

Example 2 with ServiceNode

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());
}
Also used : IVariableOrConstant(com.bigdata.bop.IVariableOrConstant) URIImpl(org.openrdf.model.impl.URIImpl) Ontology(org.wikidata.query.rdf.common.uri.Ontology) LoggerFactory(org.slf4j.LoggerFactory) AbstractServiceFactory(com.bigdata.rdf.sparql.ast.eval.AbstractServiceFactory) BigdataServiceCall(com.bigdata.rdf.sparql.ast.service.BigdataServiceCall) IVariableOrConstant(com.bigdata.bop.IVariableOrConstant) BigdataNativeServiceOptions(com.bigdata.rdf.sparql.ast.service.BigdataNativeServiceOptions) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) URI(org.openrdf.model.URI) Path(java.nio.file.Path) GraphPatternGroup(com.bigdata.rdf.sparql.ast.GraphPatternGroup) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) ServiceRegistry(com.bigdata.rdf.sparql.ast.service.ServiceRegistry) Set(java.util.Set) IOException(java.io.IOException) Reader(java.io.Reader) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) IGroupMemberNode(com.bigdata.rdf.sparql.ast.IGroupMemberNode) StandardCharsets(java.nio.charset.StandardCharsets) BD(com.bigdata.rdf.store.BD) ServiceNode(com.bigdata.rdf.sparql.ast.service.ServiceNode) Paths(java.nio.file.Paths) TermNode(com.bigdata.rdf.sparql.ast.TermNode) IVariable(com.bigdata.bop.IVariable) Timer(com.codahale.metrics.Timer) Mediawiki(org.wikidata.query.rdf.common.uri.Mediawiki) IServiceOptions(com.bigdata.rdf.sparql.ast.service.IServiceOptions) ServiceCallCreateParams(com.bigdata.rdf.sparql.ast.service.ServiceCallCreateParams) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) IVariable(com.bigdata.bop.IVariable)

Example 3 with ServiceNode

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());
}
Also used : ServiceNode(com.bigdata.rdf.sparql.ast.service.ServiceNode) BigdataValueFactory(com.bigdata.rdf.model.BigdataValueFactory) DummyConstantNode(com.bigdata.rdf.sparql.ast.DummyConstantNode) HttpClient(org.eclipse.jetty.client.HttpClient) JoinGroupNode(com.bigdata.rdf.sparql.ast.JoinGroupNode) BigdataServiceCall(com.bigdata.rdf.sparql.ast.service.BigdataServiceCall)

Example 4 with ServiceNode

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"))));
}
Also used : VarNode(com.bigdata.rdf.sparql.ast.VarNode) ServiceNode(com.bigdata.rdf.sparql.ast.service.ServiceNode) IVariable(com.bigdata.bop.IVariable) JoinGroupNode(com.bigdata.rdf.sparql.ast.JoinGroupNode) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) Test(org.junit.Test)

Example 5 with ServiceNode

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());
}
Also used : VarNode(com.bigdata.rdf.sparql.ast.VarNode) ServiceNode(com.bigdata.rdf.sparql.ast.service.ServiceNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) JoinGroupNode(com.bigdata.rdf.sparql.ast.JoinGroupNode) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) URI(org.openrdf.model.URI) MWApiServiceFactory.paramNameToURI(org.wikidata.query.rdf.blazegraph.mwapi.MWApiServiceFactory.paramNameToURI) OutputVariable(org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable) Test(org.junit.Test)

Aggregations

ServiceNode (com.bigdata.rdf.sparql.ast.service.ServiceNode)6 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)4 JoinGroupNode (com.bigdata.rdf.sparql.ast.JoinGroupNode)3 IVariable (com.bigdata.bop.IVariable)2 VarNode (com.bigdata.rdf.sparql.ast.VarNode)2 BigdataServiceCall (com.bigdata.rdf.sparql.ast.service.BigdataServiceCall)2 MalformedURLException (java.net.MalformedURLException)2 Test (org.junit.Test)2 URI (org.openrdf.model.URI)2 IVariableOrConstant (com.bigdata.bop.IVariableOrConstant)1 BigdataValueFactory (com.bigdata.rdf.model.BigdataValueFactory)1 DummyConstantNode (com.bigdata.rdf.sparql.ast.DummyConstantNode)1 GraphPatternGroup (com.bigdata.rdf.sparql.ast.GraphPatternGroup)1 IGroupMemberNode (com.bigdata.rdf.sparql.ast.IGroupMemberNode)1 TermNode (com.bigdata.rdf.sparql.ast.TermNode)1 AbstractServiceFactory (com.bigdata.rdf.sparql.ast.eval.AbstractServiceFactory)1 ServiceParams (com.bigdata.rdf.sparql.ast.eval.ServiceParams)1 BigdataNativeServiceOptions (com.bigdata.rdf.sparql.ast.service.BigdataNativeServiceOptions)1 IServiceOptions (com.bigdata.rdf.sparql.ast.service.IServiceOptions)1 ServiceCallCreateParams (com.bigdata.rdf.sparql.ast.service.ServiceCallCreateParams)1