Java Code Examples for com.hp.hpl.jena.query.ResultSet#hasNext()
The following examples show how to use
com.hp.hpl.jena.query.ResultSet#hasNext() .
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: 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 2
Source File: SPARQLEndPoint.java From LodView with MIT License | 6 votes |
public Model extractLocalData(Model result, String IRI, Model m, List<String> queries) throws Exception { // System.out.println("executing query on IRI"); Resource subject = result.createResource(IRI); for (String query : queries) { QueryExecution qe = QueryExecutionFactory.create(parseQuery(query, IRI, null, -1, null), m); try { ResultSet rs = qe.execSelect(); List<Statement> sl = new ArrayList<Statement>(); while (rs.hasNext()) { QuerySolution qs = rs.next(); RDFNode subject2 = qs.get("s"); RDFNode property = qs.get("p"); RDFNode object = qs.get("o"); result.add(result.createStatement(subject2 != null ? subject2.asResource() : subject, property.as(Property.class), object)); } result.add(sl); } catch (Exception e) { e.printStackTrace(); throw new Exception("error in query execution: " + e.getMessage()); } finally { qe.close(); } } return result; }
Example 3
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 4
Source File: RDFFileManager.java From Benchmark with GNU General Public License v3.0 | 6 votes |
public static EventPattern extractQueryFromDataset(String serviceRequest) { Model queryBase = FileManager.get().loadModel(datasetDirectory + serviceRequest); dataset.getDefaultModel().add(ModelFactory.createOntologyModel(ontoSpec, queryBase)); String describeStr = queryPrefix + " select ?x where{?x rdf:type ces:EventRequest}"; // Query query = QueryFactory.create(describeStr); // query.setPrefixMapping(pmap); QueryExecution qe = QueryExecutionFactory.create(describeStr, dataset); ResultSet results = qe.execSelect(); // ResultSetFormatter.out(System.out, results, query); Map<String, EventDeclaration> edMap = new HashMap<String, EventDeclaration>(); EventPattern ep = new EventPattern(); ep.setQuery(true); while (results.hasNext()) { // System.out.println("results!"); QuerySolution row = results.next(); RDFNode edID = row.get("x"); // System.out.println("has id: " + edID.toString()); ep = extractEDByServiceID(edID, dataset, edMap).getEp(); } return ep; }
Example 5
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 6
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 7
Source File: Wine.java From neo4jena with Apache License 2.0 | 5 votes |
public static void search(GraphDatabaseService njgraph) { NeoGraph graph = new NeoGraph(njgraph); Model njmodel = ModelFactory.createModelForGraph(graph); String s2 = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" + "PREFIX food: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/food#>"+ "PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>" + "PREFIX owl: <http://www.w3.org/2002/07/owl#>"+ "SELECT ?X WHERE {"+ "?X food:SweetFruit ?Z . }"; Query query = QueryFactory.create(s2); QueryExecution qExe = QueryExecutionFactory.create(query, njmodel); StopWatch watch = new StopWatch(); ResultSet results = qExe.execSelect(); System.out.println("Query took (ms): "+ watch.stop()); //ResultSetFormatter.out(System.out, results); int count=0; while(results.hasNext()){ //System.out.println("in while"+count); QuerySolution sol = results.next(); System.out.print(sol.get("X")); count++; } System.out.println("Record fetched:"+ count); }
Example 8
Source File: LUBM.java From neo4jena with Apache License 2.0 | 5 votes |
public static void search(GraphDatabaseService njgraph) { NeoGraph graph = new NeoGraph(njgraph); Model njmodel = ModelFactory.createModelForGraph(graph); //long start = System.currentTimeMillis(); String s2 = "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" + "PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#>" + "SELECT ?X ?name "+ "WHERE" + "{ ?X ub:name ?name ." + "FILTER regex(?name,\"^Publication\") ."+ "}"; Query query = QueryFactory.create(s2); QueryExecution qExe = QueryExecutionFactory.create(query, njmodel); StopWatch watch = new StopWatch(); ResultSet results = qExe.execSelect(); log.info("Query took (ms): "+ watch.stop()); System.out.println("Query took (ms): "+ watch.stop()); //ResultSetFormatter.out(System.out, results); int count=0; while(results.hasNext()){ //System.out.println("in while"+count); QuerySolution sol = results.next(); System.out.println(sol.get("name")); count++; } log.info("Record fetched:"+ count); System.out.println("Record fetched:"+ count); }
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: SPARQLEndPoint.java From LodView with MIT License | 5 votes |
public Model extractData(Model result, String IRI, String sparql, List<String> queries) throws Exception { // System.out.println("executing query on " + sparql); Resource subject = result.createResource(IRI); for (String query : queries) { QueryExecution qe = QueryExecutionFactory.sparqlService(sparql, parseQuery(query, IRI, null, -1, null)); try { ResultSet rs = qe.execSelect(); List<Statement> sl = new ArrayList<Statement>(); while (rs.hasNext()) { QuerySolution qs = rs.next(); RDFNode subject2 = qs.get("s"); RDFNode property = qs.get("p"); RDFNode object = qs.get("o"); result.add(result.createStatement(subject2 != null ? subject2.asResource() : subject, property.as(Property.class), object)); } result.add(sl); } catch (Exception e) { e.printStackTrace(); throw new Exception("error in query execution: " + e.getMessage()); } finally { qe.close(); } } return result; }
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 number of 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. * @return the number of the ambiguous discovered links. * @since 2.0 */ public int getNumAmbiguousDiscoveredLinks (final String sparqlEndpointURI, final String graphName, final String user, final String password) { final String query = "SELECT (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)"; int numLinks = 0; 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() ; numLinks = numLinks + soln.getLiteral("count").getInt(); } qexec.close() ; } catch (Exception exception) { LOGGER.error(MessageCatalog._00035_SPARQL_FAILED, exception, query); } return numLinks; }
Example 12
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 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 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 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: RDFFileManager.java From Benchmark with GNU General Public License v3.0 | 4 votes |
private static void extractTrafficLocation(EventDeclaration ed, Dataset dataset) { // String queryStr = queryPrefix // + " select ?rid ?fnn ?fnsn ?fnst ?fnc ?fnlat ?fnlon ?snn ?snsn ?snst ?snc ?snlat ?snlon where {<" // + ed.getID() // + "> owls:presents ?profile. <" // + ed.getID() // + // "> ssn:observes ?y. ?profile ct:hasReportID ?rid. ?y ssn:isPropertyOf ?z. ?z ct:hasFirstNode ?fn. ?z ct:hasSecondNode ?sn. " // + // " ?fn ct:hasNodeName ?fnn. ?fn ct:hasStreetNumber ?fnsn. ?fn ct:hasStreet ?fnst. ?fn ct:hasCity ?fnc. ?fn ct:hasLatitude ?fnlat. ?fn ct:hasLongtitude ?fnlon." // + // " ?sn ct:hasNodeName ?snn. ?sn ct:hasStreetNumber ?snsn. ?sn ct:hasStreet ?snst. ?sn ct:hasCity ?snc. ?sn ct:hasLatitude ?snlat. ?sn ct:hasLongtitude ?snlon.}"; String queryStr = queryPrefix + " select ?z where { <" + ed.getnodeId() + "> ssn:observes ?y. ?y ssn:isPropertyOf ?z.} "; // + // " ?fn ct:hasNodeName ?fnn. ?fn ct:hasStreetNumber ?fnsn. ?fn ct:hasStreet ?fnst. ?fn ct:hasCity ?fnc. ?fn ct:hasLatitude ?fnlat. ?fn ct:hasLongtitude ?fnlon." // + // " ?sn ct:hasNodeName ?snn. ?sn ct:hasStreetNumber ?snsn. ?sn ct:hasStreet ?snst. ?sn ct:hasCity ?snc. ?sn ct:hasLatitude ?snlat. ?sn ct:hasLongtitude ?snlon.}"; QueryExecution qe = QueryExecutionFactory.create(queryStr, dataset); ResultSet results = qe.execSelect(); if (results.hasNext()) { QuerySolution row = results.next(); String foiStr = row.get("z").toString(); // String reportId = row.get("rid").asLiteral().getString(); // String firstNodeName = row.get("fnn").asLiteral().getString(); // String firstNodeStreetNo = row.get("fnsn").asLiteral().getString(); // String firstNodeStreet = row.get("fnst").asLiteral().getString(); // String firstNodeCity = row.get("fnc").asLiteral().getString(); // Double firstNodeLat = row.get("fnlat").asLiteral().getDouble(); // Double firstNodeLon = row.get("fnlon").asLiteral().getDouble(); // // String secondNodeName = row.get("snn").asLiteral().getString(); // String secondNodeStreetNo = row.get("snsn").asLiteral().getString(); // String secondNodeStreet = row.get("snst").asLiteral().getString(); // String secondNodeCity = row.get("snc").asLiteral().getString(); // Double secondNodeLat = row.get("snlat").asLiteral().getDouble(); // Double secondNodeLon = row.get("snlon").asLiteral().getDouble(); // ((TrafficReportService) ed).setReportId(reportId); // ((TrafficReportService) ed).setNode1City(firstNodeCity); // ((TrafficReportService) ed).setNode1Lat(firstNodeLat); // ((TrafficReportService) ed).setNode1Lon(firstNodeLon); // ((TrafficReportService) ed).setNode1Street(firstNodeStreet); // ((TrafficReportService) ed).setNode1StreetNo(firstNodeStreetNo); // ((TrafficReportService) ed).setNode1Name(firstNodeName); // ((TrafficReportService) ed).setNode2City(secondNodeCity); // ((TrafficReportService) ed).setNode2Lat(secondNodeLat); // ((TrafficReportService) ed).setNode2Lon(secondNodeLon); // ((TrafficReportService) ed).setNode2Name(secondNodeName); // ((TrafficReportService) ed).setNode2Street(secondNodeStreet); // ((TrafficReportService) ed).setNode2StreetNo(secondNodeStreetNo); ed.setFoi(foiStr); } }
Example 16
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 17
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 18
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 19
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 4 votes |
/** * * @param contextURI * @param limit * @param offset * @return */ public List<? super ConceptualDomainResource> getConceptualDomainsOfContext( String contextURI, Integer limit, Integer offset) { List<ConceptualDomainResource> cdList = new ArrayList<ConceptualDomainResource>(); StringBuilder queryString = new StringBuilder(PREFIX_MDR) .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: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()); 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().EnumeratedConceptualDomain)) { cdList.add(new EnumeratedConceptualDomainImpl(res, mdrDatabase)); } else { cdList.add(new NonEnumeratedConceptualDomainImpl(res, mdrDatabase)); } } } finally { qexec.close(); } return cdList; }
Example 20
Source File: Stats.java From CostFed with GNU Affero General Public License v3.0 | 4 votes |
public static void main(String[] args) throws FileNotFoundException { String endpoint = args[0]; String name = args[1]; String appendto = args[2]; double netMeanS = 0.0, netStdevS = 0.0, netMeanO = 0.0, netStdevO = 0.0; int nProp = 0; for (int j = 0; true; j++) { ResultSet rs = query(endpoint, Queries.GET_ALL_PROPERTIES, j * 10000); int i; for (i = 0; rs.hasNext(); i++) { String p = rs.next().get("x").toString(); System.out.println("Processing: " + p); Info infoS = process(endpoint, Queries.SUBJECT_FREQUENCIES, p); netMeanS += infoS.mean; netStdevS += infoS.stdev; Info infoO = process(endpoint, Queries.OBJECT_FREQUENCIES, p); netMeanO += infoO.mean; netStdevO += infoO.stdev; } System.out.println("Gathered " + i + " properties"); nProp += i; if (i == 0) break; } netMeanS /= nProp; netStdevS /= nProp; netMeanO /= nProp; netStdevO /= nProp; PrintWriter pw = new PrintWriter(new FileOutputStream(new File(appendto), true)); String line = String.format("%s\t%f\t%f\t%f\t%f", name, netMeanS, netStdevS, netMeanO, netStdevO); System.out.println(line); pw.println(line); pw.close(); }