Skip to content

Commit

Permalink
[Enhancement #161] Support attribute language tag extraction (and com…
Browse files Browse the repository at this point in the history
…parison) in SOQL.
  • Loading branch information
ledsoft committed Jun 30, 2023
1 parent 9aa93fe commit 4da0e16
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
Expand Up @@ -102,6 +102,7 @@ functionsReturningStrings
| 'SUBSTRING' '(' stringExpression ',' simpleArithmeticExpression ',' simpleArithmeticExpression ')'
| 'LOWER' '(' stringExpression ')'
| 'UPPER' '(' stringExpression ')'
| 'LANG' '(' whereClauseParam ')'
;

simpleArithmeticExpression
Expand Down
Expand Up @@ -121,6 +121,11 @@ public static class Functions {
*/
public static final String FLOOR = "FLOOR";

/**
* Returns language tag of a literal, if it has one. Returns an empty string if it has no language tag.
*/
public static final String LANG = "LANG";

private Functions() {
throw new AssertionError();
}
Expand Down
Expand Up @@ -35,6 +35,7 @@ private static Map<String, String> initFunctions() {
map.put(SoqlConstants.Functions.ABS, "ABS");
map.put(SoqlConstants.Functions.CEIL, "CEIL");
map.put(SoqlConstants.Functions.FLOOR, "FLOOR");
map.put(SoqlConstants.Functions.LANG, "lang");
return map;
}

Expand Down
Expand Up @@ -1286,6 +1286,7 @@ static void initOwlClassUMocks(IdentifiableEntityType<OWLClassU> et, SingularAtt
when(et.getJavaType()).thenReturn(OWLClassU.class);
when(id.getJavaField()).thenReturn(OWLClassU.getIdField());
when(id.getDeclaringType()).thenReturn(et);
when(id.getName()).thenReturn(OWLClassU.getIdField().getName());
when(et.getIRI()).thenReturn(IRI.create(OWLClassU.getClassIri()));
when(et.getName()).thenReturn(OWLClassU.class.getSimpleName());
when(et.getFieldSpecifications())
Expand Down
Expand Up @@ -739,4 +739,13 @@ void parseQueryWithRelatedAttributeAndIdentifierIsCommutative() {
parseAndAssertEquality(soqlIdFirst, expectedSparql);
parseAndAssertEquality(soqlIdSecond, expectedSparql);
}

@Test
void parseQuerySupportsLangExtractionAndComparison() {
final String soql = "SELECT u FROM OWLClassU u WHERE LANG(u.singularStringAtt) = :language";
final String expectedSparql = "SELECT ?x WHERE { ?x a " + strUri(Vocabulary.c_OwlClassU) + " . " +
"?x " + strUri(Vocabulary.P_U_SINGULAR_MULTILINGUAL_ATTRIBUTE) + " ?uSingularStringAtt . " +
"FILTER (lang(?uSingularStringAtt) = ?language) }";
parseAndAssertEquality(soql, expectedSparql);
}
}

0 comments on commit 4da0e16

Please sign in to comment.