Search in sources :

Example 21 with URI

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

the class MongoFreeTextIndexerIT method testSearch.

@Test
public void testSearch() throws Exception {
    try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
        f.setConf(conf);
        f.init();
        final ValueFactory vf = new ValueFactoryImpl();
        final URI subject = new URIImpl("foo:subj");
        final URI predicate = RDFS.LABEL;
        final Value object = vf.createLiteral("this is a new hat");
        final URI context = new URIImpl("foo:context");
        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(RdfToRyaConversions.convertStatement(statement));
        f.flush();
        assertEquals(Sets.newHashSet(), getSet(f.queryText("asdf", EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(statement), getSet(f.queryText("new", EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat new", EMPTY_CONSTRAINTS)));
    }
}
Also used : 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) RyaURI(org.apache.rya.api.domain.RyaURI) URI(org.openrdf.model.URI) MongoFreeTextIndexer(org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer) Test(org.junit.Test)

Example 22 with URI

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

the class MongoFreeTextIndexerIT method testContextSearch.

@Test
public void testContextSearch() throws Exception {
    try (MongoFreeTextIndexer f = new MongoFreeTextIndexer()) {
        f.setConf(conf);
        f.init();
        final ValueFactory vf = new ValueFactoryImpl();
        final URI subject = new URIImpl("foo:subj");
        final URI predicate = new URIImpl(RDFS.COMMENT.toString());
        final Value object = vf.createLiteral("this is a new hat");
        final URI context = new URIImpl("foo:context");
        final Statement statement = vf.createStatement(subject, predicate, object, context);
        f.storeStatement(RdfToRyaConversions.convertStatement(statement));
        f.flush();
        assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", new StatementConstraints().setContext(context))));
        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) RyaURI(org.apache.rya.api.domain.RyaURI) URI(org.openrdf.model.URI) MongoFreeTextIndexer(org.apache.rya.indexing.mongodb.freetext.MongoFreeTextIndexer) Test(org.junit.Test)

Example 23 with URI

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

the class RyaDirectExample method testAddAndFreeTextSearchWithPCJ.

private static void testAddAndFreeTextSearchWithPCJ(final SailRepositoryConnection conn) throws Exception {
    // add data to the repository using the SailRepository add methods
    final ValueFactory f = conn.getValueFactory();
    final URI person = f.createURI("http://example.org/ontology/Person");
    String uuid;
    uuid = "urn:people:alice";
    conn.add(f.createURI(uuid), RDF.TYPE, person);
    conn.add(f.createURI(uuid), RDFS.LABEL, f.createLiteral("Alice Palace Hose", f.createURI("xsd:string")));
    uuid = "urn:people:bobss";
    conn.add(f.createURI(uuid), RDF.TYPE, person);
    conn.add(f.createURI(uuid), RDFS.LABEL, f.createLiteral("Bob Snob Hose", "en"));
    String queryString;
    TupleQuery tupleQuery;
    CountingResultHandler tupleHandler;
    // ///////////// search for alice
    queryString = // 
    "PREFIX fts: <http://rdf.useekm.com/fts#>  " + // 
    "SELECT ?person ?match ?e ?c ?l ?o " + // 
    "{" + // 
    "  ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . " + // 
    "  FILTER(fts:text(?match, \"pal*\")) " + // 
    "}";
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    tupleHandler = new CountingResultHandler();
    tupleQuery.evaluate(tupleHandler);
    log.info("Result count : " + tupleHandler.getCount());
    Validate.isTrue(tupleHandler.getCount() == 1);
    // ///////////// search for alice and bob
    queryString = // 
    "PREFIX fts: <http://rdf.useekm.com/fts#>  " + // 
    "SELECT ?person ?match " + // 
    "{" + // 
    "  ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . " + // 
    "  ?person a <http://example.org/ontology/Person> . " + // 
    "  FILTER(fts:text(?match, \"(alice | bob) *SE\")) " + // 
    "}";
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    tupleHandler = new CountingResultHandler();
    tupleQuery.evaluate(tupleHandler);
    log.info("Result count : " + tupleHandler.getCount());
    Validate.isTrue(tupleHandler.getCount() == 2);
    // ///////////// search for alice and bob
    queryString = // 
    "PREFIX fts: <http://rdf.useekm.com/fts#>  " + // 
    "SELECT ?person ?match " + // 
    "{" + // 
    "  ?person a <http://example.org/ontology/Person> . " + // 
    "  ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . " + // 
    "  FILTER(fts:text(?match, \"(alice | bob) *SE\")) " + // 
    "  FILTER(fts:text(?match, \"pal*\")) " + // 
    "}";
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    tupleHandler = new CountingResultHandler();
    tupleQuery.evaluate(tupleHandler);
    log.info("Result count : " + tupleHandler.getCount());
    Validate.isTrue(tupleHandler.getCount() == 1);
    // ///////////// search for bob
    queryString = // 
    "PREFIX fts: <http://rdf.useekm.com/fts#>  " + // 
    "SELECT ?person ?match ?e ?c ?l ?o " + // 
    "{" + // 
    "  ?e a ?c . " + // 
    "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + // 
    "  ?e <uri:talksTo> ?o . " + // 
    "  ?person a <http://example.org/ontology/Person> . " + // 
    "  ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . " + // 
    "  FILTER(fts:text(?match, \"!alice & hose\")) " + // 
    "}";
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    tupleHandler = new CountingResultHandler();
    tupleQuery.evaluate(tupleHandler);
    log.info("Result count : " + tupleHandler.getCount());
    Validate.isTrue(tupleHandler.getCount() == 1);
}
Also used : TupleQuery(org.openrdf.query.TupleQuery) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI)

Example 24 with URI

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

the class RyaDirectExample method createPCJ.

// private static void testDeleteGeoData(final SailRepositoryConnection conn)
// throws Exception {
// // Delete all stored points
// final String sparqlDelete = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>  "//
// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>  "//
// + "DELETE {\n" //
// + "  ?feature a geo:Feature . "//
// + "  ?feature geo:hasGeometry ?point . "//
// + "  ?point a geo:Point . "//
// + "  ?point geo:asWKT ?wkt . "//
// + "}\n" + "WHERE { \n" + "  ?feature a geo:Feature . "//
// + "  ?feature geo:hasGeometry ?point . "//
// + "  ?point a geo:Point . "//
// + "  ?point geo:asWKT ?wkt . "//
// + "}";//
// 
// final Update deleteUpdate = conn.prepareUpdate(QueryLanguage.SPARQL,
// sparqlDelete);
// deleteUpdate.execute();
// 
// String queryString;
// TupleQuery tupleQuery;
// CountingResultHandler tupleHandler;
// 
// // Find all stored points
// queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>  "//
// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>  "//
// + "SELECT ?feature ?point ?wkt " //
// + "{" //
// + "  ?feature a geo:Feature . "//
// + "  ?feature geo:hasGeometry ?point . "//
// + "  ?point a geo:Point . "//
// + "  ?point geo:asWKT ?wkt . "//
// + "}";//
// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
// tupleHandler = new CountingResultHandler();
// tupleQuery.evaluate(tupleHandler);
// log.info("Result count : " + tupleHandler.getCount());
// Validate.isTrue(tupleHandler.getCount() == 0);
// }
private static void createPCJ(final Configuration conf) throws RepositoryException, AccumuloException, AccumuloSecurityException, TableExistsException, PcjException, InferenceEngineException, NumberFormatException, UnknownHostException, SailException, TableNotFoundException {
    final Configuration config = new AccumuloRdfConfiguration(conf);
    config.set(ConfigUtils.USE_PCJ, "false");
    SailRepository repository = null;
    SailRepositoryConnection conn = null;
    try {
        final Sail extSail = RyaSailFactory.getInstance(config);
        repository = new SailRepository(extSail);
        conn = repository.getConnection();
        final String queryString1 = // 
        "" + // 
        "SELECT ?e ?c ?l ?o " + // 
        "{" + // 
        "  ?c a ?e . " + // 
        "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "}";
        final String queryString2 = // 
        "" + // 
        "SELECT ?e ?c ?l ?o " + // 
        "{" + // 
        "  ?e a ?c . " + // 
        "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + // 
        "  ?e <uri:talksTo> ?o . " + // 
        "}";
        URI obj, subclass, talksTo;
        final URI person = new URIImpl("urn:people:alice");
        final URI feature = new URIImpl("urn:feature");
        final URI sub = new URIImpl("uri:entity");
        subclass = new URIImpl("uri:class");
        obj = new URIImpl("uri:obj");
        talksTo = new URIImpl("uri:talksTo");
        conn.add(person, RDF.TYPE, sub);
        conn.add(feature, RDF.TYPE, sub);
        conn.add(sub, RDF.TYPE, subclass);
        conn.add(sub, RDFS.LABEL, new LiteralImpl("label"));
        conn.add(sub, talksTo, obj);
        final String tablename1 = RYA_TABLE_PREFIX + "INDEX_1";
        final String tablename2 = RYA_TABLE_PREFIX + "INDEX_2";
        final Connector accCon = new MockInstance(INSTANCE).getConnector("root", new PasswordToken("".getBytes(StandardCharsets.UTF_8)));
        new PcjTables().createAndPopulatePcj(conn, accCon, tablename1, queryString1, new String[] { "e", "c", "l", "o" }, Optional.<PcjVarOrderFactory>absent());
        new PcjTables().createAndPopulatePcj(conn, accCon, tablename2, queryString2, new String[] { "e", "c", "l", "o" }, Optional.<PcjVarOrderFactory>absent());
    } catch (final RyaDAOException e) {
        throw new Error("While creating PCJ tables.", e);
    } finally {
        closeQuietly(conn);
        closeQuietly(repository);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Configuration(org.apache.hadoop.conf.Configuration) AccumuloIndexingConfiguration(org.apache.rya.indexing.accumulo.AccumuloIndexingConfiguration) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) SailRepository(org.openrdf.repository.sail.SailRepository) URIImpl(org.openrdf.model.impl.URIImpl) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) URI(org.openrdf.model.URI) LiteralImpl(org.openrdf.model.impl.LiteralImpl) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) Sail(org.openrdf.sail.Sail) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) PcjTables(org.apache.rya.indexing.pcj.storage.accumulo.PcjTables)

Example 25 with URI

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

the class LocalReasoner method relevantJoinRule.

/**
 * Determine whether a fact is a triple which might be used in some join
 * rule for its subject and/or object.
 */
public static Relevance relevantJoinRule(Fact fact, Schema schema) {
    // contained in the schema object.
    if (Schema.isSchemaTriple(fact.getTriple())) {
        return Relevance.NONE;
    }
    // Otherwise, consider the semantics of the statement:
    URI predURI = fact.getPredicate();
    Value object = fact.getObject();
    boolean relevantToSubject = false;
    boolean relevantToObject = false;
    // Literals don't get reasoners, so determine whether object is a uri:
    boolean literalObject = object instanceof Literal;
    // Type statements can be joined if...
    if (predURI.equals(RDF.TYPE)) {
        Resource typeURI = (Resource) fact.getObject();
        if (schema.hasClass(typeURI)) {
            OwlClass c = schema.getClass(typeURI);
            // 1. the type is a property restriction
            if (!c.getOnProperty().isEmpty() || // 2. the type is relevant to a property restriction
            !c.getSvfRestrictions().isEmpty() || !c.getAvfRestrictions().isEmpty() || !c.getQCRestrictions().isEmpty() || // 3. the type has complementary/disjoint types
            !c.getDisjointClasses().isEmpty() || !c.getComplementaryClasses().isEmpty()) {
                relevantToSubject = true;
            }
        }
    }
    // If the schema knows about the property:
    if (schema.hasProperty(predURI)) {
        OwlProperty prop = schema.getProperty(predURI);
        // transitivity: relevant to both
        if (prop.isTransitive()) {
            relevantToSubject = true;
            relevantToObject = !literalObject;
        } else {
            // disjoint properties: relevant to subject
            if (!prop.getDisjointProperties().isEmpty()) {
                relevantToSubject = true;
            }
            // Property restrictions: possibly relevant to either
            for (Resource rURI : prop.getRestrictions()) {
                OwlClass r = schema.getClass(rURI);
                // (if <subject type rURI>, infer object's type)
                if (!r.allValuesFrom().isEmpty()) {
                    relevantToSubject = true;
                }
                // max cardinality requires a join on the subject
                if (!literalObject && (r.getMaxCardinality() >= 0 || r.getMaxQualifiedCardinality() >= 0 || !r.someValuesFrom().isEmpty())) {
                    relevantToObject = true;
                }
                if (relevantToSubject && (relevantToObject || literalObject)) {
                    break;
                }
            }
        }
    }
    return Relevance.get(relevantToSubject, relevantToObject);
}
Also used : Literal(org.openrdf.model.Literal) Value(org.openrdf.model.Value) Resource(org.openrdf.model.Resource) URI(org.openrdf.model.URI)

Aggregations

URI (org.openrdf.model.URI)368 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