Search in sources :

Example 76 with URIImpl

use of org.openrdf.model.impl.URIImpl in project wikidata-query-rdf by wikimedia.

the class WikibaseCornerBOp method get.

@Override
public IV get(IBindingSet bindingSet) {
    final IV east = getAndCheckLiteral(0, bindingSet);
    final IV west = getAndCheckLiteral(1, bindingSet);
    final GeoUtils.Box box = new GeoUtils.Box(pointFromIV(east), pointFromIV(west));
    WikibasePoint wp;
    if (corner() == Corners.NE) {
        if (!box.switched()) {
            return east;
        }
        wp = box.northEast();
    } else {
        if (!box.switched()) {
            return west;
        }
        wp = box.southWest();
    }
    final BigdataLiteral newpoint = getValueFactory().createLiteral(wp.toString(), new URIImpl(GeoSparql.WKT_LITERAL));
    return super.asIV(newpoint, bindingSet);
}
Also used : GeoUtils(org.wikidata.query.rdf.blazegraph.geo.GeoUtils) URIImpl(org.openrdf.model.impl.URIImpl) IV(com.bigdata.rdf.internal.IV) GeoUtils.pointFromIV(org.wikidata.query.rdf.blazegraph.geo.GeoUtils.pointFromIV) BigdataLiteral(com.bigdata.rdf.model.BigdataLiteral) WikibasePoint(org.wikidata.query.rdf.common.WikibasePoint)

Example 77 with URIImpl

use of org.openrdf.model.impl.URIImpl 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 78 with URIImpl

use of org.openrdf.model.impl.URIImpl in project wikidata-query-rdf by wikimedia.

the class NormalizingRdfHandlerUnitTest method testHandleStatement.

private void testHandleStatement(String suffix) throws RDFHandlerException {
    StatementChecker checkStatement = new StatementChecker();
    NormalizingRdfHandler handler = new NormalizingRdfHandler(checkStatement);
    String testStr = "http://wikiba.se/ontology-" + suffix + "#Test";
    Statement s = statement(testStr, RDF.TYPE, Ontology.ITEM);
    Statement p = statement("Q1", testStr, Ontology.ITEM);
    Statement o = statement("Q1", RDF.TYPE, new URIImpl(testStr));
    Statement o2 = statement("Q1", RDF.TYPE, new LiteralImpl(testStr));
    checkStatement.expect("http://wikiba.se/ontology#Test", null, null);
    handler.handleStatement(s);
    checkStatement.expect(null, "http://wikiba.se/ontology#Test", null);
    handler.handleStatement(p);
    checkStatement.expect(null, null, "http://wikiba.se/ontology#Test");
    handler.handleStatement(o);
    checkStatement.expect(null, null, testStr);
    handler.handleStatement(o2);
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) Statement(org.openrdf.model.Statement) URIImpl(org.openrdf.model.impl.URIImpl)

Example 79 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class RyaStatementSerializer method read.

/**
 * Reads RyaStatement from {@link Input} stream
 * @param input - input stream that statement is read from
 * @return - statement read from input stream
 */
public static RyaStatement read(Input input) {
    Preconditions.checkNotNull(input);
    String subject = input.readString();
    String predicate = input.readString();
    String objectType = input.readString();
    String objectValue = input.readString();
    RyaType value;
    if (objectType.equals(XMLSchema.ANYURI.toString())) {
        value = new RyaURI(objectValue);
    } else {
        value = new RyaType(new URIImpl(objectType), objectValue);
    }
    RyaStatement statement = new RyaStatement(new RyaURI(subject), new RyaURI(predicate), value);
    int length = 0;
    boolean hasNextValue = input.readBoolean();
    if (hasNextValue) {
        statement.setContext(new RyaURI(input.readString()));
    }
    hasNextValue = input.readBoolean();
    if (hasNextValue) {
        length = input.readInt();
        statement.setColumnVisibility(input.readBytes(length));
    }
    hasNextValue = input.readBoolean();
    if (hasNextValue) {
        statement.setQualifer(input.readString());
    }
    hasNextValue = input.readBoolean();
    if (hasNextValue) {
        statement.setTimestamp(input.readLong());
    }
    hasNextValue = input.readBoolean();
    if (hasNextValue) {
        length = input.readInt();
        statement.setValue(input.readBytes(length));
    }
    return statement;
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType)

Example 80 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class FluoStringConverter method toVar.

/**
 * Converts the String representation of a {@link Var} back into the object version.
 *
 * @param varString - The {@link Var} represented as a String. (not null)
 * @return A {@link Var} built from the string.
 */
public static Var toVar(final String varString) {
    checkNotNull(varString);
    final String[] varParts = varString.split(TYPE_DELIM);
    final String name = varParts[0];
    // The variable is a constant value.
    if (varParts.length > 1) {
        final String dataTypeString = varParts[1];
        if (dataTypeString.equals(URI_TYPE)) {
            // Handle a URI object.
            Preconditions.checkArgument(varParts.length == 2);
            final String valueString = name.substring("-const-".length());
            final Var var = new Var(name, new URIImpl(valueString));
            var.setConstant(true);
            return var;
        } else if (dataTypeString.equals(RyaSchema.BNODE_NAMESPACE)) {
            // Handle a BNode object
            Preconditions.checkArgument(varParts.length == 3);
            Var var = new Var(name);
            var.setValue(new BNodeImpl(varParts[2]));
            return var;
        } else {
            // Handle a Literal Value.
            Preconditions.checkArgument(varParts.length == 2);
            final String valueString = name.substring("-const-".length());
            final URI dataType = new URIImpl(dataTypeString);
            final Literal value = new LiteralImpl(valueString, dataType);
            final Var var = new Var(name, value);
            var.setConstant(true);
            return var;
        }
    } else {
        // The variable is a named variable.
        return new Var(varString);
    }
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) Var(org.openrdf.query.algebra.Var) Literal(org.openrdf.model.Literal) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) BNodeImpl(org.openrdf.model.impl.BNodeImpl)

Aggregations

URIImpl (org.openrdf.model.impl.URIImpl)170 Test (org.junit.Test)120 LiteralImpl (org.openrdf.model.impl.LiteralImpl)62 URI (org.openrdf.model.URI)58 BindingSet (org.openrdf.query.BindingSet)50 MapBindingSet (org.openrdf.query.impl.MapBindingSet)36 RyaURI (org.apache.rya.api.domain.RyaURI)33 HashSet (java.util.HashSet)31 Statement (org.openrdf.model.Statement)30 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)30 ArrayList (java.util.ArrayList)29 RyaType (org.apache.rya.api.domain.RyaType)25 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)24 RyaStatement (org.apache.rya.api.domain.RyaStatement)23 Value (org.openrdf.model.Value)22 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)22 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)21 StatementPattern (org.openrdf.query.algebra.StatementPattern)20 StatementImpl (org.openrdf.model.impl.StatementImpl)19 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)16