Search in sources :

Example 16 with JsonHelper

use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.

the class GettyAATHelper 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;
}
Also used : JsonHelper(mom.trd.opentheso.core.json.helper.JsonHelper) SelectedResource(mom.trd.opentheso.core.alignment.SelectedResource) ArrayList(java.util.ArrayList) JsonValue(javax.json.JsonValue) JsonObject(javax.json.JsonObject) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 17 with JsonHelper

use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.

the class OpenthesoHelper 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;
}
Also used : JsonHelper(mom.trd.opentheso.core.json.helper.JsonHelper) SelectedResource(mom.trd.opentheso.core.alignment.SelectedResource) ArrayList(java.util.ArrayList) JsonValue(javax.json.JsonValue) JsonObject(javax.json.JsonObject) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 18 with JsonHelper

use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.

the class WikidataHelper 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;
}
Also used : JsonHelper(mom.trd.opentheso.core.json.helper.JsonHelper) SelectedResource(mom.trd.opentheso.core.alignment.SelectedResource) ArrayList(java.util.ArrayList) JsonValue(javax.json.JsonValue) JsonObject(javax.json.JsonObject) EndpointException(com.bordercloud.sparql.EndpointException)

Example 19 with JsonHelper

use of mom.trd.opentheso.core.json.helper.JsonHelper in project opentheso by miledrousset.

the class WikidataTest method getDescriptions.

private void getDescriptions(String jsonDatas, String entity) {
    JsonHelper jsonHelper = new JsonHelper();
    JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
    // JsonObject test = jsonObject.getJsonObject("entities");
    JsonObject jsonObject1;
    JsonValue jsonValue;
    try {
        jsonObject1 = jsonObject.getJsonObject("entities").getJsonObject(entity).getJsonObject("descriptions");
    } 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) {
    }
}
Also used : JsonHelper(mom.trd.opentheso.core.json.helper.JsonHelper) JsonValue(javax.json.JsonValue) JsonObject(javax.json.JsonObject) MalformedURLException(java.net.MalformedURLException) EndpointException(com.bordercloud.sparql.EndpointException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

JsonHelper (mom.trd.opentheso.core.json.helper.JsonHelper)19 JsonObject (javax.json.JsonObject)18 JsonValue (javax.json.JsonValue)14 IOException (java.io.IOException)13 MalformedURLException (java.net.MalformedURLException)13 ArrayList (java.util.ArrayList)12 SelectedResource (mom.trd.opentheso.core.alignment.SelectedResource)10 JsonArray (javax.json.JsonArray)9 EndpointException (com.bordercloud.sparql.EndpointException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 XMLStreamException (javax.xml.stream.XMLStreamException)3 Endpoint (com.bordercloud.sparql.Endpoint)2 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)2 PreferencesHelper (mom.trd.opentheso.bdd.helper.PreferencesHelper)1 SearchHelper (mom.trd.opentheso.bdd.helper.SearchHelper)1 NodeAutoCompletion (mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion)1 NodePreference (mom.trd.opentheso.bdd.helper.nodes.NodePreference)1 Test (org.junit.Test)1