use of com.inova8.pathql.element.IriRefValueElement 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);
}
}
use of com.inova8.pathql.element.IriRefValueElement in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathParser method parsePredicate.
/**
* Parses the predicate.
*
* @param repositoryContext the repository context
* @param uriPattern the uri pattern
* @return the predicate element
* @throws RecognitionException the recognition exception
* @throws PathPatternException the path pattern exception
*/
public static PredicateElement parsePredicate(RepositoryContext repositoryContext, String uriPattern) throws RecognitionException, PathPatternException {
pathPatternVisitor = new PathPatternVisitor(repositoryContext);
CharStream input = CharStreams.fromString(uriPattern);
PathPatternLexer lexer = new PathPatternLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PathPatternParser parser = new PathPatternParser(tokens);
PathEltOrInverseContext pathPatternTree = parser.pathEltOrInverse();
PathElement iriRefValueElement = pathPatternVisitor.visit(pathPatternTree);
return (PredicateElement) iriRefValueElement;
}
use of com.inova8.pathql.element.IriRefValueElement in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitPredicateRef.
/**
* Visit predicate ref.
*
* @param ctx the ctx
* @return the iri ref value element
*/
@Override
public IriRefValueElement visitPredicateRef(PredicateRefContext ctx) {
// predicateRef : IRI_REF | rdfType | qname | pname_ns ;
IriRefValueElement predicateRefElement;
if (ctx.qname() != null) {
predicateRefElement = (IriRefValueElement) visit(ctx.qname());
} else if (ctx.pname_ns() != null) {
predicateRefElement = (IriRefValueElement) visit(ctx.pname_ns());
} else if (ctx.rdfType() != null) {
predicateRefElement = new IriRefValueElement(this.repositoryContext);
predicateRefElement.setIri(iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"));
} else {
predicateRefElement = new IriRefValueElement(this.repositoryContext);
String iri = ctx.IRI_REF().getText();
iri = iri.substring(1, iri.length() - 1);
predicateRefElement.setIri(iri(iri));
}
return predicateRefElement;
}
use of com.inova8.pathql.element.IriRefValueElement in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitIriRef.
/**
* Visit iri ref.
*
* @param ctx the ctx
* @return the iri ref value element
*/
@Override
public IriRefValueElement visitIriRef(IriRefContext ctx) {
// iriRef : IRI_REF | qname | pname_ns ;
IriRefValueElement iriRefElement = new IriRefValueElement(this.repositoryContext);
if (ctx.qname() != null) {
iriRefElement.setIri(((IriRefValueElement) visit(ctx.qname())).getIri());
} else if (ctx.pname_ns() != null) {
iriRefElement.setIri(((IriRefValueElement) visit(ctx.pname_ns())).getIri());
} else if (ctx.IRI_REF() != null) {
String iri = ctx.IRI_REF().getText();
iri = iri.substring(1, iri.length() - 1);
iriRefElement.setIri(iri(iri));
} else {
throw new ScriptFailedException(String.format("Error identifying iriRef %s", ctx.getText()));
}
return iriRefElement;
}
use of com.inova8.pathql.element.IriRefValueElement 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