Search in sources :

Example 1 with SelectedResource

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

the class AgrovocHelper method getTraductions.

/**
 * récupération des traductions
 *
 * @param jsonDatas
 * @param entity
 * @param languages
 * @return
 */
private ArrayList<SelectedResource> getTraductions(String xmlDatas, ArrayList<String> languages) {
    ArrayList<SelectedResource> traductions = new ArrayList<>();
    ArrayList<SelectedResource> descriptions = new ArrayList<>();
    String lang;
    String value;
    InputStream inputStream;
    SKOSXmlDocument sxd;
    try {
        inputStream = new ByteArrayInputStream(xmlDatas.getBytes("UTF-8"));
        // / read XML SKOS
        ReadRdf4j readRdf4j = new ReadRdf4j(inputStream, 0);
        sxd = readRdf4j.getsKOSXmlDocument();
        for (SKOSResource resource : sxd.getConceptList()) {
            for (SKOSLabel label : resource.getLabelsList()) {
                switch(label.getProperty()) {
                    case SKOSProperty.prefLabel:
                        lang = label.getLanguage();
                        value = label.getLabel();
                        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);
                        }
                        break;
                    default:
                        break;
                }
            }
            for (SKOSDocumentation sd : resource.getDocumentationsList()) {
                if (sd.getProperty() == SKOSProperty.definition) {
                    value = sd.getText();
                    lang = sd.getLanguage();
                    if (lang == null || value == null || lang.isEmpty() || value.isEmpty())
                        continue;
                    if (languages.contains(lang)) {
                        SelectedResource selectedResource = new SelectedResource();
                        selectedResource.setIdLang(lang);
                        selectedResource.setGettedValue(value);
                        descriptions.add(selectedResource);
                    }
                }
            }
        }
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(OpenthesoHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    resourceDefinitions = descriptions;
    return traductions;
}
Also used : ReadRdf4j(mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j) SelectedResource(mom.trd.opentheso.core.alignment.SelectedResource) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DownloadBean(mom.trd.opentheso.SelectedBeans.DownloadBean) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SKOSXmlDocument(mom.trd.opentheso.skosapi.SKOSXmlDocument) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel) IOException(java.io.IOException) SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) SKOSDocumentation(mom.trd.opentheso.skosapi.SKOSDocumentation) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 2 with SelectedResource

use of mom.trd.opentheso.core.alignment.SelectedResource 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;
}
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 3 with SelectedResource

use of mom.trd.opentheso.core.alignment.SelectedResource 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;
}
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) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with SelectedResource

use of mom.trd.opentheso.core.alignment.SelectedResource 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;
}
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 5 with SelectedResource

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

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