Java Code Examples for com.hp.hpl.jena.query.QueryExecution#close()
The following examples show how to use
com.hp.hpl.jena.query.QueryExecution#close() .
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: IntegrationTestSupertypeLayer.java From SolRDF with Apache License 2.0 | 6 votes |
/** * Executes a given SELECT query against a given dataset. * * @param data the mistery guest containing test data (query and dataset) * @throws Exception never, otherwise the test fails. */ protected void selectTest(final MisteryGuest data) throws Exception { load(data); try { assertTrue( Arrays.toString(data.datasets) + ", " + data.query, ResultSetCompare.isomorphic( SOLRDF_CLIENT.select(queryString(data.query)), (inMemoryExecution = QueryExecutionFactory.create( QueryFactory.create(queryString(data.query)), memoryDataset)).execSelect())); } catch (final Throwable error) { log.debug("JNS\n" + ResultSetFormatter.asText(SOLRDF_CLIENT.select(queryString(data.query)))); QueryExecution debugExecution = null; log.debug("MEM\n" + ResultSetFormatter.asText( (debugExecution = (QueryExecutionFactory.create( QueryFactory.create(queryString(data.query)), memoryDataset))).execSelect())); debugExecution.close(); throw error; } }
Example 2
Source File: RDFStoreDAO.java From aliada-tool with GNU General Public License v3.0 | 6 votes |
/** * It executes a SELECT SPARQL query on the SPARQL endpoint. * * @param sparqlEndpointURI the SPARQL endpoint URI. * @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. * @return the {@link com.hp.hpl.jena.query.ResultSet} of the SELECT SPARQL query. * @since 2.0 */ public ResultSet executeSelect(final String sparqlEndpointURI, final String user, final String password, final String query) { ResultSet results = null; try { // Execute the query and obtain results final QueryExecution qexec = QueryExecutionFactory.sparqlService( sparqlEndpointURI, QueryFactory.create(query), auth(sparqlEndpointURI, user, password)); qexec.setTimeout(2000, 5000); results = qexec.execSelect() ; qexec.close() ; } catch (Exception exception) { LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query); } return results; }
Example 3
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 6 votes |
public List<? super PropertyResource> getPropertiesOfContext( String contextURI) { List<PropertyResource> propertyList = new ArrayList<PropertyResource>(); StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS).append("SELECT ?property FROM <") .append(MDRDatabase.BASE_URI).append("> WHERE {") .append("?property rdfs:subClassOf mdr:Property .") .append("?property mdr:having ?aic .") .append("?aic mdr:administeredItemContextContext <") .append(contextURI).append("> .").append("}"); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); PropertyResource prop = new PropertyImpl( qs.getResource("property"), mdrDatabase); propertyList.add(prop); } } finally { qexec.close(); } return propertyList; }
Example 4
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 6 votes |
/** * @param uri * URI of the Context * @return total number of Data Element's on specified Context */ public int getNumberOfDataElementsOfContext(String uri) { StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS) .append("SELECT (COUNT(DISTINCT ?de) as ?count) FROM <") .append(MDRDatabase.BASE_URI).append("> WHERE {") .append("?de rdfs:subClassOf mdr:DataElement .") .append("?de mdr:having ?aic .") .append("?aic mdr:administeredItemContextContext <") .append(uri).append("> .").append("}"); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); int size = 0; try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); size = qs.getLiteral("count").getInt(); } } finally { qexec.close(); } return size; }
Example 5
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 6 votes |
public int getNumberOfDEC(String objectClassURI) { StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS) .append("SELECT (COUNT (DISTINCT ?dec) as ?count) FROM <") .append(MDRDatabase.BASE_URI).append("> WHERE {") .append("?dec rdfs:subClassOf mdr:DataElementConcept .") .append("?dec mdr:dataElementConceptObjectClass <") .append(objectClassURI).append("> .").append("}"); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); int size = 0; try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); size = qs.getLiteral("count").getInt(); } } finally { qexec.close(); } return size; }
Example 6
Source File: HybridResponseWriter.java From SolRDF with Apache License 2.0 | 5 votes |
@Override public void write( final Writer writer, final SolrQueryRequest request, final SolrQueryResponse response) throws IOException { final NamedList<?> values = response.getValues(); final Query query = (Query)request.getContext().get(Names.QUERY); final QueryExecution execution = (QueryExecution)response.getValues().get(Names.QUERY_EXECUTION); try { final boolean isHybridMode = Boolean.TRUE.equals(request.getContext().get(Names.HYBRID_MODE)); if (isHybridMode) { response.add(Names.SOLR_REQUEST, request); response.add(Names.SOLR_RESPONSE, response); final String contentType = contentTypeRewrites.get(getContentType(request, false)); WriterStrategy strategy = compositeWriters.get(contentType); strategy = strategy != null ? strategy : compositeWriters.get("text/xml"); strategy.doWrite(values, writer, contentType); } else { if (query == null || execution == null) { LOGGER.error(MessageCatalog._00091_NULL_QUERY_OR_EXECUTION); return; } writers.get(query.getQueryType()).doWrite(values, writer, getContentType(request, false)); } } finally { if (execution != null) { // CHECKSTYLE:OFF try { execution.close();} catch (final Exception ignore) {} // CHECKSTYLE:ON } } }
Example 7
Source File: IntegrationTestSupertypeLayer.java From SolRDF with Apache License 2.0 | 5 votes |
/** * Executes a given CONSTRUCT query against a given dataset. * * @param data the mistery guest containing test data (query and dataset) * @throws Exception never, otherwise the test fails. */ protected void constructTest(final MisteryGuest data) throws Exception { load(data); try { inMemoryExecution = QueryExecutionFactory.create( QueryFactory.create(queryString(data.query)), memoryDataset); assertTrue( Arrays.toString(data.datasets) + ", " + data.query, inMemoryExecution.execConstruct().isIsomorphicWith( SOLRDF_CLIENT.construct(queryString(data.query)))); } catch (final Throwable error) { StringWriter writer = new StringWriter(); RDFDataMgr.write(writer, SOLRDF_CLIENT.construct(queryString(data.query)), RDFFormat.NTRIPLES); log.debug("JNS\n" + writer); QueryExecution debugExecution = QueryExecutionFactory.create( QueryFactory.create(queryString(data.query)), memoryDataset); writer = new StringWriter(); RDFDataMgr.write(writer, debugExecution.execConstruct(), RDFFormat.NTRIPLES); log.debug("MEM\n" + writer); debugExecution.close(); throw error; } }
Example 8
Source File: SolRDF.java From SolRDF with Apache License 2.0 | 5 votes |
/** * Executes a SPARQL CONSTRUCT. * * @param query the SPARQL CONSTRUCT Query. * @return the {@link Model} that includes the CONSTRUCT result. * @throws UnableToExecuteQueryException in case of failure before, during or after the query execution. */ public Model construct(final String constructQuery) throws UnableToExecuteQueryException { QueryExecution execution = null; try { return (execution = execution(constructQuery)).execConstruct(); } catch (final Exception exception) { throw new UnableToExecuteQueryException(exception); } finally { execution.close(); } }
Example 9
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 5 votes |
/** * With given objectClassURI, tihs method returns a list of all * {@link DataElementConcept}s whose {@link ObjectClass} is given * * @param objectClassURI * Unique URI of the ObjectClass * @return {@link DataElementConcept}s created with given ObjectClass */ public List<? super DataElementConceptResource> getDECSofOC( String objectClassURI, Integer limit, Integer offset) { StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS).append("SELECT ?dec FROM <") .append(MDRDatabase.BASE_URI).append("> WHERE {") .append("?dec rdfs:subClassOf mdr:DataElementConcept .") .append("?dec mdr:dataElementConceptObjectClass <") .append(objectClassURI).append("> .").append("}"); if (limit != null && offset != null) { queryString.append(" LIMIT ").append(limit).append(" OFFSET ") .append(offset); } QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); List<DataElementConceptResource> decResourceList = new ArrayList<DataElementConceptResource>(); try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); DataElementConceptResource ctx = new DataElementConceptImpl( qs.getResource("dec"), this.mdrDatabase); decResourceList.add(ctx); } } finally { qexec.close(); } return decResourceList; }
Example 10
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 5 votes |
public List<? super DataElementResource> getDataElementsOfContext( String contextURI, Integer limit, Integer offset) { List<DataElementResource> dataElementResourceList = new ArrayList<DataElementResource>(); StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS).append("SELECT ?de FROM <") .append(MDRDatabase.BASE_URI).append("> WHERE {") .append("?de rdfs:subClassOf mdr:DataElement .") .append("?de mdr:having ?aic .") .append("?aic mdr:administeredItemContextContext <") .append(contextURI).append("> .").append("}"); if (limit != null && offset != null) { queryString.append(" ORDER BY ?de ").append(" LIMIT ") .append(limit).append(" OFFSET ").append(offset); } QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); DataElementResource ctx = new DataElementImpl( qs.getResource("de"), this.mdrDatabase); dataElementResourceList.add(ctx); } } finally { qexec.close(); } return dataElementResourceList; }
Example 11
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 discovered links. * * @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 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 triples with the discovered links. * @since 2.0 */ public Triple[] getDiscoveredLinks(final String sparqlEndpointURI, final String graphName, final String user, final String password, final int offset, final int limit) { final String query = "select * FROM <" + graphName + "> " + "where {?source ?rel ?target }" + " ORDER BY ?source ?target" + " OFFSET " + offset + " LIMIT " + limit; ArrayList<Triple> linksList = new ArrayList<Triple>(); 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 sourceResType = soln.getResource("source"); final Resource targetResType = soln.getResource("target"); final Resource relResType = soln.getResource("rel"); final Triple triple = new Triple(sourceResType.asNode(), relResType.asNode(), targetResType.asNode()); linksList.add(triple); } qexec.close() ; } catch (Exception exception) { LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query); } if (linksList.isEmpty()) { return new Triple[0]; } return (Triple[]) linksList.toArray(new Triple[linksList.size()]); }
Example 12
Source File: VirtuosoQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 4 votes |
@Override public List<? super PropertyResource> searchProperty(String keyword, String contextURI, TextSearchType searchType) { List<PropertyResource> propertyList = new ArrayList<PropertyResource>(); StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS) .append("SELECT ?property FROM <") .append(MDRDatabase.BASE_URI) .append("> WHERE {") .append("?property rdfs:subClassOf mdr:Property .") .append("?property mdr:having ?aic .") .append("?aic mdr:administeredItemContextTerminologicalEntry ?te .") .append("?te mdr:containingTerminologicalEntryLanguage ?ls .") .append("?ls mdr:containingNameEntry ?designation .") .append("?designation mdr:name ?name ."); if (!Util.isNull(contextURI)) { queryString.append("?aic mdr:administeredItemContextContext <") .append(contextURI).append("> ."); } if (keyword.matches("\\s*")) { return propertyList; } if (searchType == null || searchType.equals(TextSearchType.Exact)) { queryString.append(exactMatchKeyword(keyword)); } else if (searchType.equals(TextSearchType.WildCard)) { queryString.append(atLeastOneKeyword(keyword)); } else { queryString.append(allWordsKeyword(keyword)); } queryString.append(" .}"); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); PropertyResource prop = new PropertyImpl( qs.getResource("property"), mdrDatabase); propertyList.add(prop); } } finally { qexec.close(); } return propertyList; }
Example 13
Source File: TDBQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 4 votes |
@Override public List<? super PropertyResource> searchProperty(String keyword, String contextURI, TextSearchType searchType) { List<PropertyResource> propertyList = new ArrayList<PropertyResource>(); StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_PF) .append(PREFIX_RDFS) .append("SELECT ?property FROM <") .append(MDRDatabase.BASE_URI) .append("> WHERE {") .append("?property rdfs:subClassOf mdr:Property .") .append("?property mdr:having ?aic .") .append("?aic mdr:administeredItemContextTerminologicalEntry ?te .") .append("?te mdr:containingTerminologicalEntryLanguage ?ls .") .append("?ls mdr:containingNameEntry ?designation .") .append("?designation mdr:name ?name ."); if (!Util.isNull(contextURI)) { queryString.append("?aic mdr:administeredItemContextContext <") .append(contextURI).append("> . "); } if (keyword.matches("\\s*")) { return propertyList; } if (searchType == null || searchType.equals(TextSearchType.Exact)) { queryString.append(exactMatchKeyword(keyword)); } else if (searchType.equals(TextSearchType.WildCard)) { queryString.append(atLeastOneKeyword(keyword)); } else { queryString.append(allWordsKeyword(keyword)); } queryString.append(" .}"); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); PropertyResource prop = new PropertyImpl( qs.getResource("property"), mdrDatabase); propertyList.add(prop); } } finally { qexec.close(); } return propertyList; }
Example 14
Source File: VirtuosoQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 4 votes |
@Override public int getNumberOfDataElementSearch(String keyword, String contextURI, TextSearchType searchType) { StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS) .append("SELECT (COUNT (DISTINCT ?de) as ?count) FROM <") .append(MDRDatabase.BASE_URI) .append("> WHERE {") .append("?de rdfs:subClassOf mdr:DataElement .") .append("?de mdr:having ?aic .") .append("?aic mdr:administeredItemContextTerminologicalEntry ?te .") .append("?te mdr:containingTerminologicalEntryLanguage ?ls .") .append("?ls mdr:containingNameEntry ?designation .") .append("?designation mdr:name ?name ."); if (!Util.isNull(contextURI)) { queryString.append("?aic mdr:administeredItemContextContext <") .append(contextURI).append("> ."); } // checks if keyword is empty if (keyword.matches("\\s*")) { return 0; } if (searchType == null || searchType.equals(TextSearchType.Exact)) { queryString.append(exactMatchKeyword(keyword)); } else if (searchType.equals(TextSearchType.WildCard)) { queryString.append(atLeastOneKeyword(keyword)); } else { queryString.append(allWordsKeyword(keyword)); } queryString.append(" .}"); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); int size = 0; try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); size = qs.getLiteral("count").getInt(); } } finally { qexec.close(); } return size; }
Example 15
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 16
Source File: TDBQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 4 votes |
@Override public List<? super ConceptualDomainResource> searchConceptualDomain( String keyword, String contextURI, TextSearchType searchType) { List<ConceptualDomainResource> cdList = new ArrayList<ConceptualDomainResource>(); StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_PF) .append(PREFIX_RDFS) .append("SELECT ?cd FROM <") .append(MDRDatabase.BASE_URI) .append("> WHERE {") .append("?cdClass rdfs:subClassOf mdr:ConceptualDomain .") .append("?cd rdfs:subClassOf ?cdClass .") .append("?cd mdr:having ?aic .") .append("?aic mdr:administeredItemContextTerminologicalEntry ?te .") .append("?te mdr:containingTerminologicalEntryLanguage ?ls .") .append("?ls mdr:containingNameEntry ?designation .") .append("?designation mdr:name ?name ."); if (!Util.isNull(contextURI)) { queryString.append("?aic mdr:administeredItemContextContext <") .append(contextURI).append("> ."); } if (keyword.matches("\\s*")) { return cdList; } if (searchType == null || searchType.equals(TextSearchType.Exact)) { queryString.append(exactMatchKeyword(keyword)); } else if (searchType.equals(TextSearchType.WildCard)) { queryString.append(atLeastOneKeyword(keyword)); } else { queryString.append(allWordsKeyword(keyword)); } queryString.append(" .}"); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); // here conceptualDomain is checked whether its enumerated or // not, proper instantiation is done OntClass res = qs.getResource("cd").as(OntClass.class); if (res.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedConceptualDomain)) { cdList.add(new EnumeratedConceptualDomainImpl(res, mdrDatabase)); } else { cdList.add(new NonEnumeratedConceptualDomainImpl(res, mdrDatabase)); } } } finally { qexec.close(); } return cdList; }
Example 17
Source File: TDBQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 4 votes |
@Override public List<? super DataElementResource> searchDataElement(String keyword, String contextURI, TextSearchType searchType, int limit, int offset) { List<DataElementResource> dataElementList = new ArrayList<DataElementResource>(); StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_PF) .append(PREFIX_RDFS) .append("SELECT ?de FROM <") .append(MDRDatabase.BASE_URI) .append("> WHERE {") .append("?de rdfs:subClassOf mdr:DataElement .") .append("?de mdr:having ?aic .") .append("?aic mdr:administeredItemContextTerminologicalEntry ?te .") .append("?te mdr:containingTerminologicalEntryLanguage ?ls .") .append("?ls mdr:containingNameEntry ?designation .") .append("?designation mdr:name ?name ."); if (!Util.isNull(contextURI)) { queryString.append("?aic mdr:administeredItemContextContext <") .append(contextURI).append("> ."); } if (keyword.matches("\\s*")) { return dataElementList; } if (searchType == null || searchType.equals(TextSearchType.Exact)) { queryString.append(exactMatchKeyword(keyword)); } else if (searchType.equals(TextSearchType.WildCard)) { queryString.append(atLeastOneKeyword(keyword)); } else { queryString.append(allWordsKeyword(keyword)); } queryString.append(" .} ORDER BY ?score LIMIT ").append(limit) .append(" OFFSET ").append(offset); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); DataElementResource de = new DataElementImpl( qs.getResource("de"), mdrDatabase); dataElementList.add(de); } } finally { qexec.close(); } return dataElementList; }
Example 18
Source File: TDBQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 4 votes |
@Override public int getNumberOfDataElementSearch(String keyword, String contextURI, TextSearchType searchType) { StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_PF) .append(PREFIX_RDFS) .append("SELECT (COUNT (DISTINCT ?de) as ?count) FROM <") .append(MDRDatabase.BASE_URI) .append("> WHERE {") .append("?de rdfs:subClassOf mdr:DataElement .") .append("?de mdr:having ?aic .") .append("?aic mdr:administeredItemContextTerminologicalEntry ?te .") .append("?te mdr:containingTerminologicalEntryLanguage ?ls .") .append("?ls mdr:containingNameEntry ?designation .") .append("?designation mdr:name ?name ."); if (!Util.isNull(contextURI)) { queryString.append("?aic mdr:administeredItemContextContext <") .append(contextURI).append("> ."); } if (keyword.matches("\\s*")) { return 0; } if (searchType == null || searchType.equals(TextSearchType.Exact)) { queryString.append(exactMatchKeyword(keyword)); } else if (searchType.equals(TextSearchType.WildCard)) { queryString.append(atLeastOneKeyword(keyword)); } else { queryString.append(allWordsKeyword(keyword)); } queryString.append(" .}"); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); int size = 0; try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); size = qs.getLiteral("count").getInt(); } } finally { qexec.close(); } return size; }
Example 19
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 4 votes |
public List<? super ValueDomainResource> getValueDomainsOfContext( String contextURI, Integer limit, Integer offset) { List<ValueDomainResource> valueDomainResourceList = new ArrayList<ValueDomainResource>(); StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS).append("SELECT ?vd FROM <") .append(MDRDatabase.BASE_URI).append("> WHERE {") .append("?vdClass rdfs:subClassOf mdr:ValueDomain .") .append("?vd rdfs:subClassOf mdr:vdClass . ") .append("?vd mdr:having ?aic .") .append("?aic mdr:administeredItemContextContext <") .append(contextURI).append("> .").append("}"); if (limit != null && offset != null) { queryString.append(" ORDER BY ?de ").append(" LIMIT ") .append(limit).append(" OFFSET ").append(offset); } QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); // here conceptualDomain is checked whether its enumerated or // not, proper instantiation is done OntClass res = mdrDatabase.getOntModel().getOntClass( qs.getResource("cd").getURI()); if (res.hasSuperClass(mdrDatabase.getVocabulary().EnumeratedValueDomain)) { valueDomainResourceList.add(new EnumeratedValueDomainImpl( res, mdrDatabase)); } else { valueDomainResourceList .add(new NonEnumeratedValueDomainImpl(res, mdrDatabase)); } } } finally { qexec.close(); } return valueDomainResourceList; }
Example 20
Source File: Sparql.java From DataHubSystem with GNU Affero General Public License v3.0 | 4 votes |
@Override public Object execute(Map<String, EdmLiteral> parameters) throws ODataException { EdmLiteral query_lit = parameters.remove("query"); // Olingo2 checks for presence of non-nullable parameters for us! String query_s = query_lit.getLiteral(); Query query = QueryFactory.create(query_s); if (!(query.isSelectType() || query.isDescribeType())) { throw new InvalidOperationException(query.getQueryType()); } DrbCortexModel cortexmodel; try { cortexmodel = DrbCortexModel.getDefaultModel(); } catch (IOException ex) { throw new RuntimeException(ex); } Model model = cortexmodel.getCortexModel().getOntModel(); QueryExecution qexec = null; // FIXME: QueryExecution in newer versions of Jena (post apache incubation) implement AutoClosable. try { qexec = QueryExecutionFactory.create(query, model); if (query.isSelectType()) { ResultSet results = qexec.execSelect(); return ResultSetFormatter.asXMLString(results); } else { Model description = qexec.execDescribe(); // newer version of Jena have the RIOT package for I/O StringWriter strwrt = new StringWriter(); Abbreviated abb = new Abbreviated(); abb.write(description, strwrt, null); return strwrt.toString(); } } finally { if (qexec != null) { qexec.close(); } } }