use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class RdfFileInputFormatTest method testTrigInput.
@Test
public void testTrigInput() throws Exception {
RdfFileInputFormat.setRDFFormat(job, RDFFormat.TRIG);
init(TRIG_INPUT);
Assert.assertTrue(reader.nextKeyValue());
Assert.assertEquals(1, reader.getCurrentKey().get());
Statement expected = new ContextStatementImpl(new URIImpl("http://www.example.org/exampleDocument#Monica"), new URIImpl("http://www.example.org/vocabulary#name"), new LiteralImpl("Monica Murphy"), new URIImpl("http://www.example.org/exampleDocument#G1"));
Statement actual = RyaToRdfConversions.convertStatement(reader.getCurrentValue().getRyaStatement());
Assert.assertEquals(expected, actual);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class EntityIndexSetProvider method discoverEntities.
private void discoverEntities(final StatementPattern pattern, final List<StatementPattern> unmatched) {
final Var subj = pattern.getSubjectVar();
final String subjStr = subj.getName();
final RyaURI predURI = getPredURI(pattern);
// check to see if current node is type
if (new URIImpl(predURI.getData()).equals(RDF.TYPE)) {
final Var obj = pattern.getObjectVar();
final RyaURI objURI = new RyaURI(obj.getValue().stringValue());
try {
final Optional<Type> optType = typeStorage.get(objURI);
// if is type, fetch type add to subject -> type map
if (optType.isPresent()) {
final Type type = optType.get();
typeMap.put(type, pattern);
subjectTypeMap.put(subjStr, type);
// check unmatched properties, add matches
for (final StatementPattern propertyPattern : unmatched) {
// store sps into the type -> property map
final RyaURI property = getPredURI(propertyPattern);
final Var typeSubVar = getTypeSubject(type);
final Var patternSubVar = propertyPattern.getSubjectVar();
if (type.getPropertyNames().contains(property) && typeSubVar.equals(patternSubVar)) {
typeMap.put(type, propertyPattern);
}
}
}
} catch (final TypeStorageException e) {
e.printStackTrace();
}
} else {
// if not type, check to see if subject is in type map
if (subjectTypeMap.containsKey(subjStr)) {
// if is, check to see if pred is a property of type
final Type type = subjectTypeMap.get(subjStr);
if (type.getPropertyNames().contains(predURI)) {
// if is, add sp to type -> sp map
if (!typeMap.containsKey(type)) {
// each variable can only contain 1 type for now @see:Rya-235?
typeMap.put(type, pattern);
}
} else {
// if not, add to unmatched type
unmatched.add(pattern);
}
} else {
// if not, add to unmatched
unmatched.add(pattern);
}
}
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class MongoPcjStorageIT method listResults.
@Test
public void listResults() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
// Create a PCJ.
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
final String pcjId = pcjStorage.createPcj(sparql);
// Add some binding sets to it.
final Set<VisibilityBindingSet> visiSets = new HashSet<>();
final Set<BindingSet> expectedResults = new HashSet<>();
final MapBindingSet aliceBS = new MapBindingSet();
aliceBS.addBinding("a", new URIImpl("http://Alice"));
aliceBS.addBinding("b", new URIImpl("http://Person"));
visiSets.add(new VisibilityBindingSet(aliceBS, ""));
expectedResults.add(aliceBS);
final MapBindingSet charlieBS = new MapBindingSet();
charlieBS.addBinding("a", new URIImpl("http://Charlie"));
charlieBS.addBinding("b", new URIImpl("http://Comedian"));
visiSets.add(new VisibilityBindingSet(charlieBS, ""));
expectedResults.add(charlieBS);
pcjStorage.addResults(pcjId, visiSets);
// List the results that were stored.
final Set<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertEquals(expectedResults, results);
}
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class MongoPcjStorageIT method purge.
@Test
public void purge() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
// Create a PCJ.
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
final String pcjId = pcjStorage.createPcj(sparql);
// Add some binding sets to it.
final Set<VisibilityBindingSet> expectedResults = new HashSet<>();
final MapBindingSet aliceBS = new MapBindingSet();
aliceBS.addBinding("a", new URIImpl("http://Alice"));
aliceBS.addBinding("b", new URIImpl("http://Person"));
expectedResults.add(new VisibilityBindingSet(aliceBS, ""));
final MapBindingSet charlieBS = new MapBindingSet();
charlieBS.addBinding("a", new URIImpl("http://Charlie"));
charlieBS.addBinding("b", new URIImpl("http://Comedian"));
expectedResults.add(new VisibilityBindingSet(charlieBS, ""));
pcjStorage.addResults(pcjId, expectedResults);
// Purge the PCJ.
pcjStorage.purge(pcjId);
// List the results that were stored.
final Set<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertTrue(results.isEmpty());
// Make sure the PCJ metadata was updated.
final PcjMetadata metadata = pcjStorage.getPcjMetadata(pcjId);
final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(sparql);
final PcjMetadata expectedMetadata = new PcjMetadata(sparql, 0L, varOrders);
assertEquals(expectedMetadata, metadata);
}
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class PcjDocumentsWithMockTest method populatePcj.
@Test
public void populatePcj() throws Exception {
final RdfCloudTripleStore ryaStore = new RdfCloudTripleStore();
final MongoDBRyaDAO dao = new MongoDBRyaDAO();
dao.setConf(new StatefulMongoDBRdfConfiguration(conf, getMongoClient()));
dao.init();
ryaStore.setRyaDAO(dao);
ryaStore.initialize();
final SailRepositoryConnection ryaConn = new RyaSailRepository(ryaStore).getConnection();
try {
// Load some Triples into Rya.
final Set<Statement> triples = new HashSet<>();
triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://hasAge"), new NumericLiteralImpl(14, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://hasAge"), new NumericLiteralImpl(16, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://hasAge"), new NumericLiteralImpl(12, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://hasAge"), new NumericLiteralImpl(43, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
for (final Statement triple : triples) {
ryaConn.add(triple);
}
// Create a PCJ table that will include those triples in its results.
final String sparql = "SELECT ?name ?age " + "{" + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = new PcjTableNameFactory().makeTableName(conf.getRyaInstanceName(), "testPcj");
final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
pcjs.createAndPopulatePcj(ryaConn, pcjTableName, sparql);
// Make sure the cardinality was updated.
final PcjMetadata metadata = pcjs.getPcjMetadata(pcjTableName);
assertEquals(4, metadata.getCardinality());
} finally {
ryaConn.close();
ryaStore.shutDown();
}
}
Aggregations