use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class MongoStatementMetadataNodeIT method simpleQueryWithoutBindingSet.
@Test
public void simpleQueryWithoutBindingSet() throws Exception {
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
StatementMetadata metadata = new StatementMetadata();
metadata.addMetadata(new RyaURI("http://createdBy"), new RyaType("Joe"));
metadata.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-04"));
RyaStatement statement = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata);
dao.add(statement);
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq = parser.parseQuery(query, null);
List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
StatementMetadataNode<?> node = new StatementMetadataNode<>(spList, conf);
CloseableIteration<BindingSet, QueryEvaluationException> iteration = node.evaluate(new QueryBindingSet());
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("x", new LiteralImpl("CoffeeShop"));
bs.addBinding("y", new LiteralImpl("Joe"));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(1, bsList.size());
Assert.assertEquals(bs, bsList.get(0));
dao.delete(statement, conf);
} finally {
dao.destroy();
}
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class StatementMetadataExample method example1.
/**
* This example demonstrates how a reified query can be used to return
* metadata. In the example below, the query returns all the places that Joe
* works at along with the people that created the triples containing those locations
* and the dates that those triples were created on.
*
* @throws Exception
*/
private void example1() throws Exception {
String query1 = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + "PREFIX owl: <http://www.w3.org/2002/07/owl#> \n" + "SELECT ?x ?y ?z \n" + "WHERE {\n" + "_:blankNode rdf:type owl:Annotation. \n" + "_:blankNode owl:annotatedSource <http://Joe>. \n" + "_:blankNode owl:annotatedProperty <http://worksAt>. \n" + "_:blankNode owl:annotatedTarget ?x. \n" + "_:blankNode <http://createdBy> ?y. \n" + "_:blankNode <http://createdOn> ?z }\n";
StatementMetadata metadata1 = new StatementMetadata();
metadata1.addMetadata(new RyaURI("http://createdBy"), new RyaURI("http://Dave"));
metadata1.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-02"));
RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata1);
StatementMetadata metadata2 = new StatementMetadata();
metadata2.addMetadata(new RyaURI("http://createdBy"), new RyaURI("http://Dave"));
metadata2.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-02-04"));
RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context"), "", metadata2);
StatementMetadata metadata3 = new StatementMetadata();
metadata3.addMetadata(new RyaURI("http://createdBy"), new RyaURI("http://Fred"));
metadata3.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-03-08"));
RyaStatement statement3 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("Library"), new RyaURI("http://context"), "", metadata3);
// add statements for querying
dao.add(statement1);
dao.add(statement2);
dao.add(statement3);
System.out.println("**************************************************************************");
System.out.println(" RUNNING EXAMPLE 1");
System.out.println("**************************************************************************");
System.out.println("");
// issue query - 3 results expected
query(query1, 3);
// delete statements to run next example
dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), getConf());
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class StatementMetadataExample method example3.
/**
* In addition to returning metadata, this example demonstrates how a
* reified query can be used to return only those triples matching certain
* metadata criteria. The query below returns only those triples containing Joe's
* work location that were created on 2017-02-04. To filter by metadata property, simply set the
* value for the property to a fixed constant ('2017-02-04'^^xsd:date is set for the property
* http://createdOn in the query below).
*
* @throws Exception
*/
private void example3() throws Exception {
String query3 = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + "PREFIX owl: <http://www.w3.org/2002/07/owl#> \n" + "SELECT ?x ?y \n" + "WHERE {\n" + "_:blankNode rdf:type owl:Annotation. \n" + "_:blankNode owl:annotatedSource <http://Joe>. \n" + "_:blankNode owl:annotatedProperty <http://worksAt>. \n" + "_:blankNode owl:annotatedTarget ?x. \n" + "_:blankNode <http://createdBy> ?y. \n" + "_:blankNode <http://createdOn> '2017-02-04'^^xsd:date }\n";
StatementMetadata metadata1 = new StatementMetadata();
metadata1.addMetadata(new RyaURI("http://createdBy"), new RyaURI("http://Dave"));
metadata1.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-01-02"));
RyaStatement statement1 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("CoffeeShop"), new RyaURI("http://context"), "", metadata1);
StatementMetadata metadata2 = new StatementMetadata();
metadata2.addMetadata(new RyaURI("http://createdBy"), new RyaURI("http://Dave"));
metadata2.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-02-04"));
RyaStatement statement2 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("HardwareStore"), new RyaURI("http://context"), "", metadata2);
StatementMetadata metadata3 = new StatementMetadata();
metadata3.addMetadata(new RyaURI("http://createdBy"), new RyaURI("http://Fred"));
metadata3.addMetadata(new RyaURI("http://createdOn"), new RyaType(XMLSchema.DATE, "2017-03-08"));
RyaStatement statement3 = new RyaStatement(new RyaURI("http://Joe"), new RyaURI("http://worksAt"), new RyaType("Library"), new RyaURI("http://context"), "", metadata3);
// add statements for querying
dao.add(statement1);
dao.add(statement2);
dao.add(statement3);
System.out.println("**************************************************************************");
System.out.println(" RUNNING EXAMPLE 3");
System.out.println("**************************************************************************");
System.out.println("");
// issue query - 1 result expected
query(query3, 1);
// delete statements to run next example
dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), getConf());
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class AccumuloRyaUtils method createRyaStatement.
/**
* Creates a {@link RyaStatement} from a {@link Key}/{@link Value} pair.
* @param key the {@link Key}.
* @param value the {@link Value}.
* @param ryaTripleContext the {@link RyaTripleContext}.
* @return the converted {@link RyaStatement}.
* @throws TripleRowResolverException
*/
public static RyaStatement createRyaStatement(final Key key, final Value value, final RyaTripleContext ryaTripleContext) throws TripleRowResolverException {
final byte[] row = key.getRowData() != null && key.getRowData().toArray().length > 0 ? key.getRowData().toArray() : null;
final byte[] columnFamily = key.getColumnFamilyData() != null && key.getColumnFamilyData().toArray().length > 0 ? key.getColumnFamilyData().toArray() : null;
final byte[] columnQualifier = key.getColumnQualifierData() != null && key.getColumnQualifierData().toArray().length > 0 ? key.getColumnQualifierData().toArray() : null;
final Long timestamp = key.getTimestamp();
final byte[] columnVisibility = key.getColumnVisibilityData() != null && key.getColumnVisibilityData().toArray().length > 0 ? key.getColumnVisibilityData().toArray() : null;
final byte[] valueBytes = value != null && value.get().length > 0 ? value.get() : null;
final TripleRow tripleRow = new TripleRow(row, columnFamily, columnQualifier, timestamp, columnVisibility, valueBytes);
final RyaStatement ryaStatement = ryaTripleContext.deserializeTriple(TABLE_LAYOUT.SPO, tripleRow);
return ryaStatement;
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class TestUtils method createRyaStatement.
/**
* Creates a {@link RyaStatement} from the specified subject, predicate, and object.
* @param subject the subject.
* @param predicate the predicate.
* @param object the object.
* @param date the {@link Date} to use for the key's timestamp.
* @return the {@link RyaStatement}.
*/
public static RyaStatement createRyaStatement(final String subject, final String predicate, final String object, final Date date) {
final RyaURI subjectUri = createRyaUri(subject);
final RyaURI predicateUri = createRyaUri(predicate);
final RyaURI objectUri = createRyaUri(object);
final RyaStatement ryaStatement = new RyaStatement(subjectUri, predicateUri, objectUri);
if (date != null) {
ryaStatement.setTimestamp(date.getTime());
}
return ryaStatement;
}
Aggregations