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