use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.
the class T213375_UnitTest method test_value_inlining.
@SuppressWarnings("rawtypes")
@Test
public void test_value_inlining() {
// Prepare value URI
String value = "http://www.wikidata.org/value/";
String id = "0123456789abcdef0123456789abcdef01234567";
String uri = value + id;
// Pass URI to the journal for inlining
IV<?, ?> iv = this.store.addTerm(new URIImpl(uri));
// Test IV type
assertEquals(URIExtensionIV.class, iv.getClass());
// Test prefix is inlined as vocabulary IV
IV extensionIV = ((URIExtensionIV) iv).getExtensionIV();
assertEquals(VocabURIByteIV.class, extensionIV.getClass());
// Test prefix encoded correctly in lexicon
assertEquals(value, extensionIV.asValue(this.store.getLexiconRelation()).stringValue());
// Test local name is xsd:integer
assertEquals(XSDIntegerIV.class, ((URIExtensionIV) iv).getLocalNameIV().getClass());
// Test local name is encoded as hex BigInteger
assertEquals(new BigInteger(id, 16), ((URIExtensionIV) iv).getLocalNameIV().integerValue());
// Test string representation of the IV matches to reference URI
assertEquals(uri, iv.asValue(this.store.getLexiconRelation()).stringValue());
}
use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.
the class AbstractMultiTypeExtension method resolveDataType.
/**
* Convert the literal into a uri as resolved by the resolve this extension
* received on construction.
*/
@SuppressWarnings("rawtypes")
protected BigdataURI resolveDataType(LiteralExtensionIV literal) {
IV extensionIV = literal.getExtensionIV();
BigdataURI dt = dataTypes.get(extensionIV);
if (dt == null) {
throw new IllegalArgumentException("Unrecognized datatype: " + extensionIV);
}
return dt;
}
use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.
the class IsSomeValueFunctionFactory method create.
@Override
public IValueExpression<? extends IV> create(BOpContextBase context, GlobalAnnotations globals, Map<String, Object> map, ValueExpressionNode... args) {
FunctionRegistry.checkArgs(args, ValueExpressionNode.class);
IValueExpression<? extends IV> ve = AST2BOpUtility.toVE(context, globals, args[0]);
if (mode == SomeValueMode.Blank) {
return new IsBNodeBOp(ve);
} else {
String namespace = globals.lex;
long timestamp = globals.timestamp;
LexiconRelation lex = (LexiconRelation) context.getResource(namespace, timestamp);
IV vocabPrefix = lex.getContainer().getVocabulary().get(lex.getValueFactory().createURI(skolemURIPrefix));
if (vocabPrefix == null) {
throw new IllegalStateException("[" + skolemURIPrefix + "] must be part of the vocabulary");
}
return new InlineVocabEqBOp(new BOp[] { ve }, vocabPrefix);
}
}
use of com.bigdata.rdf.internal.IV in project wikidata-query-rdf by wikimedia.
the class MWApiServiceCall method getRequestParams.
/**
* Get parameter string from binding.
*/
public Map<String, String> getRequestParams(IBindingSet binding) {
// Add fixed params
final Map<String, String> params = new HashMap<>(template.getFixedParams());
// Resolve variable params
for (Map.Entry<String, IVariableOrConstant> term : inputVars.entrySet()) {
String value;
IV boundValue = null;
if (term.getValue() != null) {
boundValue = (IV) term.getValue().get(binding);
}
if (boundValue == null) {
// try default
value = template.getInputDefault(term.getKey());
if (value != null && value.isEmpty()) {
// Empty default means omit if not supplied, and it's ok
continue;
}
} else {
value = boundValue.stringValue();
}
if (value == null) {
if (template.isRequiredParameter(term.getKey())) {
throw new IllegalArgumentException("Could not find binding for parameter " + term.getKey());
} else {
continue;
}
}
params.put(term.getKey(), value);
}
return params;
}
use of com.bigdata.rdf.internal.IV 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);
}
Aggregations