use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.
the class RestRDFHelper method findAutocompleteConcepts__.
/**
* recherche par valeur
* @param ds
* @param value
* @param idTheso
* @param lang
* @return
*/
private String findAutocompleteConcepts__(HikariDataSource ds, String value, String idTheso, String lang, String group) {
if (value == null || idTheso == null) {
return null;
}
NodePreference nodePreference = new PreferencesHelper().getThesaurusPreferences(ds, idTheso);
if (nodePreference == null) {
return null;
}
SearchHelper searchHelper = new SearchHelper();
JsonHelper jsonHelper = new JsonHelper();
String uri;
ArrayList<NodeAutoCompletion> nodeAutoCompletion;
// recherche de toutes les valeurs
nodeAutoCompletion = searchHelper.searchTermNewForAutocompletion(ds, value, lang, idTheso, group);
if (nodeAutoCompletion == null || nodeAutoCompletion.isEmpty())
return null;
for (NodeAutoCompletion nodeAutoCompletion1 : nodeAutoCompletion) {
uri = getUri(nodePreference, nodeAutoCompletion1, idTheso);
jsonHelper.addJsonData(uri, nodeAutoCompletion1.getPrefLabel());
}
JsonArray datasJson = jsonHelper.getBuilder();
if (datasJson != null)
return datasJson.toString();
else
return null;
}
use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.
the class WikidataTest method getTraductionWikidata.
@Test
public void getTraductionWikidata() {
String uri = "https://www.wikidata.org/entity/Q7748";
String datas = getJsonFromURL(uri);
JsonHelper jsonHelper = new JsonHelper();
JsonObject jsonObject = jsonHelper.getJsonObject(datas);
jsonObject.getString("");
}
use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.
the class WikidataTest method getTraductions.
private void getTraductions(String jsonDatas, String entity) {
JsonHelper jsonHelper = new JsonHelper();
JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
// JsonObject test = jsonObject.getJsonObject("entities");
JsonObject jsonObject1 = null;
JsonValue jsonValue;
try {
jsonObject1 = jsonObject.getJsonObject("entities").getJsonObject(entity).getJsonObject("labels");
} catch (Exception e) {
System.err.println(e.toString());
return;
}
try {
jsonValue = jsonObject1.getJsonObject("en").get("language");
System.out.println(jsonValue.toString().replace("\"", ""));
jsonValue = jsonObject1.getJsonObject("en").get("value");
System.out.println(jsonValue.toString().replace("\"", ""));
} catch (Exception e) {
}
try {
jsonValue = jsonObject1.getJsonObject("fr").get("language");
System.out.println(jsonValue.toString().replace("\"", ""));
jsonValue = jsonObject1.getJsonObject("fr").get("value");
System.out.println(jsonValue.toString().replace("\"", ""));
} catch (Exception e) {
}
try {
jsonValue = jsonObject1.getJsonObject("ar").get("language");
System.out.println(jsonValue.toString().replace("\"", ""));
jsonValue = jsonObject1.getJsonObject("ar").get("value");
System.out.println(jsonValue.toString().replace("\"", ""));
} catch (Exception e) {
}
}
use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.
the class WikidataTest method getImages.
private void getImages(String jsonDatas, String entity) {
// pour construire l'URL de Wikimedia, il faut ajouter
// http://commons.wikimedia.org/wiki/Special:FilePath/
// puis le nom de l'image
StringBuffer url = new StringBuffer();
url.append("https://commons.wikimedia.org/wiki/Special:FilePath/");
JsonHelper jsonHelper = new JsonHelper();
JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
// JsonObject test = jsonObject.getJsonObject("entities");
JsonObject jsonObject1 = null;
JsonObject jsonObject2 = null;
JsonValue jsonValue;
try {
// .getJsonObject("P18");
jsonObject1 = jsonObject.getJsonObject("entities").getJsonObject(entity).getJsonObject("claims");
} catch (Exception e) {
System.err.println(e.toString());
return;
}
try {
// jsonValue = jsonObject1.getJsonObject("P18");
// System.out.println(jsonValue);
JsonArray jsonArray = jsonObject1.getJsonArray("P18");
for (int i = 0; i < jsonArray.size(); i++) {
jsonObject2 = jsonArray.getJsonObject(0);
jsonValue = jsonObject2.getJsonObject("mainsnak").getJsonObject("datavalue").get("value");
url.append(jsonValue.toString().replace("\"", ""));
System.out.println(url.toString());
}
} catch (Exception e) {
}
}
use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.
the class GettyAATHelper method getImages.
/**
* permet de récupérer les images de Wikidata
*
* @param jsonDatas
* @param entity
* @return
*/
private ArrayList<SelectedResource> getImages(String jsonDatas, String entity) {
// pour construire l'URL de Wikimedia, il faut ajouter
// http://commons.wikimedia.org/wiki/Special:FilePath/
// puis le nom de l'image
String fixedUrl = "https://commons.wikimedia.org/wiki/Special:FilePath/";
JsonHelper jsonHelper = new JsonHelper();
JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
// JsonObject test = jsonObject.getJsonObject("entities");
JsonObject jsonObject1;
JsonObject jsonObject2;
JsonValue jsonValue;
ArrayList<SelectedResource> imagesUrls = new ArrayList<>();
try {
// .getJsonObject("P18");
jsonObject1 = jsonObject.getJsonObject("entities").getJsonObject(entity).getJsonObject("claims");
} catch (Exception e) {
// System.err.println(e.toString());
return null;
}
try {
JsonArray jsonArray = jsonObject1.getJsonArray("P18");
for (int i = 0; i < jsonArray.size(); i++) {
SelectedResource selectedResource = new SelectedResource();
jsonObject2 = jsonArray.getJsonObject(i);
jsonValue = jsonObject2.getJsonObject("mainsnak").getJsonObject("datavalue").get("value");
selectedResource.setGettedValue(fixedUrl + jsonValue.toString().replace("\"", ""));
imagesUrls.add(selectedResource);
}
} catch (Exception e) {
}
return imagesUrls;
}
Aggregations