Java Code Examples for com.hp.hpl.jena.query.ResultSet#next()
The following examples show how to use
com.hp.hpl.jena.query.ResultSet#next() .
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: RDFFileManager.java From Benchmark with GNU General Public License v3.0 | 6 votes |
private static String extractEventPayloads(EventDeclaration ed, Dataset dataset) { String queryStr = queryPrefix + " select ?x ?y ?z where {<" + ed.getnodeId() + "> ssn:observes ?x. ?x rdf:type ?y. ?x ssn:isPropertyOf ?z }"; QueryExecution qe = QueryExecutionFactory.create(queryStr, dataset); ResultSet results = qe.execSelect(); List<String> payloads = new ArrayList<String>(); String foiId = ""; while (results.hasNext()) { QuerySolution result = results.next(); RDFNode propertyName = result.get("x"); RDFNode propertyType = result.get("y"); RDFNode foi = result.get("z"); if (propertyType.toString().equals("http://www.w3.org/2000/01/rdf-schema#Resource")) continue; // System.out.println("type: " + property + " foi: " + foi); payloads.add(propertyType.toString() + "|" + foi.toString() + "|" + propertyName.toString()); foiId = foi.toString(); // System.out.println("payload: " + propertyType.toString() + "|" + foi.toString() + "|" // + propertyName.toString()); } ed.setPayloads(payloads); return foiId; }
Example 2
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 3
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 6 votes |
public int getNumberOfObjectClasses(String contextURI) { StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS) .append("SELECT (COUNT (DISTINCT ?objectClass) as ?count) 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("> .").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 4
Source File: RDFFileManager.java From Benchmark with GNU General Public License v3.0 | 6 votes |
public static EventPattern extractQueryFromModel(Model serviceRequest) { // Model queryBase = FileManager.get().loadModel(datasetDirectory + serviceRequest); dataset.getDefaultModel().add(ModelFactory.createOntologyModel(ontoSpec, serviceRequest)); 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(); 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: PagedResultSetTestCase.java From SolRDF with Apache License 2.0 | 6 votes |
/** * Positive test. */ @Test public void range() { final int offset = 120; final int size = 24; final ResultSetRewindable cut = new PagedResultSet(executeQuery(), size, offset); final ResultSet resultSet = executeQuery(); while (cut.hasNext()) { cut.next(); } assertEquals(size, cut.size()); cut.reset(); for (int i = 0; i < offset; i++) { resultSet.next(); } for (int i = 0; i < size; i++) { assertEquals(resultSet.nextBinding(), cut.nextBinding()); } assertFalse(cut.hasNext()); }
Example 6
Source File: ResourceQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 6 votes |
public int getNumberOfValueMeanings(String conceptualDomainURI) { StringBuilder queryString = new StringBuilder(PREFIX_MDR) .append(PREFIX_RDFS) .append("SELECT (COUNT(DISTINCT ?vm) as ?count) FROM <") .append(MDRDatabase.BASE_URI).append("> WHERE {") .append("?vm rdfs:subClassOf mdr:ValueMeaning .") .append("?vm mdr:containedInValueMeaningSet <") .append(conceptualDomainURI).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 7
Source File: RDFFileManager.java From Benchmark with GNU General Public License v3.0 | 6 votes |
private static Map<String, EventDeclaration> extractEDsFromDataset(Dataset dataset) { // List<EventDeclaration> eds = new ArrayList<EventDeclaration>(); String describeStr = queryPrefix + " select ?x" + " where{?x rdf:type ?y graph <http://www.insight-centre.org/ces#> { ?y rdfs:subClassOf ces:EventService}}"; // 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>(); while (results.hasNext()) { QuerySolution row = results.next(); RDFNode edID = row.get("x"); // System.out.println("has id: " + edID.toString()); extractEDByServiceID(edID, dataset, edMap); } // RDFDataMgr.write(System.out, results, Lang.TURTLE); return edMap; }
Example 8
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 9
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 10
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 11
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 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: VirtuosoQueryFactory.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_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 Resource tempRes = this.mdrDatabase.getOntModel().getResource( qs.getResource("cd").getURI()); OntClass res = tempRes.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 14
Source File: Relation.java From xcurator with Apache License 2.0 | 4 votes |
private void findAndAddLinkedResouces(Model model, Element item, Document dataDoc, Resource parentResouce, String typePrefix) throws XPathExpressionException { //TODO: Fix it! // createSPARQL(); // name="x.y.z.y" // x // ?x y ?y . // ?y z ?z . // ?z y ?y . String whereClause = "WHERE {\n"; int j = 0; whereClause += "?x0 rdf:type <" + getTargetEntity() + "> . \n"; for (Property lookupProperty : foreignLookupKey.getProperties()) { String localValue = XMLUtils.getStringByPath(lookupProperty.getPath(), item, dataDoc).trim(); if (localValue.length() == 0) { continue; } // localValue = localValue.replaceAll("\\s+", "\\\\\\\\s+"); localValue = JenaUtils.querify(localValue); String[] splittedRelation = lookupProperty.getElement().getAttribute("name") .replace(typePrefix, "") .split("\\."); int i; for (i = 1; i < splittedRelation.length; i++) { whereClause += "?x" + (i - 1) + "" + (i != 1 ? j : "") + " t:" + splittedRelation[i] + " ?x" + (i) + "" + j + ".\n"; } whereClause += "FILTER (?x" + (i - 1) + (i != 1 ? j : "") + " = \"" + localValue + "\").\n"; j++; } whereClause += "} "; String queryStr = "PREFIX t: <" + typePrefix + ">\n" + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "select ?x0 \n" + whereClause; LogUtils.debug(this.getClass(), queryStr); Query query = QueryFactory.create(queryStr); QueryExecution qExec = null; try { qExec = QueryExecutionFactory.create(query, model); ResultSet rs = qExec.execSelect(); while (rs.hasNext()) { QuerySolution solution = rs.next(); RDFNode subject = solution.get("?x0"); parentResouce.addProperty(getJenaProperty(model), subject); } } catch (Exception e) { if (debug) { e.printStackTrace(); } } finally { if (qExec != null) { qExec.close(); } } // for (Property lookupProperty: foreignLookupKey.getProperties()) { // String localValue = XMLUtils.getStringByPath(lookupProperty.getPath(), item, dataDoc); // Selector selector = new SimpleSelector(null, lookupProperty.getJenaProperty(model), localValue); // StmtIterator iter = model.listStatements(selector); // // while (iter.hasNext()) { // Statement stmt = iter.next(); // if (targetEntity.equals(stmt.getSubject().getProperty(RDF.type).getObject().toString())) { // parentResouce.addProperty(getJenaProperty(model), stmt.getSubject()); // } // } // } // // // for (Property lookupProperty: foreignLookupKey.getProperties()) { // String localValue = XMLUtils.getStringByPath(lookupProperty.getPath(), item, dataDoc); // Selector selector = new SimpleSelector(null, lookupProperty.getJenaProperty(model), localValue); // StmtIterator iter = model.listStatements(selector); // // while (iter.hasNext()) { // Statement stmt = iter.next(); // if (targetEntity.equals(stmt.getSubject().getProperty(RDF.type).getObject().toString())) { // parentResouce.addProperty(getJenaProperty(model), stmt.getSubject()); // } // } // } }
Example 15
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 16
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 17
Source File: DataElementService.java From semanticMDR with GNU General Public License v3.0 | 4 votes |
@GET @Path("/{deid}/es") @Produces(MediaType.APPLICATION_JSON) public Response getExtractionSpec( @QueryParam("specification-format") String specificationFormat, @QueryParam("content-model") String contentModel, @PathParam("deid") String deid) { Repository repository = RepositoryManager.getInstance().getRepository(); OntModel ontModel = repository.getMDRDatabase().getOntModel(); List<String> extractionSpecifications = new ArrayList<String>(); if (specificationFormat == null || contentModel == null) { throw new WebApplicationException(Status.NOT_ACCEPTABLE); } File getExtractionFile = new File(QUERY_FILE_GET_EXTRACTIONS); String queryString = ""; try { queryString = FileUtils.readFileToString(getExtractionFile); } catch (IOException e) { logger.error("File with context serialization query could not be found "); return Response.serverError().build(); } ParameterizedSparqlString query = new ParameterizedSparqlString( queryString); query.setLiteral("uuid", ResourceFactory.createTypedLiteral(deid)); query.setLiteral("specFormat", ResourceFactory.createTypedLiteral(specificationFormat)); query.setLiteral("contentModel", ResourceFactory.createTypedLiteral(contentModel)); QueryExecution qe = QueryExecutionFactory.create(query.asQuery(), ontModel); String spec = ""; ResultSet rs = qe.execSelect(); while (rs.hasNext()) { QuerySolution qs = rs.next(); spec = qs.getLiteral("extractionSpec").getString(); if (spec != null && !spec.equals("")) { extractionSpecifications.add(spec); } } return Response.ok(extractionSpecifications).build(); }
Example 18
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 19
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 20
Source File: TDBQueryFactory.java From semanticMDR with GNU General Public License v3.0 | 4 votes |
@Override public List<? super ValueDomainResource> searchValueDomain(String keyword, String contextURI, TextSearchType searchType) { List<ValueDomainResource> vdList = new ArrayList<ValueDomainResource>(); 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:ValueDomain .") .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 vdList; } 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().EnumeratedValueDomain)) { vdList.add(new EnumeratedValueDomainImpl(res, mdrDatabase)); } else { vdList.add(new NonEnumeratedValueDomainImpl(res, mdrDatabase)); } } } finally { qexec.close(); } return vdList; }