Search in sources :

Example 1 with IV

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());
}
Also used : URIExtensionIV(com.bigdata.rdf.internal.impl.uri.URIExtensionIV) BigInteger(java.math.BigInteger) URIImpl(org.openrdf.model.impl.URIImpl) IV(com.bigdata.rdf.internal.IV) XSDIntegerIV(com.bigdata.rdf.internal.impl.literal.XSDIntegerIV) VocabURIByteIV(com.bigdata.rdf.internal.impl.uri.VocabURIByteIV) URIExtensionIV(com.bigdata.rdf.internal.impl.uri.URIExtensionIV) Test(org.junit.Test)

Example 2 with IV

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;
}
Also used : IV(com.bigdata.rdf.internal.IV) AbstractLiteralIV(com.bigdata.rdf.internal.impl.literal.AbstractLiteralIV) LiteralExtensionIV(com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV) BigdataURI(com.bigdata.rdf.model.BigdataURI)

Example 3 with IV

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);
    }
}
Also used : IsBNodeBOp(com.bigdata.rdf.internal.constraints.IsBNodeBOp) IV(com.bigdata.rdf.internal.IV) LexiconRelation(com.bigdata.rdf.lexicon.LexiconRelation)

Example 4 with IV

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;
}
Also used : IVariableOrConstant(com.bigdata.bop.IVariableOrConstant) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) IV(com.bigdata.rdf.internal.IV)

Example 5 with IV

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

Aggregations

IV (com.bigdata.rdf.internal.IV)11 URIImpl (org.openrdf.model.impl.URIImpl)3 XSDIntegerIV (com.bigdata.rdf.internal.impl.literal.XSDIntegerIV)2 URIExtensionIV (com.bigdata.rdf.internal.impl.uri.URIExtensionIV)2 VocabURIByteIV (com.bigdata.rdf.internal.impl.uri.VocabURIByteIV)2 BigdataLiteral (com.bigdata.rdf.model.BigdataLiteral)2 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)2 BigInteger (java.math.BigInteger)2 Test (org.junit.Test)2 GeoUtils.pointFromIV (org.wikidata.query.rdf.blazegraph.geo.GeoUtils.pointFromIV)2 WikibasePoint (org.wikidata.query.rdf.common.WikibasePoint)2 IVariable (com.bigdata.bop.IVariable)1 IVariableOrConstant (com.bigdata.bop.IVariableOrConstant)1 IsBNodeBOp (com.bigdata.rdf.internal.constraints.IsBNodeBOp)1 CoordinateDD (com.bigdata.rdf.internal.gis.CoordinateDD)1 AbstractLiteralIV (com.bigdata.rdf.internal.impl.literal.AbstractLiteralIV)1 LiteralExtensionIV (com.bigdata.rdf.internal.impl.literal.LiteralExtensionIV)1 LexiconRelation (com.bigdata.rdf.lexicon.LexiconRelation)1 BigdataURI (com.bigdata.rdf.model.BigdataURI)1 BigdataValue (com.bigdata.rdf.model.BigdataValue)1