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);
}
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;
}
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);
}
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;
}
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);
}
}
Aggregations