Java Code Examples for com.hp.hpl.jena.rdf.model.Resource#getURI()
The following examples show how to use
com.hp.hpl.jena.rdf.model.Resource#getURI() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpecificAPIDataset.java From aliada-tool with GNU General Public License v3.0 | 6 votes |
/** * It executes a SELECT SPARQL query on the SPARQL endpoint, to get * the URIs of the resources to use to discover links towards external datasets. * * @param sparqlEndpointURI the SPARQL endpoint URI. * @param graphName the graphName, null in case of default graph. * @param user the user name for the SPARQl endpoint. * @param password the password for the SPARQl endpoint. * @param query the query to use to look for the resources. * @param offset causes the solutions generated to start after the * specified number of solutions. * @param limit upper bound on the number of solutions returned. * @return a list of the matched URIs. * @since 2.0 */ public ResourceToLink[] getResourcesToLink(final String sparqlEndpointURI, final String user, final String password, final String sparql, final Integer offset, final Integer limit) { final ArrayList<ResourceToLink> resourcesList = new ArrayList<ResourceToLink>(); final String query = sparql + " OFFSET " + offset + " LIMIT " + limit; // Execute the query and obtain results final ResultSet results = rdfstoreDAO.executeSelect(sparqlEndpointURI, user, password, query); if (results != null){ while (results.hasNext()) { final QuerySolution soln = results.nextSolution() ; final Resource res = soln.getResource("res"); final String resURI = res.getURI(); final String textToSearch = soln.getLiteral("text").getString(); final ResourceToLink resToLink = new ResourceToLink(textToSearch, resURI); resourcesList.add(resToLink); } } if (resourcesList.isEmpty()) { return new ResourceToLink[0]; } return (ResourceToLink[]) resourcesList.toArray(new ResourceToLink[resourcesList.size()]); }
Example 2
Source File: DirectoryServlet.java From GeoTriples with Apache License 2.0 | 5 votes |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { D2RServer server = D2RServer.fromServletContext(getServletContext()); server.checkMappingFileChanged(); if (request.getPathInfo() == null) { response.sendError(404); return; } String classMapName = request.getPathInfo().substring(1); int limit = server.getConfig().getLimitPerClassMap(); Model resourceList = server.getMapping().getResourceCollection(classMapName).getInventoryModel(limit); if (resourceList == null) { response.sendError(404, "Sorry, class map '" + classMapName + "' not found."); return; } Map<String,String> resources = new TreeMap<String,String>(); ResIterator subjects = resourceList.listSubjects(); while (subjects.hasNext()) { Resource resource = subjects.nextResource(); if (!resource.isURIResource()) { continue; } String uri = resource.getURI(); Statement labelStmt = PageServlet.getBestLabel(resource); String label = (labelStmt == null) ? resource.getURI() : labelStmt.getString(); resources.put(uri, label); } Map<String,String> classMapLinks = new TreeMap<String,String>(); for (String name: server.getMapping().getResourceCollectionNames()) { classMapLinks.put(name, server.baseURI() + "directory/" + name); } VelocityWrapper velocity = new VelocityWrapper(this, request, response); Context context = velocity.getContext(); context.put("rdf_link", server.baseURI() + "all/" + classMapName); context.put("classmap", classMapName); context.put("classmap_links", classMapLinks); context.put("resources", resources); context.put("limit_per_class_map", server.getConfig().getLimitPerClassMap()); velocity.mergeTemplateXHTML("directory_page.vm"); }
Example 3
Source File: RDFStoreDAO.java From aliada-tool with GNU General Public License v3.0 | 5 votes |
/** * It executes a SELECT SPARQL query on the SPARQL endpoint, * to get the resources specified in the query argument. * * @param query the query to execute to get the resources. * @param sparqlEndpointURI the SPARQL endpoint URI. * @param user the user name for the SPARQl endpoint. * @param password the password for the SPARQl endpoint. * @param offset causes the solutions generated to start after * the specified number of solutions. * @param limit upper bound on the number of solutions returned. * @return a list of {@link eu.aliada.shared.rdfstore.RetrievedResource} with the resources. * @since 2.0 */ public RetrievedResource[] getResources(final String query, final String sparqlEndpointURI, final String user, final String password, final int offset, final int limit) { final ArrayList<RetrievedResource> resList = new ArrayList<RetrievedResource>(); try { // Execute the query and obtain results final QueryExecution qexec = QueryExecutionFactory.sparqlService( sparqlEndpointURI, QueryFactory.create(query), auth(sparqlEndpointURI, user, password)); qexec.setTimeout(2000, 5000); final ResultSet results = qexec.execSelect() ; while (results.hasNext()) { final QuerySolution soln = results.nextSolution() ; final Resource res = soln.getResource("res"); String name = ""; if(soln.contains("name")) { name = soln.getLiteral("name").getString(); } final RetrievedResource retrievedRes = new RetrievedResource(res.getURI(), name); resList.add(retrievedRes); } qexec.close() ; } catch (Exception exception) { LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query); } if (resList.isEmpty()) { return new RetrievedResource[0]; } return (RetrievedResource[]) resList.toArray(new RetrievedResource[resList.size()]); }
Example 4
Source File: Database.java From GeoTriples with Apache License 2.0 | 4 votes |
public void setStartupSQLScript(Resource script) { assertNotYetDefined(startupSQLScript, D2RQ.startupSQLScript, D2RQException.DATABASE_DUPLICATE_STARTUPSCRIPT); startupSQLScript = script.getURI(); }
Example 5
Source File: RDFStoreDAO.java From aliada-tool with GNU General Public License v3.0 | 4 votes |
/** * It executes a SELECT SPARQL query on the SPARQL endpoint, to get the * URIs of a type from ALIADA ontology. * * @param sparqlEndpointURI the SPARQL endpoint URI. * @param user the user name for the SPARQl endpoint. * @param password the password for the SPARQl endpoint. * @param typeLabel the label value of the type to search for. * @return a list of URIs with the matched types. * @since 1.0 */ public String[] getOntologyTypeURI(final String sparqlEndpointURI, final String user, final String password, final String typeLabel) { final String query = "select distinct ?type FROM <http://aliada-project.eu/2014/aliada-ontology#> " + "where {?type a <http://www.w3.org/2004/02/skos/core#Concept> . " + "?type <http://www.w3.org/2004/02/skos/core#prefLabel> ?label . " + "FILTER regex(str(?label), \"^" + typeLabel + "$\")}"; final ArrayList<String> typesList = new ArrayList<String>(); QueryExecution qexec = null; try { // Execute the query and obtain results qexec = QueryExecutionFactory.sparqlService( sparqlEndpointURI, QueryFactory.create(query), auth(sparqlEndpointURI, user, password)); if (qexec instanceof QueryEngineHTTP) { ((QueryEngineHTTP)qexec).setTimeout(2000L, 5000L); } final ResultSet results = qexec.execSelect() ; while (results.hasNext()) { final QuerySolution soln = results.nextSolution() ; final Resource resType = soln.getResource("type"); final String type = resType.getURI(); typesList.add(type); } } catch (Exception exception) { LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query); } finally { try { qexec.close(); } catch (Exception e) { // Ignore } } if (typesList.isEmpty()) { return new String[0]; } return (String[]) typesList.toArray(new String[typesList.size()]); }
Example 6
Source File: LocalResource.java From r2rml-parser with Apache License 2.0 | 4 votes |
/** * Create a local resource based on a jena model resource */ public LocalResource(Resource r) { //log.info("About to create " + r.getURI()); if (r.isAnon()) { log.info("Found a blank node"); this.blankNode = Boolean.TRUE; this.uri = null; this.uriEncoded = null; this.localName = r.getId().getLabelString(); this.namespace = null; } else { //log.info("Node URI: " + r.getURI()); this.prefixMap = r.getModel().getNsPrefixMap(); if (r.isLiteral()) { this.literal = Boolean.TRUE; //log.info("Found a literal with URI: " + r.getURI()); } else if (r.isResource()) { //log.info("Found a resource with URI: " + r.getURI()); this.resource = Boolean.TRUE; this.uri = r.getURI(); try { uriEncoded = URLEncoder.encode(r.getURI(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } namespace = r.getNameSpace(); if (namespace.contains("#")) { String prefix = findPrefixByUri(namespace); if (prefix == null) { this.localName = r.getURI(); } else { this.localName = findPrefixByUri(namespace) + ":" + r.getLocalName(); } } else { this.localName = r.getURI(); } log.info("Local resource: " + localName); } } }
Example 7
Source File: ConstantIRI.java From GeoTriples with Apache License 2.0 | 2 votes |
/** * Always succeeds. Check {@link #isValid()} to see if syntax is ok. * @return <code>null</code> if arg is <code>null</code> */ public static ConstantIRI create(Resource iri) { return iri == null ? null : new ConstantIRI(iri.getURI()); }