use of com.bordercloud.sparql.Endpoint in project opentheso by miledrousset.
the class AlignmentQuery method queryWikidata.
// private getAlignementFromSkos(){
// }
// //////////////////////////////////////
// //////////////////////////////////////
// //// /////////////
// //// SPARQL /////////////
// //// /////////////
// //////////////////////////////////////
// //////////////////////////////////////
/**
* Aligenement du thésaurus vers la source Wikidata en Sparql et en retour du Json
* @param idC
* @param idTheso
* @param lexicalValue
* @param lang
* @param requete
* @param source
* @return
*/
public ArrayList<NodeAlignment> queryWikidata(String idC, String idTheso, String lexicalValue, String lang, String requete, String source) {
try {
Endpoint sp = new Endpoint("https://query.wikidata.org/sparql", false);
/* String querySelect = "SELECT ?item ?itemLabel ?itemDescription WHERE {" +
" ?item rdfs:label \"fibula\"@en." +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],en\". }" +
"}";*/
requete = requete.replaceAll("##value##", lexicalValue);
requete = requete.replaceAll("##lang##", lang);
HashMap<String, HashMap> rs = sp.query(requete);
if (rs == null)
return null;
listeAlign = new ArrayList<>();
ArrayList<HashMap<String, Object>> rows_queryWikidata = (ArrayList) rs.get("result").get("rows");
for (HashMap<String, Object> hashMap : rows_queryWikidata) {
NodeAlignment na = new NodeAlignment();
na.setInternal_id_concept(idC);
na.setInternal_id_thesaurus(idTheso);
// label ou Nom
if (hashMap.get("itemLabel") != null)
na.setConcept_target(hashMap.get("itemLabel").toString());
else
continue;
// description
if (hashMap.get("itemDescription") != null)
na.setDef_target(hashMap.get("itemDescription").toString());
else
na.setDef_target("");
na.setThesaurus_target(source);
// URI
if (hashMap.get("item") != null)
na.setUri_target(hashMap.get("item").toString());
else
continue;
listeAlign.add(na);
/* System.out.println("URI : " + hashMap.get("item"));
System.out.println("URI : " + hashMap.get("itemLabel"));
System.out.println("URI : " + hashMap.get("itemDescription"));*/
}
} catch (EndpointException eex) {
message = eex.toString();
return null;
} catch (Exception e) {
message = "pas de connexion internet !!";
return null;
}
return listeAlign;
}
use of com.bordercloud.sparql.Endpoint in project opentheso by miledrousset.
the class WikidataHelper method queryWikidata.
/**
* Alignement du thésaurus vers la source Wikidata en Sparql et en retour du Json
* @param idC
* @param idTheso
* @param lexicalValue
* @param lang
* @param requete
* @param source
* @return
*/
public ArrayList<NodeAlignment> queryWikidata(String idC, String idTheso, String lexicalValue, String lang, String requete, String source) {
ArrayList<NodeAlignment> listAlignValues = new ArrayList<>();
try {
Endpoint sp = new Endpoint("https://query.wikidata.org/sparql", false);
/* String querySelect = "SELECT ?item ?itemLabel ?itemDescription WHERE {" +
" ?item rdfs:label \"fibula\"@en." +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],en\". }" +
"}";*/
requete = requete.replaceAll("##value##", lexicalValue);
requete = requete.replaceAll("##lang##", lang);
HashMap<String, HashMap> rs = sp.query(requete);
if (rs == null)
return null;
ArrayList<HashMap<String, Object>> rows_queryWikidata = (ArrayList) rs.get("result").get("rows");
for (HashMap<String, Object> hashMap : rows_queryWikidata) {
NodeAlignment na = new NodeAlignment();
na.setInternal_id_concept(idC);
na.setInternal_id_thesaurus(idTheso);
// label ou Nom
if (hashMap.get("itemLabel") != null)
na.setConcept_target(hashMap.get("itemLabel").toString());
else
continue;
// description
if (hashMap.get("itemDescription") != null)
na.setDef_target(hashMap.get("itemDescription").toString());
else
na.setDef_target("");
na.setThesaurus_target(source);
// URI
if (hashMap.get("item") != null)
na.setUri_target(hashMap.get("item").toString());
else
continue;
listAlignValues.add(na);
}
} catch (EndpointException eex) {
messages.append(eex.toString());
return null;
} catch (Exception e) {
messages.append("pas de connexion internet !!");
return null;
}
return listAlignValues;
}
use of com.bordercloud.sparql.Endpoint in project opentheso by miledrousset.
the class WikidataTest method searchValue.
// récupération des URI qui parlent du concept avec l'entité codé exp : http://www.wikidata.org/entity/Q324926 pour fibule
// SELECT ?item ?itemLabel WHERE {
// ?item rdfs:label "fibule"@fr.
// SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr". }.
// }
// @Test
public void searchValue() {
try {
Endpoint sp = new Endpoint("https://query.wikidata.org/sparql", false);
String querySelect = "SELECT ?item ?itemLabel ?itemDescription WHERE {\n" + " ?item rdfs:label \"fibula\"@fr.\n" + " SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],fr\". }\n" + "}";
HashMap rs = sp.query(querySelect);
HashMap<String, HashMap> rs3_queryPopulationInFrance = sp.query(querySelect);
ArrayList<HashMap<String, Object>> rows_queryPopulationInFrance = (ArrayList) rs3_queryPopulationInFrance.get("result").get("rows");
for (HashMap<String, Object> hashMap : rows_queryPopulationInFrance) {
System.out.println("URI : " + hashMap.get("item"));
System.out.println("URI : " + hashMap.get("itemLabel"));
System.out.println("URI : " + hashMap.get("itemDescription"));
}
// printResult(rs, 30);
} catch (EndpointException eex) {
System.out.println(eex);
eex.printStackTrace();
}
}
Aggregations