Java Code Examples for com.hp.hpl.jena.query.QuerySolution#getResource()
The following examples show how to use
com.hp.hpl.jena.query.QuerySolution#getResource() .
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: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 6 votes |
/** * @return all of the {@link Datatype}s */ public List<? super DatatypeResource> getDatatypes() { StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS).append(PREFIX_XSD) .append("SELECT ?datatype FROM <").append(MDRDatabase.BASE_URI) .append("> WHERE {") .append("?datatype rdfs:subClassOf mdr:Datatype }"); List<DatatypeResource> datatypeList = new ArrayList<DatatypeResource>(); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); Resource res = qs.getResource("datatype"); datatypeList.add(new DatatypeImpl(res, mdrDatabase)); } } finally { qexec.close(); } return datatypeList; }
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 |
public List<? super ContextResource> getContextsOfContext(String contextURI) { List<ContextResource> contextResourceList = new ArrayList<ContextResource>(); StringBuilder queryString = new StringBuilder().append(PREFIX_MDR) .append(PREFIX_RDFS).append("SELECT ?ctx FROM <") .append(MDRDatabase.BASE_URI).append("> WHERE {") .append("?ctx rdfs:subClassOf mdr:Context .") .append("?ctx mdr:having ?aic .") .append("?aic mdr:administeredItemContextContext <") .append(contextURI).append("> .").append("FILTER (?ctx != <") .append(contextURI).append("> ) }"); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); ContextResource ctx = new ContextImpl(qs.getResource("ctx"), this.mdrDatabase); contextResourceList.add(ctx); } } finally { qexec.close(); } return contextResourceList; }
Example 5
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 5 votes |
public Resource getAdministeredItem(String id) { StringBuilder queryString = new StringBuilder() .append(PREFIX_MDR) .append(PREFIX_RDFS) .append("SELECT ?ai FROM <") .append(MDRDatabase.BASE_URI) .append("> WHERE { ") .append("?prop rdfs:subPropertyOf mdr:administeredItemAdministrationRecord. ") .append("?ai ?prop ?administrationRecord. ") .append("?administrationRecord mdr:administeredItemIdentifier ?ii.") .append("?ii mdr:dataIdentifier ?di. FILTER regex (?di, \"") .append(id).append("\") .}"); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); Resource ai = null; try { ResultSet rs = qexec.execSelect(); if (rs.hasNext()) { QuerySolution qs = rs.next(); ai = qs.getResource("ai"); } if (rs.hasNext()) { throw new IllegalStateException( "Something is wrong. There is more than one AdministeredItems with the same ID."); } } finally { qexec.close(); } return ai; }
Example 6
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 7
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 5 votes |
/** * Runs SPARQL Query ove the MDRDatabase to get list of {@link ObjectClass} * es on a specific {@link Context} * * @param contextURI * URI of the Context on MDRDatabase * @return List of {@link ObjectClassResource} on the specified Context */ public List<? super ObjectClassResource> getObjectClassesOfContext( String contextURI, Integer limit, Integer offset) { StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS).append("SELECT ?objectClass FROM <") .append(MDRDatabase.BASE_URI).append("> WHERE {") .append("?objectClassClass rdfs:subClassOf mdr:ObjectClass .") .append("?objectClass rdfs:subClassOf ?objectClassClass .") .append("?objectClass mdr:having ?aic .") .append("?aic mdr:administeredItemContextContext <") .append(contextURI).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<ObjectClassResource> objectClassResourceList = new ArrayList<ObjectClassResource>(); try { ResultSet rs = qexec.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); ConceptResource ctx = new ConceptImpl( qs.getResource("objectClass"), this.mdrDatabase); objectClassResourceList.add(ctx); } } finally { qexec.close(); } return objectClassResourceList; }
Example 8
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 9
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 5 votes |
/** * Method to execute full text search on the MDR to match given string with * the Datatype Names * * @param datatypeName * Name of the Datatype which is looked for * @param searchType * Enumeration for types of Full Text Search * @return */ public List<? super DatatypeResource> searchDatatype(String datatypeName) { StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS).append(PREFIX_XSD) .append("SELECT ?datatype FROM <").append(MDRDatabase.BASE_URI) .append("> WHERE {") .append("?datatype rdfs:subClassOf mdr:Datatype. ") .append("?datatype mdr:datatypeName \"").append(datatypeName) .append("\"^^xsd:string }"); List<DatatypeResource> datatypeList = new ArrayList<DatatypeResource>(); 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 Resource res = qs.getResource("datatype"); datatypeList.add(new DatatypeImpl(res, mdrDatabase)); } } finally { qexec.close(); } return datatypeList; }
Example 10
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 5 votes |
public List<? super ClassificationSchemeResource> getClassificationSchemes( String contextURI) { List<ClassificationSchemeResource> csList = new ArrayList<ClassificationSchemeResource>(); ResultSet rs = getClassificationSchemesOfContext(contextURI); while (rs.hasNext()) { QuerySolution qs = rs.next(); Resource res = qs.getResource("cs"); csList.add(new ClassificationSchemeImpl(res, mdrDatabase)); } return csList; }
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 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 12
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 ambiguous discovered links of a source URI. * * @param ambiguousLink a {@link eu.aliada.shared.rdfstore.AmbiguousLink} that contains the source URI. * @param localRes the source resource of the link. * @param extResBegin the beginning string of the target link. * @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. * @since 2.0 */ public void getSourceURIAmbiguousLinks(final AmbiguousLink ambiguousLink, final Resource localRes, final String extResBegin, final String sparqlEndpointURI, final String graphName, final String user, final String password) { final String query = "SELECT ?rel ?extRes FROM <" + graphName + "> " + " WHERE {<" + ambiguousLink.getSourceURI() + "> ?rel ?extRes ." + " FILTER regex(?extRes, \"^" + extResBegin + "\", \"i\")" + " }"; 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 extRes = soln.getResource("extRes"); final Resource relResType = soln.getResource("rel"); final Triple triple = new Triple(localRes.asNode(), relResType.asNode(), extRes.asNode()); ambiguousLink.addLink(triple); } qexec.close() ; } catch (Exception exception) { LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query); } }
Example 13
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 ambiguous 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 {@link eu.aliada.shared.rdfstore.AmbiguousLink} with the ambiguous discovered links. * @since 2.0 */ public AmbiguousLink[] getAmbiguousDiscoveredLinks(final String sparqlEndpointURI, final String graphName, final String user, final String password, final int offset, final int limit) { final String query = "SELECT ?localRes ?extResBegin (COUNT(?localRes) AS ?count) FROM <" + graphName + "> " + " WHERE {?localRes ?rel ?extRes ." + " BIND( str(?extRes) as ?extResStr )." + " BIND( SUBSTR(?extResStr, 1,14) AS ?extResBegin)" + " }" + " GROUP BY ?localRes ?extResBegin" + " HAVING (COUNT(?localRes) > 1)" + " ORDER BY ?localRes" + " OFFSET " + offset + " LIMIT " + limit; ArrayList<AmbiguousLink> ambiguousLinksList = new ArrayList<AmbiguousLink>(); 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 localRes = soln.getResource("localRes"); final String extResBegin = soln.getLiteral("extResBegin").getString(); final AmbiguousLink ambiguousLink = new AmbiguousLink(); ambiguousLink.setSourceURI(localRes.getURI()); getSourceURIAmbiguousLinks(ambiguousLink, localRes, extResBegin, sparqlEndpointURI, graphName, user, password); ambiguousLinksList.add(ambiguousLink); } qexec.close() ; } catch (Exception exception) { LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query); } if (ambiguousLinksList.isEmpty()) { return new AmbiguousLink[0]; } return (AmbiguousLink[]) ambiguousLinksList.toArray(new AmbiguousLink[ambiguousLinksList.size()]); }
Example 14
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 15
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 16
Source File: VirtuosoQueryFactory.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_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("> ."); } // checks if keyword is empty 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(" OPTION (score ?sc) .} ORDER BY ?sc 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 17
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 18
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 19
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 4 votes |
public Resource getAdministeredItem(String id, String registrationAuthorityOrganizationID, String version) { StringBuilder queryString = new StringBuilder() .append(PREFIX_MDR) .append(PREFIX_RDFS) .append(PREFIX_XSD) .append("SELECT ?ai FROM <") .append(MDRDatabase.BASE_URI) .append("> WHERE { ") .append("?prop rdfs:subPropertyOf mdr:administeredItemAdministrationRecord. ") .append("?ai ?prop ?administrationRecord. ") .append("?administrationRecord mdr:administeredItemIdentifier ?ii. ") .append("?ii mdr:dataIdentifier \"").append(id) .append("\"^^xsd:string. ") .append("?ii mdr:itemRegistrationAuthorityIdentifier ?rai. ") .append("?rai mdr:organizationIdentifier \"") .append(registrationAuthorityOrganizationID) .append("\"^^xsd:string. "); if (version != null && !version.isEmpty()) { queryString.append("?ii mdr:version \"").append(version) .append("\"^^xsd:string. "); ; } queryString.append("}"); QueryExecution qexec = this.createQueryExecution( queryString.toString(), this.mdrDatabase.getOntModel()); Resource ai = null; try { ResultSet rs = qexec.execSelect(); if (rs.hasNext()) { QuerySolution qs = rs.next(); ai = qs.getResource("ai"); } if (rs.hasNext()) { throw new IllegalStateException( "Something is wrong. There is more than one AdministeredItems with the same ID and RegistrationAuthorityIdentifier.organizationIdentifier."); } } finally { qexec.close(); } return ai; }
Example 20
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()]); }