Search in sources :

Example 16 with SelectedResource

use of mom.trd.opentheso.core.alignment.SelectedResource in project opentheso by miledrousset.

the class Alignment method addDefinitions__.

private boolean addDefinitions__(String idTheso, String idConcept, int idUser) {
    NoteHelper noteHelper = new NoteHelper();
    TermHelper termHelper = new TermHelper();
    String idTerm = termHelper.getIdTermOfConcept(connect.getPoolConnexion(), idConcept, idTheso);
    if (idTerm == null)
        return false;
    // ajout de la note avec prefix de la source (wikidata)
    for (SelectedResource selectedResource : descriptionsOfAlignment) {
        if (selectedResource.isSelected()) {
            if (!noteHelper.addTermNote(connect.getPoolConnexion(), idTerm, selectedResource.getIdLang(), idTheso, selectedResource.getGettedValue() + " (" + selectedAlignement + ")", "definition", idUser)) {
                error = true;
                alignementResult = alignementResult + ": Erreur dans l'ajout des définitions";
            }
        }
    }
    alignementResult = alignementResult + " Définitions ajoutées ##";
    return true;
}
Also used : SelectedResource(mom.trd.opentheso.core.alignment.SelectedResource) NoteHelper(mom.trd.opentheso.bdd.helper.NoteHelper) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper)

Example 17 with SelectedResource

use of mom.trd.opentheso.core.alignment.SelectedResource in project opentheso by miledrousset.

the class GemetHelper method getDescriptions.

/**
 * permet de récupérer les descriptions de wikidata
 *
 * @param jsonDatas
 * @param entity
 * @param languages
 * @return
 */
private ArrayList<SelectedResource> getDescriptions(String jsonDatas, ArrayList<String> languages) {
    ArrayList<SelectedResource> descriptions = new ArrayList<>();
    String lang;
    String value;
    // lecture du fichier Json des langues
    JsonArray dataArray;
    JsonObject dataObject;
    try (JsonReader reader = Json.createReader(new StringReader(jsonDatas))) {
        dataArray = reader.readArray();
        for (int i = 0; i < dataArray.size(); ++i) {
            dataObject = dataArray.getJsonObject(i);
            SelectedResource selectedResource = new SelectedResource();
            lang = dataObject.getString("language");
            value = dataObject.getString("string");
            if (lang == null || value == null || lang.isEmpty() || value.isEmpty())
                continue;
            if (languages.contains(lang)) {
                selectedResource.setIdLang(lang);
                selectedResource.setGettedValue(value);
                descriptions.add(selectedResource);
            }
        }
    }
    return descriptions;
}
Also used : JsonArray(javax.json.JsonArray) SelectedResource(mom.trd.opentheso.core.alignment.SelectedResource) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject) JsonReader(javax.json.JsonReader)

Example 18 with SelectedResource

use of mom.trd.opentheso.core.alignment.SelectedResource in project opentheso by miledrousset.

the class GemetHelper method getTraductions.

/**
 * récupération des traductions
 *
 * @param jsonDatas
 * @param entity
 * @param languages
 * @return
 */
private ArrayList<SelectedResource> getTraductions(String jsonDatas, ArrayList<String> languages) {
    ArrayList<SelectedResource> traductions = new ArrayList<>();
    String lang;
    String value;
    // lecture du fichier Json des langues
    JsonArray dataArray;
    JsonObject dataObject;
    try (JsonReader reader = Json.createReader(new StringReader(jsonDatas))) {
        dataArray = reader.readArray();
        for (int i = 0; i < dataArray.size(); ++i) {
            dataObject = dataArray.getJsonObject(i);
            lang = dataObject.getString("language");
            value = dataObject.getString("string");
            if (lang == null || value == null || lang.isEmpty() || value.isEmpty())
                continue;
            if (languages.contains(lang)) {
                SelectedResource selectedResource = new SelectedResource();
                selectedResource.setIdLang(lang);
                selectedResource.setGettedValue(value);
                traductions.add(selectedResource);
            }
        }
    }
    return traductions;
}
Also used : JsonArray(javax.json.JsonArray) SelectedResource(mom.trd.opentheso.core.alignment.SelectedResource) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject) JsonReader(javax.json.JsonReader)

Example 19 with SelectedResource

use of mom.trd.opentheso.core.alignment.SelectedResource 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)

Aggregations

SelectedResource (mom.trd.opentheso.core.alignment.SelectedResource)19 ArrayList (java.util.ArrayList)13 JsonObject (javax.json.JsonObject)12 JsonValue (javax.json.JsonValue)10 JsonHelper (mom.trd.opentheso.core.json.helper.JsonHelper)10 IOException (java.io.IOException)7 MalformedURLException (java.net.MalformedURLException)6 JsonArray (javax.json.JsonArray)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 EndpointException (com.bordercloud.sparql.EndpointException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 StringReader (java.io.StringReader)2 JsonReader (javax.json.JsonReader)2 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)2 Endpoint (com.bordercloud.sparql.Endpoint)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 DownloadBean (mom.trd.opentheso.SelectedBeans.DownloadBean)1 Term (mom.trd.opentheso.bdd.datas.Term)1 ExternalImagesHelper (mom.trd.opentheso.bdd.helper.ExternalImagesHelper)1