Search in sources :

Example 51 with URIImpl

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

the class SmartUriAdapter method createTypePropertiesUri.

private static URI createTypePropertiesUri(final ImmutableMap<RyaURI, ImmutableMap<RyaURI, Property>> typeProperties) throws SmartUriException {
    final List<NameValuePair> nameValuePairs = new ArrayList<>();
    for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> typeProperty : typeProperties.entrySet()) {
        final RyaURI type = typeProperty.getKey();
        final Map<RyaURI, Property> propertyMap = typeProperty.getValue();
        final URI typeUri = createIndividualTypeWithPropertiesUri(type, propertyMap);
        final String keyString = type.getDataType().getLocalName();
        final String valueString = typeUri.getLocalName();
        nameValuePairs.add(new BasicNameValuePair(keyString, valueString));
    }
    final URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.addParameters(nameValuePairs);
    String uriString;
    try {
        final java.net.URI uri = uriBuilder.build();
        final String queryString = uri.getRawSchemeSpecificPart();
        uriString = "urn:test" + queryString;
    } catch (final URISyntaxException e) {
        throw new SmartUriException("Unable to create type properties for the Smart URI", e);
    }
    return new URIImpl(uriString);
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) ArrayList(java.util.ArrayList) URIImpl(org.openrdf.model.impl.URIImpl) URISyntaxException(java.net.URISyntaxException) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) ImmutableMap(com.google.common.collect.ImmutableMap) URIBuilder(org.apache.http.client.utils.URIBuilder) RyaURI(org.apache.rya.api.domain.RyaURI) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Property(org.apache.rya.indexing.entity.model.Property)

Example 52 with URIImpl

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

the class SmartUriAdapter method removeTypePrefixFromUri.

private static String removeTypePrefixFromUri(final String uriString, final String typePrefix) {
    final String localName = new URIImpl(uriString).getLocalName();
    final String beginning = StringUtils.removeEnd(uriString, localName);
    final String replacement = localName.replaceFirst(typePrefix + ".", "");
    final String formattedUriString = beginning + replacement;
    return formattedUriString;
}
Also used : URIImpl(org.openrdf.model.impl.URIImpl)

Example 53 with URIImpl

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

the class SmartUriAdapter method createIndividualTypeWithPropertiesUri.

private static URI createIndividualTypeWithPropertiesUri(final RyaURI type, final Map<RyaURI, Property> map) throws SmartUriException {
    final List<NameValuePair> nameValuePairs = new ArrayList<>();
    for (final Entry<RyaURI, Property> entry : map.entrySet()) {
        final RyaURI key = entry.getKey();
        final Property property = entry.getValue();
        final RyaType ryaType = property.getValue();
        final String keyString = (new URIImpl(key.getData())).getLocalName();
        final Value value = RyaToRdfConversions.convertValue(ryaType);
        final String valueString = value.stringValue();
        nameValuePairs.add(new BasicNameValuePair(keyString, valueString));
    }
    final URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.addParameters(nameValuePairs);
    String uriString;
    try {
        final java.net.URI uri = uriBuilder.build();
        final String queryString = uri.getRawSchemeSpecificPart();
        uriString = type.getData() + /*new URIImpl(type.getData()).getLocalName()*/
        queryString;
    } catch (final URISyntaxException e) {
        throw new SmartUriException("Unable to create type URI with all its properties for the Smart URI", e);
    }
    return new URIImpl(uriString);
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) ArrayList(java.util.ArrayList) URIImpl(org.openrdf.model.impl.URIImpl) URISyntaxException(java.net.URISyntaxException) RyaType(org.apache.rya.api.domain.RyaType) URIBuilder(org.apache.http.client.utils.URIBuilder) RyaURI(org.apache.rya.api.domain.RyaURI) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) Value(org.openrdf.model.Value) Property(org.apache.rya.indexing.entity.model.Property)

Example 54 with URIImpl

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

the class AccumuloPcjSerializerTest method basicShortMixLiteralBsTest.

@Test
public void basicShortMixLiteralBsTest() throws BindingSetConversionException {
    final QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("X", new LiteralImpl("literal1"));
    bs.addBinding("Y", new LiteralImpl("5", new URIImpl("http://www.w3.org/2001/XMLSchema#integer")));
    final VariableOrder varOrder = new VariableOrder("X", "Y");
    BindingSetConverter<byte[]> converter = new AccumuloPcjSerializer();
    final byte[] byteVal = converter.convert(bs, varOrder);
    final BindingSet newBs = converter.convert(byteVal, varOrder);
    assertEquals(bs, newBs);
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) MapBindingSet(org.openrdf.query.impl.MapBindingSet) AccumuloPcjSerializer(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjSerializer) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) URIImpl(org.openrdf.model.impl.URIImpl) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

Example 55 with URIImpl

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

the class AccumuloPcjSerializerTest method basicShortUriBsTest.

@Test
public void basicShortUriBsTest() throws BindingSetConversionException {
    final QueryBindingSet bs = new QueryBindingSet();
    bs.addBinding("X", new URIImpl("http://uri1"));
    bs.addBinding("Y", new URIImpl("http://uri2"));
    final VariableOrder varOrder = new VariableOrder("X", "Y");
    BindingSetConverter<byte[]> converter = new AccumuloPcjSerializer();
    final byte[] byteVal = converter.convert(bs, varOrder);
    final BindingSet newBs = converter.convert(byteVal, varOrder);
    assertEquals(bs, newBs);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) MapBindingSet(org.openrdf.query.impl.MapBindingSet) AccumuloPcjSerializer(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjSerializer) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) URIImpl(org.openrdf.model.impl.URIImpl) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) Test(org.junit.Test)

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