public static void process(ASTQueryContainer ast, POFMetadata meta) {
    final ASTGraphPatternGroup gpg = ast.getQuery().getWhereClause().getGraphPatternGroup();

    final List<Object> keyword =
        meta.pofNode.getMetadata() == null
            ? null
            : meta.pofNode.getMetadata(SyntaxTreeBuilder.Keyword);
    final List<Object> prefix =
        meta.pofNode.getMetadata() == null
            ? null
            : meta.pofNode.getMetadata(SyntaxTreeBuilder.Prefix);
    final List<Object> qname =
        meta.pofNode.getMetadata() == null
            ? null
            : meta.pofNode.getMetadata(SyntaxTreeBuilder.Qname);

    if (keyword != null) {
      final ASTBasicGraphPattern bgp =
          addRegexFilter(meta.pofNode, keyword.get(0).toString(), true);
      gpg.jjtAppendChild(bgp);
    } else if (prefix != null) {
      final ASTBasicGraphPattern bgp =
          addRegexFilter(meta.pofNode, "^" + prefix.get(0).toString().substring(1), true);
      gpg.jjtAppendChild(bgp);
    } else if (qname != null) {
      final ASTBasicGraphPattern bgp =
          addRegexFilter(meta.pofNode, "^" + qname.get(0).toString(), true);
      gpg.jjtAppendChild(bgp);
    }
  }
  @Test
  public void testTranslateClassTriplePattern() throws Exception {
    final String query = "SELECT * { ?s a <Person> . }";
    ast = SyntaxTreeBuilder.parseQuery(query);
    SparqlTranslationProcessor.process(ast);

    final String[] vars = ASTVarGenerator.getCurrentVarNames();
    assertEquals(1, vars.length);
    final String expected =
        "QueryContainer\n"
            + " SelectQuery\n"
            + "  Select ( * )\n"
            + "  DatasetClause (named=false)\n"
            + "   IRI ("
            + AnalyticsVocab.GRAPH_SUMMARY_GRAPH
            + ")\n"
            + "  WhereClause\n"
            + "   GraphPatternGroup\n"
            + "    BasicGraphPattern\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var (s)\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "       ObjectList\n"
            + "        Var ("
            + vars[0]
            + ")\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + vars[0]
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "       ObjectList\n"
            + "        IRI (Person)";

    assertEquals(expected, ast.dump(""));
  }
  @Test
  public void testConnectedObject2() throws Exception {
    final String query = "SELECT * { ?s ?p ?o . ?a ?POF ?o . }";
    ast = SyntaxTreeBuilder.parseQuery(query);
    SparqlTranslationProcessor.process(ast);

    final String[] vars = ASTVarGenerator.getCurrentVarNames();
    assertEquals(2, vars.length);
    final String expected =
        "QueryContainer\n"
            + " SelectQuery\n"
            + "  Select ( distinct * )\n"
            + "   ProjectionElem\n"
            + "    Var ("
            + QueryProcessor.CARDINALITY_VAR
            + ")\n"
            + "   ProjectionElem\n"
            + "    Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "  DatasetClause (named=false)\n"
            + "   IRI ("
            + AnalyticsVocab.GRAPH_SUMMARY_GRAPH
            + ")\n"
            + "  WhereClause\n"
            + "   GraphPatternGroup\n"
            + "    BasicGraphPattern\n"
            + "     Constraint\n"
            + "      Not\n"
            + "       IsLiteral\n"
            + "        Var (o)\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + vars[0]
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.EDGE_SOURCE
            + ")\n"
            + "       ObjectList\n"
            + "        Var (s)\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + vars[0]
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.EDGE_TARGET
            + ")\n"
            + "       ObjectList\n"
            + "        Var (o)\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + vars[0]
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "       ObjectList\n"
            + "        Var (p)\n"
            + "     Constraint\n"
            + "      Not\n"
            + "       IsLiteral\n"
            + "        Var (o)\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.EDGE_SOURCE
            + ")\n"
            + "       ObjectList\n"
            + "        Var (a)\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.EDGE_TARGET
            + ")\n"
            + "       ObjectList\n"
            + "        Var (o)\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "       ObjectList\n"
            + "        Var (POF)\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.CARDINALITY
            + ")\n"
            + "       ObjectList\n"
            + "        Var (POFcardinality)";

    assertEquals(expected, ast.dump(""));
  }
  @Test
  public void testPOFonClass() throws Exception {
    final String query = "SELECT * { ?a a ?POF . }";
    ast = SyntaxTreeBuilder.parseQuery(query);
    SparqlTranslationProcessor.process(ast);

    final String[] vars = ASTVarGenerator.getCurrentVarNames();
    assertEquals(2, vars.length);
    final String expected =
        "QueryContainer\n"
            + " SelectQuery\n"
            + "  Select ( distinct * )\n"
            + "   ProjectionElem\n"
            + "    Var ("
            + QueryProcessor.CLASS_ATTRIBUTE_CARD_VAR
            + ")\n"
            + "   ProjectionElem\n"
            + "    Var ("
            + QueryProcessor.CLASS_ATTRIBUTE_LABEL_VAR
            + ")\n"
            + "   ProjectionElem\n"
            + "    Var ("
            + QueryProcessor.CARDINALITY_VAR
            + ")\n"
            + "   ProjectionElem\n"
            + "    Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "  DatasetClause (named=false)\n"
            + "   IRI ("
            + AnalyticsVocab.GRAPH_SUMMARY_GRAPH
            + ")\n"
            + "  WhereClause\n"
            + "   GraphPatternGroup\n"
            + "    BasicGraphPattern\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "       ObjectList\n"
            + "        Var ("
            + vars[0]
            + ")\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + vars[0]
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "       ObjectList\n"
            + "        Var (POF)\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.CARDINALITY
            + ")\n"
            + "       ObjectList\n"
            + "        Var ("
            + QueryProcessor.CARDINALITY_VAR
            + ")\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + vars[0]
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.TYPE
            + ")\n"
            + "       ObjectList\n"
            + "        Var ("
            + vars[1]
            + ")\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + vars[1]
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.CARDINALITY
            + ")\n"
            + "       ObjectList\n"
            + "        Var ("
            + QueryProcessor.CLASS_ATTRIBUTE_CARD_VAR
            + ")\n"
            + "     TriplesSameSubjectPath\n"
            + "      Var ("
            + vars[1]
            + ")\n"
            + "      PropertyListPath\n"
            + "       PathAlternative\n"
            + "        PathSequence\n"
            + "         PathElt\n"
            + "          IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "       ObjectList\n"
            + "        Var ("
            + QueryProcessor.CLASS_ATTRIBUTE_LABEL_VAR
            + ")";

    assertEquals(expected, ast.dump(""));
  }
  @Test
  public void testTranslateDatasetPOF() throws Exception {
    final String query = "SELECT * { GRAPH ?POF { ?s a <Person> . ?s <age> ?age } }";
    ast = SyntaxTreeBuilder.parseQuery(query);
    SparqlTranslationProcessor.process(ast);

    final String[] vars = ASTVarGenerator.getCurrentVarNames();
    assertEquals(2, vars.length);
    final String expected =
        "QueryContainer\n"
            + " SelectQuery\n"
            + "  Select ( distinct * )\n"
            + "   ProjectionElem\n"
            + "    Var ("
            + QueryProcessor.CARDINALITY_VAR
            + ")\n"
            + "   ProjectionElem\n"
            + "    Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "  DatasetClause (named=false)\n"
            + "   IRI ("
            + AnalyticsVocab.GRAPH_SUMMARY_GRAPH
            + ")\n"
            + "  WhereClause\n"
            + "   GraphPatternGroup\n"
            + "    GraphPatternGroup\n"
            + "     BasicGraphPattern\n"
            + "      TriplesSameSubjectPath\n"
            + "       Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "       PropertyListPath\n"
            + "        PathAlternative\n"
            + "         PathSequence\n"
            + "          PathElt\n"
            + "           IRI ("
            + AnalyticsVocab.DOMAIN_URI
            + ")\n"
            + "        ObjectList\n"
            + "         Var (POF)\n"
            + "      TriplesSameSubjectPath\n"
            + "       Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "       PropertyListPath\n"
            + "        PathAlternative\n"
            + "         PathSequence\n"
            + "          PathElt\n"
            + "           IRI ("
            + AnalyticsVocab.CARDINALITY
            + ")\n"
            + "        ObjectList\n"
            + "         Var ("
            + QueryProcessor.CARDINALITY_VAR
            + ")\n"
            + "      TriplesSameSubjectPath\n"
            + "       Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "       PropertyListPath\n"
            + "        PathAlternative\n"
            + "         PathSequence\n"
            + "          PathElt\n"
            + "           IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "        ObjectList\n"
            + "         Var ("
            + vars[0]
            + ")\n"
            + "      TriplesSameSubjectPath\n"
            + "       Var ("
            + vars[0]
            + ")\n"
            + "       PropertyListPath\n"
            + "        PathAlternative\n"
            + "         PathSequence\n"
            + "          PathElt\n"
            + "           IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "        ObjectList\n"
            + "         IRI (Person)\n"
            + "      TriplesSameSubjectPath\n"
            + "       Var ("
            + vars[1]
            + ")\n"
            + "       PropertyListPath\n"
            + "        PathAlternative\n"
            + "         PathSequence\n"
            + "          PathElt\n"
            + "           IRI ("
            + AnalyticsVocab.EDGE_SOURCE
            + ")\n"
            + "        ObjectList\n"
            + "         Var ("
            + QueryProcessor.POF_RESOURCE
            + ")\n"
            + "      TriplesSameSubjectPath\n"
            + "       Var ("
            + vars[1]
            + ")\n"
            + "       PropertyListPath\n"
            + "        PathAlternative\n"
            + "         PathSequence\n"
            + "          PathElt\n"
            + "           IRI ("
            + AnalyticsVocab.EDGE_TARGET
            + ")\n"
            + "        ObjectList\n"
            + "         RDFLiteral\n"
            + "          String ("
            + AnalyticsVocab.BLANK_NODE_COLLECTION
            + ")\n"
            + "      TriplesSameSubjectPath\n"
            + "       Var ("
            + vars[1]
            + ")\n"
            + "       PropertyListPath\n"
            + "        PathAlternative\n"
            + "         PathSequence\n"
            + "          PathElt\n"
            + "           IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "        ObjectList\n"
            + "         IRI (age)\n"
            + "      TriplesSameSubjectPath\n"
            + "       Var ("
            + vars[1]
            + ")\n"
            + "       PropertyListPath\n"
            + "        PathAlternative\n"
            + "         PathSequence\n"
            + "          PathElt\n"
            + "           IRI ("
            + AnalyticsVocab.EDGE_PUBLISHED_IN
            + ")\n"
            + "        ObjectList\n"
            + "         Var (POF)";

    assertEquals(expected, ast.dump(""));
  }
  @Test
  public void testTranslateDataset2() throws Exception {
    final String query =
        "SELECT * { Graph <http://sindice.com> { ?s a <Person> . OPTIONAL {?s ?p ?o } } }";
    ast = SyntaxTreeBuilder.parseQuery(query);
    SparqlTranslationProcessor.process(ast);

    final String[] vars = ASTVarGenerator.getCurrentVarNames();
    assertEquals(2, vars.length);
    final String expected =
        "QueryContainer\n"
            + " SelectQuery\n"
            + "  Select ( * )\n"
            + "  DatasetClause (named=false)\n"
            + "   IRI ("
            + AnalyticsVocab.GRAPH_SUMMARY_GRAPH
            + ")\n"
            + "  WhereClause\n"
            + "   GraphPatternGroup\n"
            + "    GraphPatternGroup\n"
            + "     BasicGraphPattern\n"
            + "      TriplesSameSubjectPath\n"
            + "       Var (s)\n"
            + "       PropertyListPath\n"
            + "        PathAlternative\n"
            + "         PathSequence\n"
            + "          PathElt\n"
            + "           IRI ("
            + AnalyticsVocab.DOMAIN_URI
            + ")\n"
            + "        ObjectList\n"
            + "         IRI ("
            + AnalyticsVocab.DOMAIN_URI_PREFIX
            + "sindice.com)\n"
            + "      TriplesSameSubjectPath\n"
            + "       Var (s)\n"
            + "       PropertyListPath\n"
            + "        PathAlternative\n"
            + "         PathSequence\n"
            + "          PathElt\n"
            + "           IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "        ObjectList\n"
            + "         Var ("
            + vars[0]
            + ")\n"
            + "      TriplesSameSubjectPath\n"
            + "       Var ("
            + vars[0]
            + ")\n"
            + "       PropertyListPath\n"
            + "        PathAlternative\n"
            + "         PathSequence\n"
            + "          PathElt\n"
            + "           IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "        ObjectList\n"
            + "         IRI (Person)\n"
            + "     OptionalGraphPattern\n"
            + "      BasicGraphPattern\n"
            + "       TriplesSameSubjectPath\n"
            + "        Var ("
            + vars[1]
            + ")\n"
            + "        PropertyListPath\n"
            + "         PathAlternative\n"
            + "          PathSequence\n"
            + "           PathElt\n"
            + "            IRI ("
            + AnalyticsVocab.EDGE_SOURCE
            + ")\n"
            + "         ObjectList\n"
            + "          Var (s)\n"
            + "       TriplesSameSubjectPath\n"
            + "        Var ("
            + vars[1]
            + ")\n"
            + "        PropertyListPath\n"
            + "         PathAlternative\n"
            + "          PathSequence\n"
            + "           PathElt\n"
            + "            IRI ("
            + AnalyticsVocab.EDGE_TARGET
            + ")\n"
            + "         ObjectList\n"
            + "          RDFLiteral\n"
            + "           String ("
            + AnalyticsVocab.BLANK_NODE_COLLECTION
            + ")\n"
            + "       TriplesSameSubjectPath\n"
            + "        Var ("
            + vars[1]
            + ")\n"
            + "        PropertyListPath\n"
            + "         PathAlternative\n"
            + "          PathSequence\n"
            + "           PathElt\n"
            + "            IRI ("
            + AnalyticsVocab.LABEL
            + ")\n"
            + "         ObjectList\n"
            + "          Var (p)\n"
            + "       TriplesSameSubjectPath\n"
            + "        Var ("
            + vars[1]
            + ")\n"
            + "        PropertyListPath\n"
            + "         PathAlternative\n"
            + "          PathSequence\n"
            + "           PathElt\n"
            + "            IRI ("
            + AnalyticsVocab.EDGE_PUBLISHED_IN
            + ")\n"
            + "         ObjectList\n"
            + "          IRI ("
            + AnalyticsVocab.DOMAIN_URI_PREFIX
            + "sindice.com)";

    assertEquals(expected, ast.dump(""));
  }