Search in sources :

Example 1 with WholeRowHashedTripleResolver

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());
}
Also used : Pattern(java.util.regex.Pattern) TriplePatternStrategy(org.apache.rya.api.query.strategy.TriplePatternStrategy) Matcher(java.util.regex.Matcher) WholeRowHashedTripleResolver(org.apache.rya.api.resolver.triple.impl.WholeRowHashedTripleResolver) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaURI(org.apache.rya.api.domain.RyaURI) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) TripleRowRegex(org.apache.rya.api.resolver.triple.TripleRowRegex)

Aggregations

Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 RyaStatement (org.apache.rya.api.domain.RyaStatement)1 RyaURI (org.apache.rya.api.domain.RyaURI)1 TriplePatternStrategy (org.apache.rya.api.query.strategy.TriplePatternStrategy)1 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)1 TripleRowRegex (org.apache.rya.api.resolver.triple.TripleRowRegex)1 WholeRowHashedTripleResolver (org.apache.rya.api.resolver.triple.impl.WholeRowHashedTripleResolver)1