use of org.apache.jena.query.QuerySolution in project jena by apache.
the class TestTextHighlighting method doTestSearchWithLiterals.
protected Map<String, Literal> doTestSearchWithLiterals(String queryString, Set<String> expectedEntityURIs) {
Map<String, Literal> literals = new HashMap<>();
Query query = QueryFactory.create(queryString);
dataset.begin(ReadWrite.READ);
try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
ResultSet results = qexec.execSelect();
assertEquals(expectedEntityURIs.size() > 0, results.hasNext());
int count;
for (count = 0; results.hasNext(); count++) {
QuerySolution soln = results.nextSolution();
String entityUri = soln.getResource("s").getURI();
assertTrue(expectedEntityURIs.contains(entityUri));
Literal literal = soln.getLiteral("lit");
assertNotNull(literal);
literals.put(entityUri, literal);
}
assertEquals(expectedEntityURIs.size(), count);
} finally {
dataset.end();
}
return literals;
}
use of org.apache.jena.query.QuerySolution in project jena by apache.
the class TestTextMultilingualEnhancements02 method doTestSearchWithLiterals.
protected Map<String, Literal> doTestSearchWithLiterals(String queryString, Set<String> expectedEntityURIs) {
Map<String, Literal> literals = new HashMap<>();
Query query = QueryFactory.create(queryString);
dataset.begin(ReadWrite.READ);
try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
ResultSet results = qexec.execSelect();
assertEquals(expectedEntityURIs.size() > 0, results.hasNext());
int count;
for (count = 0; results.hasNext(); count++) {
QuerySolution soln = results.nextSolution();
String entityUri = soln.getResource("s").getURI();
assertTrue(expectedEntityURIs.contains(entityUri));
Literal literal = soln.getLiteral("lit");
assertNotNull(literal);
literals.put(entityUri, literal);
}
assertEquals(expectedEntityURIs.size(), count);
} finally {
dataset.end();
}
return literals;
}
use of org.apache.jena.query.QuerySolution in project Info-Evaluation by TechnionYP5777.
the class SqlRunner method getPersonalInfo.
public TableEntry getPersonalInfo(int wikiPageID) throws ClassNotFoundException, SQLException, IOException, ParseException {
Extractor ext = new Extractor(wikiPageID);
ext.executeQuery(QueryTypes.ABSTRACT_BY_WIKI_PAGE_ID);
ResultSetRewindable results = ext.getResults();
results.reset();
QuerySolution solution = results.nextSolution();
RDFNode overview = solution.get("abstract");
String overviewStr = "No Abstract";
if (overview != null)
if (overview.isResource())
overviewStr = (overview.asResource() + "").split("resource/")[1];
else if (overview.isLiteral())
overviewStr = (overview.asLiteral() + "").split("@")[0];
ext.executeQuery(QueryTypes.BASIC_INFO_BY_WIKI_PAGE_ID);
ResultSetRewindable basicInfoByIdResults = ext.getResults();
basicInfoByIdResults.reset();
TableEntry te = SqlTablesFiller.getBasicInfo(basicInfoByIdResults);
TableEntry result = new TableEntry(te);
result.setUrl(wikiURL + wikiPageID);
result.setOverview(overviewStr);
String photoLink = result.getPhotoLink();
photoLink.replaceAll("'", "\'");
int containsQuesmark = photoLink.indexOf("?");
if (containsQuesmark != -1) {
photoLink = photoLink.substring(0, containsQuesmark);
}
result.setPhotoLink(photoLink);
return result;
}
use of org.apache.jena.query.QuerySolution in project opentheso by miledrousset.
the class AlignmentQuery method queryBNF.
/**
* cette fonction permet de récuperer les alignements de la BNF
* requête de type Sparql
* @param idC
* @param idTheso
* @param lexicalValue
* @param lang
* @param requete
* @param source
* @return
*/
public ArrayList<NodeAlignment> queryBNF(String idC, String idTheso, String lexicalValue, String lang, String requete, String source) {
listeAlign = new ArrayList<>();
// lexicalValue = lexicalValue.replaceAll(" ", "%20");
requete = requete.replace("##lang##", "\"" + lang + "\"");
if (lexicalValue.contains(" ")) {
String[] valueTemp = lexicalValue.split(" ");
boolean first = true;
for (String valuetemp : valueTemp) {
requete = requete.substring(0, requete.length() - 1);
if (first) {
requete = requete.replace("##value##", valuetemp.trim());
first = false;
} else {
requete = requete.concat(" && regex(?value, \"" + valuetemp.trim() + "\",\"i\")");
}
}
requete = requete + ")";
} else {
requete = requete.replace("##value##", "\"" + lexicalValue + "\"");
}
/*requete = "PREFIX skos: <http://www.w3.org/2004/02/skos/core#>" +
" PREFIX xml: <http://www.w3.org/XML/1998/namespace>" +
" SELECT ?instrument ?prop ?value" +
" where { <http://data.bnf.fr/ark:/12148/cb119367821> skos:narrower+ ?instrument. ?instrument ?prop ?value. FILTER( (regex(?prop,skos:prefLabel) || regex(?prop,skos:altLabel)) && regex(?value, \"cornemuse\",\"i\")) filter(lang(?value) =\"fr\")} LIMIT 10";
*/
// System.out.println(requete);
Query query = QueryFactory.create(requete);
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://data.bnf.fr/sparql", query);
ResultSet results = qexec.execSelect();
while (results.hasNext()) {
QuerySolution qs = results.next();
NodeAlignment na = new NodeAlignment();
na.setInternal_id_concept(idC);
na.setInternal_id_thesaurus(idTheso);
na.setConcept_target(qs.get("value").toString());
// qs.get("comment").toString());
na.setDef_target("");
na.setThesaurus_target(source);
na.setUri_target(qs.get("instrument").toString());
listeAlign.add(na);
}
qexec.close();
return listeAlign;
}
use of org.apache.jena.query.QuerySolution in project opentheso by miledrousset.
the class AlignmentQuery method queryDBPedia.
/**
* Cette fonction permet de récupérer les alignements présents sur DBPedia
* pour un concept passé en paramètre
*
* @param idC
* @param idTheso
* @param lexicalValue
* @param lang
* @param source
* @return
*/
public ArrayList<NodeAlignment> queryDBPedia(String idC, String idTheso, String lexicalValue, String lang, String source) {
listeAlign = new ArrayList<>();
if (lexicalValue.contains(" ")) {
lexicalValue = lexicalValue.substring(0, lexicalValue.indexOf(" "));
}
lexicalValue = String.valueOf(lexicalValue.charAt(0)).toUpperCase() + lexicalValue.substring(1);
String sparqlQueryString1 = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" + "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>" + "SELECT * WHERE {" + " ?s rdfs:label ?label ." + " ?s rdfs:comment ?comment ." + " ?s dbpedia-owl:thumbnail ?thumbnail ." + " ?s foaf:isPrimaryTopicOf ?primaryTopicOf ." + " FILTER(regex(?s,\"resource/" + lexicalValue + "*\"))" + " FILTER(lang(?label) = \"" + lang + "\")" + " FILTER(lang(?comment) = \"" + lang + "\")" + " }";
// System.out.println(sparqlQueryString1);
Query query = QueryFactory.create(sparqlQueryString1);
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
ResultSet results = qexec.execSelect();
while (results.hasNext()) {
QuerySolution qs = results.next();
NodeAlignment na = new NodeAlignment();
na.setInternal_id_concept(idC);
na.setInternal_id_thesaurus(idTheso);
na.setConcept_target(qs.get("label").toString());
na.setDef_target(qs.get("comment").toString());
na.setThesaurus_target(source);
na.setUri_target(qs.get("primaryTopicOf").toString());
listeAlign.add(na);
}
qexec.close();
return listeAlign;
}
Aggregations