Search in sources :

Example 11 with BindingSet

use of org.eclipse.rdf4j.query.BindingSet in project rdf4j by eclipse.

the class HTTPRepositoryConnection method getNamespaces.

public RepositoryResult<Namespace> getNamespaces() throws RepositoryException {
    try {
        List<Namespace> namespaceList = new ArrayList<Namespace>();
        TupleQueryResult namespaces = client.getNamespaces();
        try {
            while (namespaces.hasNext()) {
                BindingSet bindingSet = namespaces.next();
                Value prefix = bindingSet.getValue("prefix");
                Value namespace = bindingSet.getValue("namespace");
                if (prefix instanceof Literal && namespace instanceof Literal) {
                    String prefixStr = ((Literal) prefix).getLabel();
                    String namespaceStr = ((Literal) namespace).getLabel();
                    namespaceList.add(new SimpleNamespace(prefixStr, namespaceStr));
                }
            }
        } finally {
            namespaces.close();
        }
        return createRepositoryResult(namespaceList);
    } catch (QueryEvaluationException e) {
        throw new RepositoryException(e);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Literal(org.eclipse.rdf4j.model.Literal) ArrayList(java.util.ArrayList) Value(org.eclipse.rdf4j.model.Value) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult) Namespace(org.eclipse.rdf4j.model.Namespace) SimpleNamespace(org.eclipse.rdf4j.model.impl.SimpleNamespace) SimpleNamespace(org.eclipse.rdf4j.model.impl.SimpleNamespace)

Example 12 with BindingSet

use of org.eclipse.rdf4j.query.BindingSet in project rdf4j by eclipse.

the class RemoteRepositoryManager method getAllRepositoryInfos.

@Override
public Collection<RepositoryInfo> getAllRepositoryInfos(boolean skipSystemRepo) throws RepositoryException {
    List<RepositoryInfo> result = new ArrayList<RepositoryInfo>();
    try (RDF4JProtocolSession httpClient = getSesameClient().createRDF4JProtocolSession(serverURL)) {
        httpClient.setUsernameAndPassword(username, password);
        TupleQueryResult responseFromServer = httpClient.getRepositoryList();
        while (responseFromServer.hasNext()) {
            BindingSet bindingSet = responseFromServer.next();
            RepositoryInfo repInfo = new RepositoryInfo();
            String id = Literals.getLabel(bindingSet.getValue("id"), null);
            if (skipSystemRepo && id.equals(SystemRepository.ID)) {
                continue;
            }
            Value uri = bindingSet.getValue("uri");
            String description = Literals.getLabel(bindingSet.getValue("title"), null);
            boolean readable = Literals.getBooleanValue(bindingSet.getValue("readable"), false);
            boolean writable = Literals.getBooleanValue(bindingSet.getValue("writable"), false);
            if (uri instanceof IRI) {
                try {
                    repInfo.setLocation(new URL(uri.toString()));
                } catch (MalformedURLException e) {
                    logger.warn("Server reported malformed repository URL: {}", uri);
                }
            }
            repInfo.setId(id);
            repInfo.setDescription(description);
            repInfo.setReadable(readable);
            repInfo.setWritable(writable);
            result.add(repInfo);
        }
    } catch (IOException ioe) {
        logger.warn("Unable to retrieve list of repositories", ioe);
        throw new RepositoryException(ioe);
    } catch (QueryEvaluationException qee) {
        logger.warn("Unable to retrieve list of repositories", qee);
        throw new RepositoryException(qee);
    } catch (UnauthorizedException ue) {
        logger.warn("Not authorized to retrieve list of repositories", ue);
        throw new RepositoryException(ue);
    } catch (RepositoryException re) {
        logger.warn("Unable to retrieve list of repositories", re);
        throw re;
    }
    return result;
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) IRI(org.eclipse.rdf4j.model.IRI) MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException) URL(java.net.URL) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Value(org.eclipse.rdf4j.model.Value) UnauthorizedException(org.eclipse.rdf4j.http.protocol.UnauthorizedException) RDF4JProtocolSession(org.eclipse.rdf4j.http.client.RDF4JProtocolSession) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Example 13 with BindingSet

use of org.eclipse.rdf4j.query.BindingSet in project rdf4j by eclipse.

the class HTTPRepositoryConnection method getContextIDs.

public RepositoryResult<Resource> getContextIDs() throws RepositoryException {
    try {
        List<Resource> contextList = new ArrayList<Resource>();
        TupleQueryResult contextIDs = client.getContextIDs();
        try {
            while (contextIDs.hasNext()) {
                BindingSet bindingSet = contextIDs.next();
                Value context = bindingSet.getValue("contextID");
                if (context instanceof Resource) {
                    contextList.add((Resource) context);
                }
            }
        } finally {
            contextIDs.close();
        }
        return createRepositoryResult(contextList);
    } catch (QueryEvaluationException e) {
        throw new RepositoryException(e);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Resource(org.eclipse.rdf4j.model.Resource) ArrayList(java.util.ArrayList) Value(org.eclipse.rdf4j.model.Value) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException) TupleQueryResult(org.eclipse.rdf4j.query.TupleQueryResult)

Example 14 with BindingSet

use of org.eclipse.rdf4j.query.BindingSet in project rdf4j by eclipse.

the class InsertBindingSetCursor method next.

@Override
public BindingSet next() throws QueryEvaluationException {
    BindingSet next = super.next();
    if (next == null) {
        return null;
    }
    int size = bindings.size() + next.size();
    SPARQLQueryBindingSet set = new SPARQLQueryBindingSet(size);
    set.addAll(bindings);
    for (Binding binding : next) {
        set.setBinding(binding);
    }
    return set;
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) BindingSet(org.eclipse.rdf4j.query.BindingSet)

Example 15 with BindingSet

use of org.eclipse.rdf4j.query.BindingSet in project graal by graphik-team.

the class TupleQueryResultAtomIterator method next.

@Override
public Atom next() throws IteratorException {
    BindingSet bs = this.it.next();
    Term[] terms = new Term[atom.getTerms().size()];
    int i = 0;
    for (Term t : atom) {
        if (t.isVariable()) {
            terms[i] = utils.valueToTerm(bs.getValue(t.getLabel()));
        } else {
            terms[i] = t;
        }
        ++i;
    }
    return DefaultAtomFactory.instance().create(atom.getPredicate(), terms);
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) Term(fr.lirmm.graphik.graal.api.core.Term)

Aggregations

BindingSet (org.eclipse.rdf4j.query.BindingSet)28 ArrayList (java.util.ArrayList)9 IRI (org.eclipse.rdf4j.model.IRI)8 Value (org.eclipse.rdf4j.model.Value)8 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)6 TupleQueryResult (org.eclipse.rdf4j.query.TupleQueryResult)6 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)6 IOException (java.io.IOException)5 Literal (org.eclipse.rdf4j.model.Literal)5 Binding (org.eclipse.rdf4j.query.Binding)5 ListBindingSet (org.eclipse.rdf4j.query.impl.ListBindingSet)5 InputStream (java.io.InputStream)4 BNode (org.eclipse.rdf4j.model.BNode)4 AbstractQueryResultIOTupleTest (org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOTupleTest)4 QueryResultCollector (org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector)4 SPARQLResultsJSONParser (org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLResultsJSONParser)4 Test (org.junit.Test)4 Resource (org.eclipse.rdf4j.model.Resource)3 Var (org.eclipse.rdf4j.query.algebra.Var)3 InputStreamReader (java.io.InputStreamReader)2