Search in sources :

Example 56 with RepositoryContext

use of com.inova8.pathql.context.RepositoryContext in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathPatternSPARQLTests method test_4.

/**
 * Test 4.
 *
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
@Test
@Order(4)
void test_4() throws RecognitionException, PathPatternException {
    PathElement element = PathParser.parsePathPattern(repositoryContext, ":volumeFlow [ gt \"35\" ]");
    assertEquals("?n0 <http://default/volumeFlow> ?n1 .\r\n" + "FILTER(?n1 gt '35')\r\n" + "", element.toSPARQL());
}
Also used : PathElement(com.inova8.pathql.element.PathElement) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 57 with RepositoryContext

use of com.inova8.pathql.context.RepositoryContext in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathPatternSPARQLTests method test_24.

/**
 * Test 24.
 */
@Test
@Order(24)
void test_24() {
    try {
        PathElement element = PathParser.parsePathPattern(repositoryContext, "^:hasProductBatteryLimit/(:massFlow |:volumeFlow  |:density)");
        assertEquals("?n1 <http://default/hasProductBatteryLimit> ?n0 .\r\n" + "{{{{?n1 <http://default/massFlow> ?n2 .\r\n" + "}UNION{\r\n" + "?n1 <http://default/volumeFlow> ?n2 .\r\n" + "}}}UNION{\r\n" + "?n1 <http://default/density> ?n2 .\r\n" + "}}", element.toSPARQL());
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : PathElement(com.inova8.pathql.element.PathElement) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 58 with RepositoryContext

use of com.inova8.pathql.context.RepositoryContext in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathPatternSPARQLTests method test_05.

/**
 * Test 05.
 *
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
@Test
@Order(0)
void test_05() throws RecognitionException, PathPatternException {
    PathElement element = PathParser.parsePathPattern(repositoryContext, ":parent1/:parent2/:parent3");
    assertEquals("?n0 <http://default/parent1> ?n1 .\r\n" + "?n1 <http://default/parent2> ?n2 .\r\n" + "?n2 <http://default/parent3> ?n3 .\r\n" + "", element.toSPARQL());
}
Also used : PathElement(com.inova8.pathql.element.PathElement) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 59 with RepositoryContext

use of com.inova8.pathql.context.RepositoryContext in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathPatternSPARQLTests method test_28.

/**
 * Test 28.
 */
@Test
@Order(28)
void test_28() {
    try {
        PathElement element = PathParser.parsePathPattern(repositoryContext, "(:Attribute@:density  |:density)");
        assertEquals("{{{{?r1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> ?n0 }UNION{ ?n0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> ?r1 }}\r\n" + "{{?r1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <http://default/density> }UNION{ <http://default/density> <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> ?r1 }}\r\n" + "{{?r1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> ?n1 }UNION{ ?n1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> ?r1 }}\r\n" + "}UNION{\r\n" + "?n0 <http://default/density> ?n1 .\r\n" + "}}", element.toSPARQL());
    } catch (Exception e) {
        assertEquals("", e.getMessage());
    }
}
Also used : PathElement(com.inova8.pathql.element.PathElement) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 60 with RepositoryContext

use of com.inova8.pathql.context.RepositoryContext in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PathParser method parseIriRef.

/**
 * Parses the iri ref.
 *
 * @param repositoryContext the repository context
 * @param uriPattern the uri pattern
 * @return the iri ref value element
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
public static IriRefValueElement parseIriRef(RepositoryContext repositoryContext, String uriPattern) throws RecognitionException, PathPatternException {
    try {
        pathPatternVisitor = new PathPatternVisitor(repositoryContext);
        CharStream input = CharStreams.fromString(uriPattern);
        PathPatternLexer lexer = new PathPatternLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        PathPatternParser parser = new PathPatternParser(tokens);
        IriRefContext pathPatternTree = parser.iriRef();
        PathElement iriRefValueElement = pathPatternVisitor.visit(pathPatternTree);
        return (IriRefValueElement) iriRefValueElement;
    } catch (Exception qe) {
        throw new PathPatternException(qe.getMessage(), null);
    }
}
Also used : PathPatternVisitor(com.inova8.pathql.processor.PathPatternVisitor) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) PathElement(com.inova8.pathql.element.PathElement) PathPatternParser(com.inova8.pathql.pathPattern.PathPatternParser) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement) PathPatternException(com.inova8.pathql.processor.PathPatternException) PathPatternLexer(com.inova8.pathql.pathPattern.PathPatternLexer) CharStream(org.antlr.v4.runtime.CharStream) PathPatternException(com.inova8.pathql.processor.PathPatternException) RecognitionException(org.antlr.v4.runtime.RecognitionException) IriRefContext(com.inova8.pathql.pathPattern.PathPatternParser.IriRefContext)

Aggregations

PathElement (com.inova8.pathql.element.PathElement)116 Order (org.junit.jupiter.api.Order)110 Test (org.junit.jupiter.api.Test)110 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)110 RecognitionException (org.antlr.v4.runtime.RecognitionException)78 PathPatternException (com.inova8.pathql.processor.PathPatternException)26 PathTupleExpr (com.inova8.intelligentgraph.path.PathTupleExpr)10 PathPatternVisitor (com.inova8.pathql.processor.PathPatternVisitor)8 RepositoryContext (com.inova8.pathql.context.RepositoryContext)7 Iterations (com.inova8.pathql.element.Iterations)7 PathPatternLexer (com.inova8.pathql.pathPattern.PathPatternLexer)7 PathPatternParser (com.inova8.pathql.pathPattern.PathPatternParser)7 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)7 BeforeAll (org.junit.jupiter.api.BeforeAll)7 PathBinding (com.inova8.intelligentgraph.path.PathBinding)5 PathPatternContext (com.inova8.pathql.pathPattern.PathPatternParser.PathPatternContext)4 CharStream (org.antlr.v4.runtime.CharStream)4 PathErrorListener (com.inova8.pathql.processor.PathErrorListener)2 IriRefValueElement (com.inova8.pathql.element.IriRefValueElement)1 PredicateElement (com.inova8.pathql.element.PredicateElement)1