use of org.apache.rya.api.resolver.triple.impl.WholeRowHashedTripleResolver in project incubator-rya by apache.
the class HashedPoWholeRowTriplePatternStrategyTest method testRegex.
public void testRegex() throws Exception {
RyaURI subj = new RyaURI("urn:test#1234");
RyaURI pred = new RyaURI("urn:test#pred");
RyaURI obj = new RyaURI("urn:test#obj");
RyaStatement ryaStatement = new RyaStatement(subj, pred, obj);
Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = new WholeRowHashedTripleResolver().serialize(ryaStatement);
TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
String row = new String(tripleRow.getRow());
TriplePatternStrategy spoStrategy = new HashedSpoWholeRowTriplePatternStrategy();
TriplePatternStrategy poStrategy = new HashedPoWholeRowTriplePatternStrategy();
TriplePatternStrategy ospStrategy = new OspWholeRowTriplePatternStrategy();
// pred
TripleRowRegex tripleRowRegex = spoStrategy.buildRegex(null, pred.getData(), null, null, null);
Pattern p = Pattern.compile(tripleRowRegex.getRow());
Matcher matcher = p.matcher(row);
assertTrue(matcher.matches());
// subj
tripleRowRegex = spoStrategy.buildRegex(subj.getData(), null, null, null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
// obj
tripleRowRegex = spoStrategy.buildRegex(null, null, obj.getData(), null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
// po table
row = new String(serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO).getRow());
tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), null, null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
tripleRowRegex = poStrategy.buildRegex(null, pred.getData(), obj.getData(), null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
tripleRowRegex = poStrategy.buildRegex(subj.getData(), pred.getData(), obj.getData(), null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
// various regex
tripleRowRegex = poStrategy.buildRegex(null, "urn:test#pr[e|d]{2}", null, null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertTrue(matcher.matches());
// does not match
tripleRowRegex = poStrategy.buildRegex(null, "hello", null, null, null);
p = Pattern.compile(tripleRowRegex.getRow());
matcher = p.matcher(row);
assertFalse(matcher.matches());
}
Aggregations