Search in sources :

Example 96 with URIImpl

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

the class AccumuloFreeTextIndexerTest method testSearch.

@Test
public void testSearch() 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 = RDFS.LABEL;
        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();
        printTables(conf);
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("asdf", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("this & !is", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("this", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("is", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("a", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("new", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("ha*", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("*at", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("hat & new", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryText("this & hat & new", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("bat", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("this & bat", 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) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) Test(org.junit.Test)

Example 97 with URIImpl

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

the class AccumuloFreeTextIndexerTest method testDelete.

@Test
public void testDelete() throws Exception {
    try (AccumuloFreeTextIndexer f = new AccumuloFreeTextIndexer()) {
        f.setConf(conf);
        f.setMultiTableBatchWriter(ConfigUtils.createMultitableBatchWriter(conf));
        f.init();
        ValueFactory vf = new ValueFactoryImpl();
        URI subject1 = new URIImpl("foo:subj");
        URI predicate1 = RDFS.LABEL;
        Value object1 = vf.createLiteral("this is a new hat");
        URI context1 = new URIImpl("foo:context");
        Statement statement1 = vf.createStatement(subject1, predicate1, object1, context1);
        f.storeStatement(RdfToRyaConversions.convertStatement(statement1));
        URI subject2 = new URIImpl("foo:subject");
        URI predicate2 = RDFS.LABEL;
        Value object2 = vf.createLiteral("Do you like my new hat?");
        URI context2 = new URIImpl("foo:context");
        Statement statement2 = vf.createStatement(subject2, predicate2, object2, context2);
        f.storeStatement(RdfToRyaConversions.convertStatement(statement2));
        f.flush();
        System.out.println("testDelete: BEFORE DELETE");
        printTables(conf);
        f.deleteStatement(RdfToRyaConversions.convertStatement(statement1));
        System.out.println("testDelete: AFTER FIRST DELETION");
        printTables(conf);
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("this is a new hat", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement2), getSet(f.queryText("Do you like my new hat?", EMPTY_CONSTRAINTS)));
        // Check that "new" didn't get deleted from the term table after "this is a new hat"
        // was deleted since "new" is still in "Do you like my new hat?"
        Assert.assertEquals(Sets.newHashSet(statement2), getSet(f.queryText("new", EMPTY_CONSTRAINTS)));
        f.deleteStatement(RdfToRyaConversions.convertStatement(statement2));
        System.out.println("testDelete: AFTER LAST DELETION");
        printTables(conf);
        System.out.println("testDelete: DONE");
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("this is a new hat", EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryText("Do you like my new hat?", 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) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI) Test(org.junit.Test)

Example 98 with URIImpl

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

the class AccumuloIndexSetColumnVisibilityTest method init.

@BeforeClass
public static void init() throws AccumuloException, AccumuloSecurityException, PCJStorageException, IOException, InterruptedException, TableNotFoundException, AlreadyInitializedException, RyaDetailsRepositoryException {
    // Setup the mini accumulo instance used by the test.
    accumulo = startMiniAccumulo();
    accumulo.getZooKeepers();
    instance = accumulo.getInstanceName();
    zooKeepers = accumulo.getZooKeepers();
    conf = getConf();
    accCon.securityOperations().changeUserAuthorizations("root", new Authorizations("U", "USA"));
    // Initialize the Rya Details for the Rya instance.
    initRyaDetails();
    // Initialize a PCJ.
    storage = new AccumuloPcjStorage(accCon, ryaInstanceName);
    pcjId = storage.createPcj("SELECT ?name ?age " + "{" + "?name <http://hasAge> ?age ." + "?name <http://playsSport> \"Soccer\" " + "}");
    // Store the PCJ's results.
    pcjBs1 = new QueryBindingSet();
    pcjBs1.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
    pcjBs1.addBinding("name", new URIImpl("http://Alice"));
    pcjBs2 = new QueryBindingSet();
    pcjBs2.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
    pcjBs2.addBinding("name", new URIImpl("http://Bob"));
    final Set<VisibilityBindingSet> visBs = new HashSet<>();
    for (final BindingSet bs : Sets.<BindingSet>newHashSet(pcjBs1, pcjBs2)) {
        visBs.add(new VisibilityBindingSet(bs, "U|USA"));
    }
    storage.addResults(pcjId, visBs);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) Authorizations(org.apache.accumulo.core.security.Authorizations) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) URIImpl(org.openrdf.model.impl.URIImpl) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) HashSet(java.util.HashSet) BeforeClass(org.junit.BeforeClass)

Example 99 with URIImpl

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

the class MongoPcjIntegrationTest method testEvaluateOneIndex.

@Test
public void testEvaluateOneIndex() 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 CountingResultHandler crh1 = new CountingResultHandler();
        final CountingResultHandler crh2 = new CountingResultHandler();
        PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 1, conf.getRyaInstanceName(), indexSparqlString);
        conn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString).evaluate(crh1);
        PcjIntegrationTestingUtil.deleteCoreRyaTables(getMongoClient(), conf.getRyaInstanceName(), conf.getTriplesCollectionName());
        pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString).evaluate(crh2);
        assertEquals(crh1.count, crh2.count);
    } finally {
        conn.close();
        pcjConn.close();
        nonPcjSail.shutDown();
        pcjSail.shutDown();
    }
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) SailRepository(org.openrdf.repository.sail.SailRepository) Sail(org.openrdf.sail.Sail) URIImpl(org.openrdf.model.impl.URIImpl) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration) StatefulMongoDBRdfConfiguration(org.apache.rya.mongodb.StatefulMongoDBRdfConfiguration) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 100 with URIImpl

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

the class DuplicateDataDetectorIT method testCreateEntityNearDuplicateConfigDisabled.

@Test
public void testCreateEntityNearDuplicateConfigDisabled() throws EntityStorageException, TypeStorageException, ConfigurationException, ObjectStorageException {
    // Create the types the Entity uses.
    final TypeStorage typeStorage = new MongoTypeStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    final Type personType = createPersonType();
    final Type employeeType = createEmployeeType();
    typeStorage.create(personType);
    typeStorage.create(employeeType);
    final Optional<Type> storedPersonType = typeStorage.get(personType.getId());
    final Optional<Type> storedEmployeeType = typeStorage.get(employeeType.getId());
    assertTrue(storedPersonType.isPresent());
    assertTrue(storedEmployeeType.isPresent());
    // Create it.
    final DuplicateDataConfig duplicateDataConfig = new DuplicateDataConfig(// boolean
    new Tolerance(0.0, ToleranceType.DIFFERENCE), // byte
    new Tolerance(0.0, ToleranceType.DIFFERENCE), // date
    new Tolerance(500.0, ToleranceType.DIFFERENCE), // double
    new Tolerance(0.0001, ToleranceType.PERCENTAGE), // float
    new Tolerance(0.0001, ToleranceType.PERCENTAGE), // integer
    new Tolerance(1.0, ToleranceType.DIFFERENCE), // long
    new Tolerance(1.0, ToleranceType.DIFFERENCE), // short
    new Tolerance(1.0, ToleranceType.DIFFERENCE), // string
    new Tolerance(1.0, ToleranceType.DIFFERENCE), // uri
    new Tolerance(1.0, ToleranceType.DIFFERENCE), new HashMap<String, List<String>>(), false);
    final DuplicateDataDetector duplicateDataDetector = new DuplicateDataDetector(duplicateDataConfig);
    final EntityStorage entityStorage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME, duplicateDataDetector);
    final Entity bobEntity = createBobEntity();
    entityStorage.create(bobEntity);
    assertTrue(entityStorage.get(bobEntity.getSubject()).isPresent());
    final Builder duplicateBobBuilder = Entity.builder(createBobEntity());
    duplicateBobBuilder.setSubject(createRyaUri("Robert"));
    // Modify a property for each type that is within tolerance
    duplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_AGE, shortRyaType((short) 41)));
    duplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_WEIGHT, floatRyaType(250.76f)));
    duplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_HEIGHT, doubleRyaType(72.499)));
    duplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_INCOME, intRyaType(50001)));
    duplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_NUMBER_OF_CHILDREN, byteRyaType((byte) 2)));
    duplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_LICENSE_NUMBER, longRyaType(123456789013L)));
    duplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_DATE_OF_BIRTH, dateRyaType(new DateTime(NOW.getTime() - 1).minusYears(40))));
    duplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_EXPIRATION_DATE, dateRyaType(new Date(NOW.getTime() - 1))));
    duplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_GLASSES, booleanRyaType(true)));
    duplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_EMAIL_ADDRESS, uriRyaType(new URIImpl("mailto:bob.smitch01@gmail.com"))));
    duplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_ADDRESS, stringRyaType("124 Fake St. Washington, DC 20024")));
    duplicateBobBuilder.setProperty(EMPLOYEE_TYPE_URI, new Property(HAS_EXTENSION, shortRyaType((short) 556)));
    final Entity duplicateBobEntity = duplicateBobBuilder.build();
    // Data duplication detection is disabled so it will be created.
    try {
        entityStorage.create(duplicateBobEntity);
    } catch (final EntityNearDuplicateException e) {
        fail();
    }
    assertTrue(entityStorage.get(duplicateBobEntity.getSubject()).isPresent());
    final Builder notDuplicateBobBuilder = Entity.builder(createBobEntity());
    notDuplicateBobBuilder.setSubject(createRyaUri("Not Bob"));
    // Modify a property for each type that is within tolerance
    notDuplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_AGE, shortRyaType((short) 50)));
    notDuplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_WEIGHT, floatRyaType(300.0f)));
    notDuplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_HEIGHT, doubleRyaType(100.0)));
    notDuplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_INCOME, intRyaType(60000)));
    notDuplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_NUMBER_OF_CHILDREN, byteRyaType((byte) 5)));
    notDuplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_LICENSE_NUMBER, longRyaType(9L)));
    notDuplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_DATE_OF_BIRTH, dateRyaType(new DateTime(NOW.getTime() - 10000000L).minusYears(40))));
    notDuplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_EXPIRATION_DATE, dateRyaType(new Date(NOW.getTime() - 10000000L))));
    notDuplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_GLASSES, booleanRyaType(false)));
    notDuplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_EMAIL_ADDRESS, uriRyaType(new URIImpl("mailto:bad.email.address@gmail.com"))));
    notDuplicateBobBuilder.setProperty(PERSON_TYPE_URI, new Property(HAS_ADDRESS, stringRyaType("123456789 Fake St. Washington, DC 20024")));
    notDuplicateBobBuilder.setProperty(EMPLOYEE_TYPE_URI, new Property(HAS_EXTENSION, shortRyaType((short) 1000)));
    final Entity notDuplicateBobEntity = notDuplicateBobBuilder.build();
    // Data duplication detection is disabled so it will be created.
    try {
        entityStorage.create(notDuplicateBobEntity);
    } catch (final EntityNearDuplicateException e) {
        fail();
    }
    assertTrue(entityStorage.get(notDuplicateBobEntity.getSubject()).isPresent());
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) MongoEntityStorage(org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage) ReflectionToStringBuilder(org.apache.commons.lang.builder.ReflectionToStringBuilder) Builder(org.apache.rya.indexing.entity.model.Entity.Builder) URIImpl(org.openrdf.model.impl.URIImpl) DateTime(org.joda.time.DateTime) Date(java.util.Date) MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) TypeStorage(org.apache.rya.indexing.entity.storage.TypeStorage) MongoTypeStorage(org.apache.rya.indexing.entity.storage.mongo.MongoTypeStorage) RyaType(org.apache.rya.api.domain.RyaType) RyaTypeUtils.shortRyaType(org.apache.rya.api.domain.RyaTypeUtils.shortRyaType) RyaTypeUtils.floatRyaType(org.apache.rya.api.domain.RyaTypeUtils.floatRyaType) RyaTypeUtils.uriRyaType(org.apache.rya.api.domain.RyaTypeUtils.uriRyaType) RyaTypeUtils.longRyaType(org.apache.rya.api.domain.RyaTypeUtils.longRyaType) RyaTypeUtils.stringRyaType(org.apache.rya.api.domain.RyaTypeUtils.stringRyaType) RyaTypeUtils.doubleRyaType(org.apache.rya.api.domain.RyaTypeUtils.doubleRyaType) RyaTypeUtils.byteRyaType(org.apache.rya.api.domain.RyaTypeUtils.byteRyaType) RyaTypeUtils.booleanRyaType(org.apache.rya.api.domain.RyaTypeUtils.booleanRyaType) RyaTypeUtils.dateRyaType(org.apache.rya.api.domain.RyaTypeUtils.dateRyaType) Type(org.apache.rya.indexing.entity.model.Type) RyaTypeUtils.intRyaType(org.apache.rya.api.domain.RyaTypeUtils.intRyaType) DuplicateDataConfig(org.apache.rya.indexing.smarturi.duplication.conf.DuplicateDataConfig) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Property(org.apache.rya.indexing.entity.model.Property) 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