Search in sources :

Example 1 with WrongArityException

use of fr.lirmm.graphik.graal.api.store.WrongArityException in project graal by graphik-team.

the class RDF4jUtils method atomToStatement.

// /////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
// /////////////////////////////////////////////////////////////////////////
public Statement atomToStatement(Atom atom) throws WrongArityException, MalformedLangStringException {
    if (atom.getPredicate().getArity() != 2) {
        throw new WrongArityException("Error on " + atom + ": arity " + atom.getPredicate().getArity() + " is not supported by this store. ");
    }
    IRI predicate = this.createURI(atom.getPredicate());
    IRI term0 = this.createURI(atom.getTerm(0));
    Value term1 = this.createValue(atom.getTerm(1));
    return valueFactory.createStatement(term0, predicate, term1);
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) WrongArityException(fr.lirmm.graphik.graal.api.store.WrongArityException) Value(org.eclipse.rdf4j.model.Value)

Example 2 with WrongArityException

use of fr.lirmm.graphik.graal.api.store.WrongArityException in project graal by graphik-team.

the class RDF4jStore method termsByPredicatePosition.

@Override
public CloseableIterator<Term> termsByPredicatePosition(Predicate p, int position) throws AtomSetException {
    TupleQuery query = null;
    TupleQueryResult results = null;
    try {
        if (position == 0) {
            query = this.connection.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT DISTINCT ?x WHERE { ?x <" + utils.createURI(p) + "> ?y }");
        } else if (position == 1) {
            query = this.connection.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT DISTINCT ?x WHERE { ?y <" + utils.createURI(p) + "> ?x }");
        } else {
            throw new WrongArityException("Position should be 0 for subject or 1 for object.");
        }
        results = query.evaluate();
    } catch (RepositoryException e) {
        throw new AtomSetException(e);
    } catch (MalformedQueryException e) {
        throw new AtomSetException(e);
    } catch (QueryEvaluationException e) {
        throw new AtomSetException(e);
    }
    return new TermsIterator(results, "x", this.utils);
}
Also used : QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) WrongArityException(fr.lirmm.graphik.graal.api.store.WrongArityException) AtomSetException(fr.lirmm.graphik.graal.api.core.AtomSetException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) TupleQuery(org.eclipse.rdf4j.query.TupleQuery) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Aggregations

WrongArityException (fr.lirmm.graphik.graal.api.store.WrongArityException)2 AtomSetException (fr.lirmm.graphik.graal.api.core.AtomSetException)1 IRI (org.eclipse.rdf4j.model.IRI)1 Value (org.eclipse.rdf4j.model.Value)1 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)1 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)1 TupleQuery (org.eclipse.rdf4j.query.TupleQuery)1 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)1 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)1