use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.
the class GettyAATHelper method getDescriptions.
/**
* permet de récupérer les descriptions de wikidata
*
* @param jsonDatas
* @param entity
* @param languages
* @return
*/
private ArrayList<SelectedResource> getDescriptions(String jsonDatas, String entity, ArrayList<String> languages) {
ArrayList<SelectedResource> descriptions = new ArrayList<>();
JsonHelper jsonHelper = new JsonHelper();
JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
// JsonObject test = jsonObject.getJsonObject("entities");
JsonObject jsonObject1;
JsonValue jsonValue;
String lang;
String value;
try {
jsonObject1 = jsonObject.getJsonObject("entities").getJsonObject(entity).getJsonObject("descriptions");
} catch (Exception e) {
// System.err.println(e.toString());
return null;
}
for (String language : languages) {
try {
SelectedResource selectedResource = new SelectedResource();
jsonValue = jsonObject1.getJsonObject(language).get("language");
lang = jsonValue.toString().replace("\"", "");
selectedResource.setIdLang(lang);
jsonValue = jsonObject1.getJsonObject(language).get("value");
value = jsonValue.toString().replace("\"", "");
selectedResource.setGettedValue(value);
descriptions.add(selectedResource);
} catch (Exception e) {
}
}
return descriptions;
}
use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.
the class OpenthesoHelper 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;
}
use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.
the class OpenthesoHelper method getTraductions.
/**
* récupération des traductions
*
* @param jsonDatas
* @param entity
* @param languages
* @return
*/
private ArrayList<SelectedResource> getTraductions(String jsonDatas, String entity, ArrayList<String> languages) {
ArrayList<SelectedResource> traductions = new ArrayList<>();
JsonHelper jsonHelper = new JsonHelper();
JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
// JsonObject test = jsonObject.getJsonObject("entities");
JsonObject jsonObject1;
JsonValue jsonValue;
String lang;
String value;
try {
jsonObject1 = jsonObject.getJsonObject("entities").getJsonObject(entity).getJsonObject("labels");
} catch (Exception e) {
// System.err.println(e.toString());
return null;
}
for (String language : languages) {
try {
SelectedResource selectedResource = new SelectedResource();
jsonValue = jsonObject1.getJsonObject(language).get("language");
lang = jsonValue.toString().replace("\"", "");
selectedResource.setIdLang(lang);
jsonValue = jsonObject1.getJsonObject(language).get("value");
value = jsonValue.toString().replace("\"", "");
selectedResource.setGettedValue(value);
traductions.add(selectedResource);
} catch (Exception e) {
}
}
return traductions;
}
use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.
the class IdRefTest method getNames.
private void getNames(String jsonDatas) {
JsonHelper jsonHelper = new JsonHelper();
JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
// JsonObject test = jsonObject.getJsonObject("entities");
JsonObject jsonObject1;
JsonArray jsonArray;
String valeur = "";
String uri = "https://www.idref.fr/";
String idRef = "";
JsonArray jsonArrayNames;
String nom = "";
String prenom = "";
try {
if (jsonObject == null)
return;
if (jsonObject.getJsonObject("response") == null)
return;
jsonArray = jsonObject.getJsonObject("response").getJsonArray("docs");
} catch (Exception e) {
System.err.println(e.toString());
return;
}
for (int i = 0; i < jsonArray.size(); i++) {
// jsonObject1.getValueType()
jsonObject1 = jsonArray.getJsonObject(i);
valeur = ((JsonObject) jsonObject1).getString("affcourt_z");
idRef = ((JsonObject) jsonObject1).getString("ppn_z");
// récupération des noms et prénoms
jsonArrayNames = jsonObject1.getJsonArray("nom_s");
if (jsonArrayNames != null) {
for (int j = 0; j < jsonArrayNames.size(); j++) {
if (j == 0)
nom = jsonArrayNames.getString(j);
else
nom = nom + "; " + jsonArrayNames.getString(j);
}
}
jsonArrayNames = jsonObject1.getJsonArray("prenom_s");
if (jsonArrayNames != null) {
for (int j = 0; j < jsonArrayNames.size(); j++) {
if (j == 0)
prenom = jsonArrayNames.getString(j);
else
prenom = prenom + "; " + jsonArrayNames.getString(j);
}
}
System.out.println(valeur);
System.out.println(idRef);
System.out.println("url = " + uri + idRef);
System.out.println("Noms= " + nom);
System.out.println("Prenoms= " + prenom);
}
}
use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.
the class IdRefTest method getValues.
private void getValues(String jsonDatas) {
JsonHelper jsonHelper = new JsonHelper();
JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
// JsonObject test = jsonObject.getJsonObject("entities");
JsonObject jsonObject1;
JsonArray jsonArray;
String valeur = "";
String uri = "https://www.idref.fr/";
String idRef = "";
JsonValue jsonValue;
try {
if (jsonObject == null)
return;
if (jsonObject.getJsonObject("response") == null)
return;
jsonArray = jsonObject.getJsonObject("response").getJsonArray("docs");
} catch (Exception e) {
System.err.println(e.toString());
return;
}
for (int i = 0; i < jsonArray.size(); i++) {
// jsonObject1.getValueType()
jsonObject1 = jsonArray.getJsonObject(i);
valeur = ((JsonObject) jsonObject1).getString("affcourt_z");
idRef = ((JsonObject) jsonObject1).getString("ppn_z");
System.out.println(valeur);
System.out.println(idRef);
System.out.println("url = " + uri + idRef);
}
}
Aggregations