Search in sources :

Example 6 with PredicateElement

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;
}
Also used : PredicateElement(com.inova8.pathql.element.PredicateElement) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement)

Example 7 with 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;
}
Also used : ObjectListValueElement(com.inova8.pathql.element.ObjectListValueElement) ValueElement(com.inova8.pathql.element.ValueElement) ObjectListValueElement(com.inova8.pathql.element.ObjectListValueElement) IriRefValueElement(com.inova8.pathql.element.IriRefValueElement) FilterOperatorValueElement(com.inova8.pathql.element.FilterOperatorValueElement) LiteralValueElement(com.inova8.pathql.element.LiteralValueElement) SequencePathElement(com.inova8.pathql.element.SequencePathElement) BoundPathElement(com.inova8.pathql.element.BoundPathElement) PathElement(com.inova8.pathql.element.PathElement) AlternativePathElement(com.inova8.pathql.element.AlternativePathElement) QueryOptionsPathElement(com.inova8.pathql.element.QueryOptionsPathElement) VerbObjectListContext(com.inova8.pathql.pathPattern.PathPatternParser.VerbObjectListContext) PredicateElement(com.inova8.pathql.element.PredicateElement) ArrayList(java.util.ArrayList) VerbObjectList(com.inova8.pathql.element.VerbObjectList) FactFilterElement(com.inova8.pathql.element.FactFilterElement)

Example 8 with PredicateElement

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;
}
Also used : PathPatternVisitor(com.inova8.pathql.processor.PathPatternVisitor) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) PathElement(com.inova8.pathql.element.PathElement) PredicateElement(com.inova8.pathql.element.PredicateElement) PathPatternParser(com.inova8.pathql.pathPattern.PathPatternParser) PathPatternLexer(com.inova8.pathql.pathPattern.PathPatternLexer) PathEltOrInverseContext(com.inova8.pathql.pathPattern.PathPatternParser.PathEltOrInverseContext) CharStream(org.antlr.v4.runtime.CharStream)

Example 9 with PredicateElement

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);
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) IntelligentGraphRepository(com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository) ReificationType(com.inova8.pathql.context.ReificationType) PredicateElement(com.inova8.pathql.element.PredicateElement) Thing(com.inova8.intelligentgraph.model.Thing)

Aggregations

PredicateElement (com.inova8.pathql.element.PredicateElement)7 IRI (org.eclipse.rdf4j.model.IRI)5 IntelligentGraphRepository (com.inova8.intelligentgraph.intelligentGraphRepository.IntelligentGraphRepository)4 Thing (com.inova8.intelligentgraph.model.Thing)4 CustomQueryOptions (com.inova8.intelligentgraph.context.CustomQueryOptions)2 EvaluationContext (com.inova8.intelligentgraph.evaluator.EvaluationContext)2 ReificationType (com.inova8.pathql.context.ReificationType)2 IriRefValueElement (com.inova8.pathql.element.IriRefValueElement)2 PathElement (com.inova8.pathql.element.PathElement)2 Value (org.eclipse.rdf4j.model.Value)2 ValueExprEvaluationException (org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException)2 AlternativePathElement (com.inova8.pathql.element.AlternativePathElement)1 BoundPathElement (com.inova8.pathql.element.BoundPathElement)1 FactFilterElement (com.inova8.pathql.element.FactFilterElement)1 FilterOperatorValueElement (com.inova8.pathql.element.FilterOperatorValueElement)1 LiteralValueElement (com.inova8.pathql.element.LiteralValueElement)1 ObjectListValueElement (com.inova8.pathql.element.ObjectListValueElement)1 QueryOptionsPathElement (com.inova8.pathql.element.QueryOptionsPathElement)1 SequencePathElement (com.inova8.pathql.element.SequencePathElement)1 ValueElement (com.inova8.pathql.element.ValueElement)1