Search in sources :

Example 1 with JsonHelper

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

the class GemetHelper method getImages.

/**
 * permet de récupérer les images de Wikidata
 *
 * @param jsonDatas
 * @param entity
 * @return
 */
private ArrayList<SelectedResource> getImages(String jsonDatas) {
    // 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 {
            jsonObject1 = jsonObject.getJsonObject("entities").getJsonObject(entity).getJsonObject("claims");//.getJsonObject("P18");
        } 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;
}
Also used : JsonHelper(mom.trd.opentheso.core.json.helper.JsonHelper) SelectedResource(mom.trd.opentheso.core.alignment.SelectedResource) JsonValue(javax.json.JsonValue) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject)

Example 2 with JsonHelper

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

the class IdRefHelper method getValuesSubject.

private ArrayList<NodeAlignment> getValuesSubject(String jsonDatas, String idC, String idTheso, String source) {
    JsonHelper jsonHelper = new JsonHelper();
    JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
    // JsonObject test = jsonObject.getJsonObject("entities");
    JsonObject jsonObject1;
    JsonArray jsonArray;
    ArrayList<NodeAlignment> listAlignValues = new ArrayList<>();
    String uri = "https://www.idref.fr/";
    try {
        if (jsonObject == null)
            return null;
        if (jsonObject.getJsonObject("response") == null)
            return null;
        jsonArray = jsonObject.getJsonObject("response").getJsonArray("docs");
    } catch (Exception e) {
        System.err.println(e.toString());
        return null;
    }
    for (int i = 0; i < jsonArray.size(); i++) {
        NodeAlignment na = new NodeAlignment();
        na.setInternal_id_concept(idC);
        na.setInternal_id_thesaurus(idTheso);
        // jsonObject1.getValueType()
        jsonObject1 = jsonArray.getJsonObject(i);
        // label ou Nom
        try {
            jsonObject1.getString("affcourt_z");
            na.setConcept_target(((JsonObject) jsonObject1).getString("affcourt_z"));
        } catch (Exception e) {
            continue;
        }
        // description
        na.setDef_target("");
        na.setThesaurus_target(source);
        // URI
        try {
            jsonObject1.getString("ppn_z");
            na.setUri_target(uri + ((JsonObject) jsonObject1).getString("ppn_z"));
        } catch (Exception e) {
            continue;
        }
        na.setUri_target(uri + ((JsonObject) jsonObject1).getString("ppn_z"));
        listAlignValues.add(na);
    /*    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); */
    }
    return listAlignValues;
}
Also used : JsonArray(javax.json.JsonArray) JsonHelper(mom.trd.opentheso.core.json.helper.JsonHelper) NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 3 with JsonHelper

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

the class IdRefHelper method getValuesNames.

private ArrayList<NodeAlignment> getValuesNames(String jsonDatas, String idC, String idTheso, String source) {
    JsonHelper jsonHelper = new JsonHelper();
    JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
    // JsonObject test = jsonObject.getJsonObject("entities");
    JsonObject jsonObject1;
    JsonArray jsonArray;
    ArrayList<NodeAlignment> listAlignValues = new ArrayList<>();
    String uri = "https://www.idref.fr/";
    // String valeur = "";
    // String idRef = "";
    // JsonValue jsonValue;
    String nom = "";
    String prenom = "";
    JsonArray jsonArrayNames;
    try {
        if (jsonObject == null)
            return null;
        if (jsonObject.getJsonObject("response") == null)
            return null;
        jsonArray = jsonObject.getJsonObject("response").getJsonArray("docs");
    } catch (Exception e) {
        System.err.println(e.toString());
        return null;
    }
    for (int i = 0; i < jsonArray.size(); i++) {
        NodeAlignment na = new NodeAlignment();
        na.setInternal_id_concept(idC);
        na.setInternal_id_thesaurus(idTheso);
        // jsonObject1.getValueType()
        jsonObject1 = jsonArray.getJsonObject(i);
        // label ou Nom
        try {
            jsonObject1.getString("affcourt_z");
            na.setConcept_target(((JsonObject) jsonObject1).getString("affcourt_z"));
        } catch (Exception e) {
            continue;
        }
        na.setThesaurus_target(source);
        // URI
        try {
            jsonObject1.getString("ppn_z");
            na.setUri_target(uri + ((JsonObject) jsonObject1).getString("ppn_z"));
        } catch (Exception e) {
            continue;
        }
        // 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);
            }
        }
        // description
        na.setDef_target("Noms=" + nom + "/ Prenoms= " + prenom);
        listAlignValues.add(na);
    /*    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); */
    }
    return listAlignValues;
}
Also used : JsonArray(javax.json.JsonArray) JsonHelper(mom.trd.opentheso.core.json.helper.JsonHelper) NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 4 with JsonHelper

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

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

Example 5 with JsonHelper

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

the class WikidataHelper 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) EndpointException(com.bordercloud.sparql.EndpointException)

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