Search in sources :

Example 1 with TermNode

use of com.bigdata.rdf.sparql.ast.TermNode in project wikidata-query-rdf by wikimedia.

the class GeoService method getRequiredBound.

@Override
public Set<IVariable<?>> getRequiredBound(final ServiceNode serviceNode) {
    /**
     * This method extracts exactly those variables that are incoming,
     * i.e. must be bound before executing the execution of the service.
     *
     * Those can be only in service parameters.
     */
    final Set<IVariable<?>> requiredBound = new HashSet<>();
    for (StatementPatternNode sp : getStatementPatterns(serviceNode)) {
        final TermNode subj = sp.s();
        final IVariableOrConstant<?> object = sp.o().getValueExpression();
        if (subj.isConstant() && BD.SERVICE_PARAM.equals(subj.getValue()) && object instanceof IVariable<?>) {
            // the subject var is what we return
            requiredBound.add((IVariable<?>) object);
        }
    }
    return requiredBound;
}
Also used : IVariable(com.bigdata.bop.IVariable) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) TermNode(com.bigdata.rdf.sparql.ast.TermNode) HashSet(java.util.HashSet)

Example 2 with TermNode

use of com.bigdata.rdf.sparql.ast.TermNode 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;
}
Also used : IGroupMemberNode(com.bigdata.rdf.sparql.ast.IGroupMemberNode) ServiceParams(com.bigdata.rdf.sparql.ast.eval.ServiceParams) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) TermNode(com.bigdata.rdf.sparql.ast.TermNode) URI(org.openrdf.model.URI)

Example 3 with TermNode

use of com.bigdata.rdf.sparql.ast.TermNode in project wikidata-query-rdf by wikimedia.

the class MWApiServiceFactory method getLimitsFromParams.

/**
 * Get limit configuration from service node params.
 * @return Limits object/tracker
 */
MWApiLimits getLimitsFromParams(final ServiceParams serviceParams) {
    int limitResults = -1;
    int limitContinuations = getSettingFromParams(serviceParams, LIMIT_CONTINUATIONS_KEY, -1);
    int limitEmptyContinuations = getSettingFromParams(serviceParams, LIMIT_EMPTY_CONTINUATIONS_KEY, 25);
    TermNode limitResultsNode = serviceParams.get(LIMIT_RESULTS_KEY, null);
    if (limitResultsNode != null) {
        serviceParams.clear(LIMIT_RESULTS_KEY);
        String s = limitResultsNode.getValue().stringValue();
        if (s.equals("once")) {
            // backwards compatibility, there used to be just one limit
            limitContinuations = 0;
        } else {
            limitResults = Integer.parseInt(s);
        }
    }
    return clampLimitsByConfig(limitResults, limitContinuations, limitEmptyContinuations);
}
Also used : TermNode(com.bigdata.rdf.sparql.ast.TermNode)

Example 4 with TermNode

use of com.bigdata.rdf.sparql.ast.TermNode in project wikidata-query-rdf by wikimedia.

the class GeoAroundService method buildServiceNode.

@Override
protected JoinGroupNode buildServiceNode(ServiceCallCreateParams params, ServiceParams serviceParams) {
    final AbstractTripleStore store = params.getTripleStore();
    final Vocabulary voc = store.getVocabulary();
    BigdataValueFactory vf = store.getValueFactory();
    final StatementPatternNode pattern = getPatternNode(params);
    final TermNode searchVar = pattern.s();
    final TermNode predicate = pattern.p();
    final TermNode locationVar = pattern.o();
    final JoinGroupNode newGroup = new JoinGroupNode();
    // ?var geo:search "inCircle" .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SEARCH)), new DummyConstantNode(vf.createLiteral(GeoFunction.IN_CIRCLE.toString()))));
    // ?var geo:predicate wdt:P625 .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.PREDICATE)), predicate));
    // ?var geo:searchDatatype ogc:wktLiteral .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SEARCH_DATATYPE)), new ConstantNode(voc.getConstant(new URIImpl(GeoSparql.WKT_LITERAL)))));
    // ?var geo:spatialCircleCenter ?parisLoc .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SPATIAL_CIRCLE_CENTER)), getParam(serviceParams, CENTER_PARAM)));
    // ?var geo:spatialCircleRadius "1" .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.SPATIAL_CIRCLE_RADIUS)), getParam(serviceParams, RADIUS_PARAM)));
    // ?var geo:locationValue ?location .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.LOCATION_VALUE)), locationVar));
    // ?var geo:coordSystem "0" .
    newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.COORD_SYSTEM)), getGlobeNode(vf, serviceParams)));
    final TermNode distance = serviceParams.get(DISTANCE_PARAM, null);
    if (distance != null) {
        // ?var geo:distanceValue ?distance .
        newGroup.addArg(new StatementPatternNode(searchVar, new DummyConstantNode(vf.asValue(GeoSpatial.DISTANCE_VALUE)), distance));
    }
    return newGroup;
}
Also used : Vocabulary(com.bigdata.rdf.vocab.Vocabulary) AbstractTripleStore(com.bigdata.rdf.store.AbstractTripleStore) BigdataValueFactory(com.bigdata.rdf.model.BigdataValueFactory) ConstantNode(com.bigdata.rdf.sparql.ast.ConstantNode) DummyConstantNode(com.bigdata.rdf.sparql.ast.DummyConstantNode) DummyConstantNode(com.bigdata.rdf.sparql.ast.DummyConstantNode) JoinGroupNode(com.bigdata.rdf.sparql.ast.JoinGroupNode) URIImpl(org.openrdf.model.impl.URIImpl) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode) TermNode(com.bigdata.rdf.sparql.ast.TermNode)

Example 5 with TermNode

use of com.bigdata.rdf.sparql.ast.TermNode in project wikidata-query-rdf by wikimedia.

the class MWApiServiceFactory method getServiceHost.

/**
 * Get service host and check if it's valid.
 * @return Service endpoint.
 * @throws MalformedURLException on bad URL
 */
private Endpoint getServiceHost(final ServiceParams serviceParams) throws MalformedURLException {
    TermNode hostNode = serviceParams.get(ENDPOINT_KEY, null);
    requireNonNull(hostNode, "Service name (wikibase:endpoint) should be supplied");
    serviceParams.clear(ENDPOINT_KEY);
    return Endpoint.create(hostNode.getValueExpression(), config);
}
Also used : TermNode(com.bigdata.rdf.sparql.ast.TermNode)

Aggregations

TermNode (com.bigdata.rdf.sparql.ast.TermNode)8 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)4 DummyConstantNode (com.bigdata.rdf.sparql.ast.DummyConstantNode)3 BigdataValue (com.bigdata.rdf.model.BigdataValue)2 BigdataValueFactory (com.bigdata.rdf.model.BigdataValueFactory)2 ConstantNode (com.bigdata.rdf.sparql.ast.ConstantNode)2 JoinGroupNode (com.bigdata.rdf.sparql.ast.JoinGroupNode)2 AbstractTripleStore (com.bigdata.rdf.store.AbstractTripleStore)2 Vocabulary (com.bigdata.rdf.vocab.Vocabulary)2 URIImpl (org.openrdf.model.impl.URIImpl)2 IVariable (com.bigdata.bop.IVariable)1 BigdataURI (com.bigdata.rdf.model.BigdataURI)1 IGroupMemberNode (com.bigdata.rdf.sparql.ast.IGroupMemberNode)1 ServiceParams (com.bigdata.rdf.sparql.ast.eval.ServiceParams)1 GeoSpatialSearchException (com.bigdata.service.geospatial.GeoSpatialSearchException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Literal (org.openrdf.model.Literal)1 URI (org.openrdf.model.URI)1 Value (org.openrdf.model.Value)1