/** * Create a QueryExecution that will access a SPARQL service over HTTP * * @param service URL of the remote service * @param query Query to execute * @param defaultGraph URI of the default graph * @return QueryExecution */ public static QueryExecution sparqlService(String service, Query query, String defaultGraph) { checkNotNull(service, "URL for service is null"); // checkNotNull(defaultGraph, "IRI for default graph is null") ; checkArg(query); QueryEngineHTTP qe = createServiceRequest(service, query); qe.addDefaultGraph(defaultGraph); return qe; }
@Override public QueryExecution execute(Query query) { if (log.isDebugEnabled()) log.debug("Running query on " + sparqlEndpoint + ":\n" + query); QueryEngineHTTP qe = new QueryEngineHTTP(sparqlEndpoint, query); // System.err.println( ">> basic user: "******">> basic password: " + new String(basicPassword)); if (basicUser != null) qe.setBasicAuthentication(basicUser, basicPassword); return qe; }
/** * Create a QueryExecution that will access a SPARQL service over HTTP * * @param service URL of the remote service * @param query Query to execute * @param defaultGraphURIs List of URIs to make up the default graph * @param namedGraphURIs List of URIs to make up the named graphs * @return QueryExecution */ public static QueryExecution sparqlService( String service, Query query, List<String> defaultGraphURIs, List<String> namedGraphURIs) { checkNotNull(service, "URL for service is null"); // checkNotNull(defaultGraphURIs, "List of default graph URIs is null") ; // checkNotNull(namedGraphURIs, "List of named graph URIs is null") ; checkArg(query); QueryEngineHTTP qe = createServiceRequest(service, query); if (defaultGraphURIs != null) qe.setDefaultGraphURIs(defaultGraphURIs); if (namedGraphURIs != null) qe.setNamedGraphURIs(namedGraphURIs); return qe; }
@Override public void processInput(Resource input, Resource output) { final Model model = ModelFactory.createDefaultModel(); final List<Statement> tipURIs = input.listProperties(Vocab.has).toList(); final SublistIterator<Statement> tipsIterator = new SublistIterator<Statement>(tipURIs, QUERY_CHUNK_SIZE); while (tipsIterator.hasNext()) { final List<String> ancestorQueryBlocks = new ArrayList<String>(); final List<String> parentQueryBlocks = new ArrayList<String>(); final List<Statement> tips = tipsIterator.next(); for (Statement statement : tips) { final String tipURI = statement.getResource().getProperty(DC.subject).getResource().getURI(); ancestorQueryBlocks.add(String.format(ancestorQueryBody, tipURI)); parentQueryBlocks.add(String.format(parentQueryBody, tipURI)); } final String ancestorQuery = String.format(ancestorQueryHead, StringUtils.join(ancestorQueryBlocks, " UNION ")); final String parentQuery = String.format(parentQueryHead, StringUtils.join(parentQueryBlocks, ", ")); QueryEngineHTTP ancestorQE = new QueryEngineHTTP(endpoint, ancestorQuery); QueryEngineHTTP parentQE = new QueryEngineHTTP(endpoint, parentQuery); ancestorQE.execConstruct(model); ancestorQE.close(); parentQE.execConstruct(model); parentQE.close(); } this.processNode(Vocab.TaxonomyRoot, model, output.getModel(), null, output); output.getModel().setNsPrefix("cdao", "http://www.evolutionaryontology.org/cdao/1.0/cdao.owl#"); }