Search in sources :

Example 1 with ParseError

use of fr.lirmm.graphik.graal.api.io.ParseError in project graal by graphik-team.

the class Producer method run.

@Override
public void run() {
    org.eclipse.rdf4j.rio.RDFParser rdfParser = Rio.createParser(format);
    if (this.config != null) {
        rdfParser.setParserConfig(config);
    }
    rdfParser.setRDFHandler(new RDFListener(buffer));
    try {
        rdfParser.parse(this.reader, "");
    } catch (RDFParseException e) {
        throw new ParseError("An error occured while parsing", e);
    } catch (RDFHandlerException e) {
        throw new ParseError("An error occured while parsing", e);
    } catch (IOException e) {
        throw new ParseError("An error occured while parsing", e);
    }
    buffer.close();
    try {
        this.reader.close();
    } catch (IOException e) {
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) ParseError(fr.lirmm.graphik.graal.api.io.ParseError) IOException(java.io.IOException) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 2 with ParseError

use of fr.lirmm.graphik.graal.api.io.ParseError in project graal by graphik-team.

the class AbstractDlgpListener method endsConjunction.

@Override
public void endsConjunction(OBJECT_TYPE objectType) {
    switch(objectType) {
        case QUERY:
            Set<Variable> bodyVars = this.atomSet.getVariables();
            for (Term t : this.answerVars) {
                if (t.isVariable() && !bodyVars.contains(t)) {
                    throw new ParseError("The variable [" + t + "] of the answer list does not appear in the query body.");
                }
            }
            this.createQuery(DefaultConjunctiveQueryFactory.instance().create(this.label, this.atomSet, this.answerVars));
            break;
        case NEG_CONSTRAINT:
            this.createNegConstraint(new DefaultNegativeConstraint(this.label, this.atomSet));
            break;
        case RULE:
            if (this.atomSet2 == null) {
                this.atomSet2 = this.atomSet;
                this.atomSet = new LinkedListAtomSet();
            } else {
                this.createRule(DefaultRuleFactory.instance().create(this.label, this.atomSet, this.atomSet2));
            }
            break;
        case FACT:
            this.createAtomSet(this.atomSet);
            break;
        default:
            break;
    }
}
Also used : DefaultNegativeConstraint(fr.lirmm.graphik.graal.core.DefaultNegativeConstraint) Variable(fr.lirmm.graphik.graal.api.core.Variable) LinkedListAtomSet(fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet) ParseError(fr.lirmm.graphik.graal.api.io.ParseError) Term(fr.lirmm.graphik.graal.api.core.Term)

Example 3 with ParseError

use of fr.lirmm.graphik.graal.api.io.ParseError in project graal by graphik-team.

the class SparqlConjunctiveQueryParser method execute.

// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
private void execute(String queryString) {
    this.prefixes = new LinkedList<Prefix>();
    List<Term> ans = new LinkedList<Term>();
    Query sparql = QueryFactory.create(queryString);
    for (Map.Entry<String, String> e : sparql.getPrefixMapping().getNsPrefixMap().entrySet()) {
        this.prefixes.add(new Prefix(e.getKey(), e.getValue()));
    }
    if (sparql.isSelectType()) {
        for (String v : sparql.getResultVars()) {
            ans.add(DefaultTermFactory.instance().createVariable(v));
        }
    }
    ElementVisitorImpl visitor = new ElementVisitorImpl(DefaultAtomSetFactory.instance().create());
    sparql.getQueryPattern().visit(visitor);
    // check if answer variables appear in the query body
    Set<Variable> bodyVars = visitor.getAtomSet().getVariables();
    for (Term t : ans) {
        if (t.isVariable() && !bodyVars.contains(t)) {
            throw new ParseError("The variable [" + t + "] of the answer list does not appear in the query body.");
        }
    }
    this.query = DefaultConjunctiveQueryFactory.instance().create(visitor.getAtomSet(), ans);
}
Also used : Variable(fr.lirmm.graphik.graal.api.core.Variable) ConjunctiveQuery(fr.lirmm.graphik.graal.api.core.ConjunctiveQuery) Query(org.apache.jena.query.Query) Prefix(fr.lirmm.graphik.util.Prefix) Term(fr.lirmm.graphik.graal.api.core.Term) LinkedList(java.util.LinkedList) ParseError(fr.lirmm.graphik.graal.api.io.ParseError) Map(java.util.Map)

Aggregations

ParseError (fr.lirmm.graphik.graal.api.io.ParseError)3 Term (fr.lirmm.graphik.graal.api.core.Term)2 Variable (fr.lirmm.graphik.graal.api.core.Variable)2 ConjunctiveQuery (fr.lirmm.graphik.graal.api.core.ConjunctiveQuery)1 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)1 LinkedListAtomSet (fr.lirmm.graphik.graal.core.atomset.LinkedListAtomSet)1 Prefix (fr.lirmm.graphik.util.Prefix)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Query (org.apache.jena.query.Query)1 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)1 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)1