Search in sources :

Example 1 with URI

use of org.openrdf.model.URI in project gocd by gocd.

the class SesameGraph method createURIReference.

public URIReference createURIReference(RDFType type, String uri) {
    ArgumentUtil.guaranteeNotNull(type, "Type may not be null.");
    ArgumentUtil.guaranteeNotNull(uri, "URI may not be null.");
    ArgumentUtil.guaranteeFalse("URI may not be a blank node!", uri.startsWith("_:"));
    URI sesameNativeURI = conn.getValueFactory().createURI(uri);
    try {
        conn.add(sesameNativeURI, RDF.TYPE, conn.getValueFactory().createURI(type.getURIText()), contextResource);
    } catch (RepositoryException e) {
        throw new ShineRuntimeException(e);
    }
    return new SesameURIReference(sesameNativeURI);
}
Also used : ShineRuntimeException(com.thoughtworks.studios.shine.ShineRuntimeException) RepositoryException(org.openrdf.repository.RepositoryException) URI(org.openrdf.model.URI)

Example 2 with URI

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

the class MongoDbSmartUriIT method testQuery.

@Test
public void testQuery() throws SmartUriException {
    smartUriConverter.storeEntity(BOB_ENTITY);
    // Look up Person Type Entities that match Bob's SSN property
    final Set<Property> properties = new LinkedHashSet<>();
    properties.add(BOB_ENTITY.lookupTypeProperty(PERSON_TYPE, HAS_SSN).get());
    final Map<URI, Value> map = SmartUriAdapter.propertiesToMap(properties);
    final ConvertingCursor<TypedEntity> cursor = smartUriConverter.queryEntity(PERSON_TYPE, map);
    int count = 0;
    while (cursor.hasNext()) {
        final TypedEntity typedEntity = cursor.next();
        System.out.println(typedEntity);
        count++;
    }
    assertEquals(count, 1);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) Value(org.openrdf.model.Value) Property(org.apache.rya.indexing.entity.model.Property) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) Test(org.junit.Test)

Example 3 with URI

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

the class MongoPcjIntegrationTest method testEvaluateTwoIndexValidate.

@Test
public void testEvaluateTwoIndexValidate() throws Exception {
    final Sail nonPcjSail = RyaSailFactory.getInstance(conf);
    final MongoDBRdfConfiguration pcjConf = conf.clone();
    pcjConf.setBoolean(ConfigUtils.USE_PCJ, true);
    final Sail pcjSail = RyaSailFactory.getInstance(pcjConf);
    final SailRepositoryConnection conn = new SailRepository(nonPcjSail).getConnection();
    final SailRepositoryConnection pcjConn = new SailRepository(pcjSail).getConnection();
    addPCJS(pcjConn);
    try {
        final URI superclass = new URIImpl("uri:superclass");
        final URI superclass2 = new URIImpl("uri:superclass2");
        conn.add(subclass, RDF.TYPE, superclass);
        conn.add(subclass2, RDF.TYPE, superclass2);
        conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
        conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
        final String indexSparqlString = // 
        "" + // 
        "SELECT ?dog ?pig ?duck  " + // 
        "{" + // 
        "  ?pig a ?dog . " + // 
        "  ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + // 
        "}";
        final String indexSparqlString2 = // 
        "" + // 
        "SELECT ?o ?f ?e ?c ?l  " + // 
        "{" + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?c a ?f . " + // 
        "}";
        final String queryString = // 
        "" + // 
        "SELECT ?e ?c ?l ?f ?o " + // 
        "{" + // 
        "  ?e a ?c . " + // 
        "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?c a ?f . " + // 
        "}";
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 1, conf.getRyaInstanceName(), indexSparqlString);
        final MongoPcjQueryNode ais1 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 1);
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 2, conf.getRyaInstanceName(), indexSparqlString2);
        final MongoPcjQueryNode ais2 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 2);
        final List<ExternalTupleSet> index = new ArrayList<>();
        index.add(ais1);
        index.add(ais2);
        ParsedQuery pq = null;
        final SPARQLParser sp = new SPARQLParser();
        pq = sp.parseQuery(queryString, null);
        final List<TupleExpr> teList = Lists.newArrayList();
        final TupleExpr te = pq.getTupleExpr();
        final PCJOptimizer pcj = new PCJOptimizer(index, false, new MongoPcjIndexSetProvider(new StatefulMongoDBRdfConfiguration(conf, getMongoClient())));
        pcj.optimize(te, null, null);
        teList.add(te);
        final IndexPlanValidator ipv = new IndexPlanValidator(false);
        assertTrue(ipv.isValid(te));
    } finally {
        conn.close();
        pcjConn.close();
        nonPcjSail.shutDown();
        pcjSail.shutDown();
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoPcjQueryNode(org.apache.rya.indexing.mongodb.pcj.MongoPcjQueryNode) SailRepository(org.openrdf.repository.sail.SailRepository) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) IndexPlanValidator(org.apache.rya.indexing.IndexPlanValidator.IndexPlanValidator) URIImpl(org.openrdf.model.impl.URIImpl) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) URI(org.openrdf.model.URI) TupleExpr(org.openrdf.query.algebra.TupleExpr) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Sail(org.openrdf.sail.Sail) MongoPcjIndexSetProvider(org.apache.rya.indexing.mongodb.pcj.MongoPcjIndexSetProvider) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) Test(org.junit.Test)

Example 4 with URI

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

the class MongoPcjIntegrationTest method testEvaluateThreeIndexValidate.

@Test
public void testEvaluateThreeIndexValidate() throws Exception {
    final Sail nonPcjSail = RyaSailFactory.getInstance(conf);
    final MongoDBRdfConfiguration pcjConf = conf.clone();
    pcjConf.setBoolean(ConfigUtils.USE_PCJ, true);
    final Sail pcjSail = RyaSailFactory.getInstance(pcjConf);
    final SailRepositoryConnection conn = new SailRepository(nonPcjSail).getConnection();
    final SailRepositoryConnection pcjConn = new SailRepository(pcjSail).getConnection();
    addPCJS(pcjConn);
    try {
        final URI superclass = new URIImpl("uri:superclass");
        final URI superclass2 = new URIImpl("uri:superclass2");
        final URI howlsAt = new URIImpl("uri:howlsAt");
        final URI subType = new URIImpl("uri:subType");
        final URI superSuperclass = new URIImpl("uri:super_superclass");
        conn.add(subclass, RDF.TYPE, superclass);
        conn.add(subclass2, RDF.TYPE, superclass2);
        conn.add(obj, RDFS.LABEL, new LiteralImpl("label"));
        conn.add(obj2, RDFS.LABEL, new LiteralImpl("label2"));
        conn.add(sub, howlsAt, superclass);
        conn.add(superclass, subType, superSuperclass);
        final String indexSparqlString = // 
        "" + // 
        "SELECT ?dog ?pig ?duck  " + // 
        "{" + // 
        "  ?pig a ?dog . " + // 
        "  ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + // 
        "}";
        final String indexSparqlString2 = // 
        "" + // 
        "SELECT ?o ?f ?e ?c ?l  " + // 
        "{" + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?c a ?f . " + // 
        "}";
        final String indexSparqlString3 = // 
        "" + // 
        "SELECT ?wolf ?sheep ?chicken  " + // 
        "{" + // 
        "  ?wolf <uri:howlsAt> ?sheep . " + // 
        "  ?sheep <uri:subType> ?chicken. " + // 
        "}";
        final String queryString = // 
        "" + // 
        "SELECT ?e ?c ?l ?f ?o " + // 
        "{" + // 
        "  ?e a ?c . " + // 
        "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "  ?o <http://www.w3.org/2000/01/rdf-schema#label> ?l. " + // 
        "  ?c a ?f . " + // 
        "  ?e <uri:howlsAt> ?f. " + // 
        "  ?f <uri:subType> ?o. " + // 
        "}";
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 1, conf.getRyaInstanceName(), indexSparqlString);
        final MongoPcjQueryNode ais1 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 1);
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 2, conf.getRyaInstanceName(), indexSparqlString2);
        final MongoPcjQueryNode ais2 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 2);
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 3, conf.getRyaInstanceName(), indexSparqlString3);
        final MongoPcjQueryNode ais3 = new MongoPcjQueryNode(conf, conf.getMongoDBName() + 3);
        final List<ExternalTupleSet> index = new ArrayList<>();
        index.add(ais1);
        index.add(ais3);
        index.add(ais2);
        ParsedQuery pq = null;
        final SPARQLParser sp = new SPARQLParser();
        pq = sp.parseQuery(queryString, null);
        final List<TupleExpr> teList = Lists.newArrayList();
        final TupleExpr te = pq.getTupleExpr();
        final PCJOptimizer pcj = new PCJOptimizer(index, false, new MongoPcjIndexSetProvider(new StatefulMongoDBRdfConfiguration(conf, getMongoClient())));
        pcj.optimize(te, null, null);
        teList.add(te);
        final IndexPlanValidator ipv = new IndexPlanValidator(false);
        assertTrue(ipv.isValid(te));
    } finally {
        conn.close();
        pcjConn.close();
        nonPcjSail.shutDown();
        pcjSail.shutDown();
    }
}
Also used : SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) MongoPcjQueryNode(org.apache.rya.indexing.mongodb.pcj.MongoPcjQueryNode) SailRepository(org.openrdf.repository.sail.SailRepository) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ArrayList(java.util.ArrayList) IndexPlanValidator(org.apache.rya.indexing.IndexPlanValidator.IndexPlanValidator) URIImpl(org.openrdf.model.impl.URIImpl) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) URI(org.openrdf.model.URI) TupleExpr(org.openrdf.query.algebra.TupleExpr) ExternalTupleSet(org.apache.rya.indexing.external.tupleSet.ExternalTupleSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) PCJOptimizer(org.apache.rya.indexing.pcj.matching.PCJOptimizer) Sail(org.openrdf.sail.Sail) MongoPcjIndexSetProvider(org.apache.rya.indexing.mongodb.pcj.MongoPcjIndexSetProvider) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) Test(org.junit.Test)

Example 5 with URI

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

the class AccumuloFreeTextIndexerTest method testContextSearch.

@Test
public void testContextSearch() throws Exception {
    try (AccumuloFreeTextIndexer f = new AccumuloFreeTextIndexer()) {
        f.setConf(conf);
        f.setMultiTableBatchWriter(ConfigUtils.createMultitableBatchWriter(conf));
        f.init();
        ValueFactory vf = new ValueFactoryImpl();
        URI subject = new URIImpl("foo:subj");
        URI predicate = new URIImpl(RDFS.COMMENT.toString());
        Value object = vf.createLiteral("this is a new hat");
        URI context = new URIImpl("foo:context");
        Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(RdfToRyaConversions.convertStatement(statement));
        f.flush();
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", new StatementConstraints().setContext(context))));
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("hat", new StatementConstraints().setContext(vf.createURI("foo:context2")))));
    }
}
Also used : StatementConstraints(org.apache.rya.indexing.StatementConstraints) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Value(org.openrdf.model.Value) URIImpl(org.openrdf.model.impl.URIImpl) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) Test(org.junit.Test)

Aggregations

URI (org.openrdf.model.URI)369 Test (org.junit.Test)138 Value (org.openrdf.model.Value)122 Resource (org.openrdf.model.Resource)110 Statement (org.openrdf.model.Statement)96 ValueFactory (org.openrdf.model.ValueFactory)83 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)67 URIImpl (org.openrdf.model.impl.URIImpl)58 HashSet (java.util.HashSet)36 RyaURI (org.apache.rya.api.domain.RyaURI)34 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)34 Literal (org.openrdf.model.Literal)34 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)34 StatementImpl (org.openrdf.model.impl.StatementImpl)32 LiteralImpl (org.openrdf.model.impl.LiteralImpl)29 Var (org.openrdf.query.algebra.Var)28 ArrayList (java.util.ArrayList)25 SailConnection (org.openrdf.sail.SailConnection)25 LinearRing (com.vividsolutions.jts.geom.LinearRing)24 Polygon (com.vividsolutions.jts.geom.Polygon)24