use of com.inova8.pathql.element.LiteralValueElement in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitQueryOptions.
/**
* Visit query options.
*
* @param ctx the ctx
* @return the query options path element
*/
@Override
public QueryOptionsPathElement visitQueryOptions(QueryOptionsContext ctx) {
// queryOptions : ( queryOption )+;
// queryOption: KEY '=' literal ('^^' type )?;
// KEY : '&' [a-zA-Z]+ ;
CustomQueryOptions customQueryOptions = new CustomQueryOptions();
for (QueryOptionContext queryOption : ctx.queryOption()) {
String key = queryOption.KEY().getText().substring(1);
LiteralValueElement literal = (LiteralValueElement) visit(queryOption.literal());
if (queryOption.type() != null) {
IriRefValueElement type = (IriRefValueElement) visit(queryOption.type());
Literal typeLiteral = Values.literal(Values.getValueFactory(), literal.getLiteral().getLabel(), type.getIri());
customQueryOptions.add(key, typeLiteral);
} else {
customQueryOptions.add(key, literal.getLiteral());
}
}
QueryOptionsPathElement queryOptionsPathElement = new QueryOptionsPathElement(this.repositoryContext);
queryOptionsPathElement.setCustomQueryOptions(customQueryOptions);
return queryOptionsPathElement;
}
use of com.inova8.pathql.element.LiteralValueElement in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitLiteral.
/**
* Visit literal.
*
* @param ctx the ctx
* @return the literal value element
*/
@Override
public LiteralValueElement visitLiteral(LiteralContext ctx) {
// rdfLiteral: (DQLITERAL | SQLITERAL) ('^^' (IRI_REF | qname) )? ;
LiteralValueElement literalElement = new LiteralValueElement(this.repositoryContext);
String literalValue = null;
if (ctx.DQLITERAL() == null) {
literalValue = ctx.SQLITERAL().getText();
} else {
literalValue = ctx.DQLITERAL().getText();
}
literalValue = literalValue.substring(1, literalValue.length() - 1);
IRI datatypeIRI = null;
if (ctx.IRI_REF() == null) {
if (ctx.qname() == null) {
literalElement.setLiteral(literal(literalValue));
} else {
IriRefValueElement qnameElement = visitQname(ctx.qname());
datatypeIRI = qnameElement.getIri();
literalElement.setLiteral(literal(literalValue, datatypeIRI));
}
} else {
String datatypeIRIString = ctx.IRI_REF().getText();
literalElement.setLiteral(literal(literalValue, datatypeIRIString));
}
// literalElement.setLiteral(literal(literalValue));
return literalElement;
}
Aggregations