use of com.inova8.pathql.element.PredicateElement in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitPredicate.
/**
* Visit predicate.
*
* @param ctx the ctx
* @return the predicate element
*/
@Override
public PredicateElement visitPredicate(PredicateContext ctx) {
// predicate : ( reifiedPredicate | predicateRef | rdfType | '*' ) factFilterPattern? #objectFilterPattern
PredicateElement predicateElement = null;
if (ctx.reifiedPredicate() != null) {
predicateElement = (PredicateElement) visit(ctx.reifiedPredicate());
predicateElement.setOperator(PathConstants.Operator.PREDICATE);
} else if (ctx.predicateRef() != null) {
predicateElement = new PredicateElement(this.repositoryContext);
predicateElement.setOperator(PathConstants.Operator.PREDICATE);
IriRefValueElement predicateRef = ((IriRefValueElement) visit(ctx.predicateRef()));
predicateElement.setPredicate(predicateRef.getIri());
} else if (ctx.rdfType() != null) {
predicateElement = new PredicateElement(this.repositoryContext);
predicateElement.setOperator(PathConstants.Operator.PREDICATE);
predicateElement.setPredicate((iri("http://rdftype")));
} else if (ctx.anyPredicate() != null) {
predicateElement = new PredicateElement(this.repositoryContext);
predicateElement.setOperator(PathConstants.Operator.PREDICATE);
predicateElement.setAnyPredicate(true);
}
if (ctx.factFilterPattern() != null) {
if (ctx.reifiedPredicate() != null) {
predicateElement.setStatementFilterElement((FactFilterElement) visit(ctx.factFilterPattern()));
} else {
predicateElement.setObjectFilterElement((FactFilterElement) visit(ctx.factFilterPattern()));
}
}
return predicateElement;
}
use of com.inova8.pathql.element.PredicateElement in project com.inova8.intelligentgraph by peterjohnlawrence.
the class PathPatternVisitor method visitPropertyListNotEmpty.
/**
* Visit property list not empty.
*
* @param ctx the ctx
* @return the fact filter element
*/
@Override
public FactFilterElement visitPropertyListNotEmpty(PropertyListNotEmptyContext ctx) {
// propertyListNotEmpty : verbObjectList ( ';' ( verbObjectList )? )* ;
FactFilterElement propertyListNotEmptyElement = new FactFilterElement(this.repositoryContext);
ArrayList<VerbObjectList> propertyListNotEmpty = new ArrayList<VerbObjectList>();
for (VerbObjectListContext verbObjectListContext : ctx.verbObjectList()) {
PathElement verb = visit(verbObjectListContext.verb());
ObjectListValueElement objectList = (ObjectListValueElement) visit(verbObjectListContext.objectList());
VerbObjectList verbObjectList = new VerbObjectList(this.repositoryContext);
if (verb instanceof ValueElement) {
verbObjectList.setFilterOperator(((FilterOperatorValueElement) verb).getFilterOperator());
} else if (verb instanceof PredicateElement) {
verbObjectList.setPredicate(((PredicateElement) verb));
}
verbObjectList.setObjectList(objectList.getObjectList());
propertyListNotEmpty.add(verbObjectList);
}
propertyListNotEmptyElement.setPropertyListNotEmpty(propertyListNotEmpty);
return propertyListNotEmptyElement;
}
use of com.inova8.pathql.element.PredicateElement 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.PredicateElement in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method addFact.
/**
* Adds the fact.
*
* @param thingresource the thingresource
* @param pathQL the path QL
* @param value the value
* @param contexts the contexts
* @throws RecognitionException the recognition exception
* @throws PathPatternException the path pattern exception
*/
private void addFact(Resource thingresource, String pathQL, Value value, Resource... contexts) throws RecognitionException, PathPatternException {
IntelligentGraphRepository source = IntelligentGraphRepository.create(this);
Thing thing = Thing.create(source, thingresource, null);
PredicateElement predicateElement = (PredicateElement) PathParser.parsePathPattern(source.getRepositoryContext(), pathQL);
predicateElement.getSourceVariable().setValue(thing.getValue());
if (predicateElement.getIsReified()) {
ReificationType reificationType = source.getRepositoryContext().getReificationTypes().get(predicateElement.getReification().stringValue());
if (reificationType != null) {
IRI reification = iri(reificationType.getReificationType().stringValue() + "/" + thing.getIRI().hashCode() + "." + predicateElement.getPredicate().hashCode() + "." + value.hashCode());
super.addStatement(reification, RDF.TYPE, predicateElement.getReification(), contexts);
super.addStatement(reification, reificationType.getReificationSubject(), thing.getIRI(), contexts);
super.addStatement(reification, reificationType.getReificationPredicate(), predicateElement.getPredicate(), contexts);
super.addStatement(reification, reificationType.getReificationObject(), value, contexts);
} else {
logger.error("Reified type not supported:" + predicateElement.toString());
}
} else {
IRI propertyIri = predicateElement.getPredicate();
super.addStatement(thing.getIRI(), propertyIri, value, contexts);
checkReificationsChanged(propertyIri);
}
}
Aggregations