Search in sources :

Example 11 with JsonHelper

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

the class RestRDFHelper method findAutocompleteConcepts__.

/**
 * recherche par valeur
 * @param ds
 * @param value
 * @param idTheso
 * @param lang
 * @return
 */
private String findAutocompleteConcepts__(HikariDataSource ds, String value, String idTheso, String lang, String group) {
    if (value == null || idTheso == null) {
        return null;
    }
    NodePreference nodePreference = new PreferencesHelper().getThesaurusPreferences(ds, idTheso);
    if (nodePreference == null) {
        return null;
    }
    SearchHelper searchHelper = new SearchHelper();
    JsonHelper jsonHelper = new JsonHelper();
    String uri;
    ArrayList<NodeAutoCompletion> nodeAutoCompletion;
    // recherche de toutes les valeurs
    nodeAutoCompletion = searchHelper.searchTermNewForAutocompletion(ds, value, lang, idTheso, group);
    if (nodeAutoCompletion == null || nodeAutoCompletion.isEmpty())
        return null;
    for (NodeAutoCompletion nodeAutoCompletion1 : nodeAutoCompletion) {
        uri = getUri(nodePreference, nodeAutoCompletion1, idTheso);
        jsonHelper.addJsonData(uri, nodeAutoCompletion1.getPrefLabel());
    }
    JsonArray datasJson = jsonHelper.getBuilder();
    if (datasJson != null)
        return datasJson.toString();
    else
        return null;
}
Also used : JsonArray(javax.json.JsonArray) JsonHelper(mom.trd.opentheso.core.json.helper.JsonHelper) NodePreference(mom.trd.opentheso.bdd.helper.nodes.NodePreference) SearchHelper(mom.trd.opentheso.bdd.helper.SearchHelper) NodeAutoCompletion(mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion) PreferencesHelper(mom.trd.opentheso.bdd.helper.PreferencesHelper)

Example 12 with JsonHelper

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

the class WikidataTest method getTraductionWikidata.

@Test
public void getTraductionWikidata() {
    String uri = "https://www.wikidata.org/entity/Q7748";
    String datas = getJsonFromURL(uri);
    JsonHelper jsonHelper = new JsonHelper();
    JsonObject jsonObject = jsonHelper.getJsonObject(datas);
    jsonObject.getString("");
}
Also used : JsonHelper(mom.trd.opentheso.core.json.helper.JsonHelper) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 13 with JsonHelper

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

the class WikidataTest method getTraductions.

private void getTraductions(String jsonDatas, String entity) {
    JsonHelper jsonHelper = new JsonHelper();
    JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
    // JsonObject test = jsonObject.getJsonObject("entities");
    JsonObject jsonObject1 = null;
    JsonValue jsonValue;
    try {
        jsonObject1 = jsonObject.getJsonObject("entities").getJsonObject(entity).getJsonObject("labels");
    } 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)

Example 14 with JsonHelper

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

the class WikidataTest method getImages.

private void 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
    StringBuffer url = new StringBuffer();
    url.append("https://commons.wikimedia.org/wiki/Special:FilePath/");
    JsonHelper jsonHelper = new JsonHelper();
    JsonObject jsonObject = jsonHelper.getJsonObject(jsonDatas);
    // JsonObject test = jsonObject.getJsonObject("entities");
    JsonObject jsonObject1 = null;
    JsonObject jsonObject2 = null;
    JsonValue jsonValue;
    try {
        // .getJsonObject("P18");
        jsonObject1 = jsonObject.getJsonObject("entities").getJsonObject(entity).getJsonObject("claims");
    } catch (Exception e) {
        System.err.println(e.toString());
        return;
    }
    try {
        // jsonValue =   jsonObject1.getJsonObject("P18");
        // System.out.println(jsonValue);
        JsonArray jsonArray = jsonObject1.getJsonArray("P18");
        for (int i = 0; i < jsonArray.size(); i++) {
            jsonObject2 = jsonArray.getJsonObject(0);
            jsonValue = jsonObject2.getJsonObject("mainsnak").getJsonObject("datavalue").get("value");
            url.append(jsonValue.toString().replace("\"", ""));
            System.out.println(url.toString());
        }
    } catch (Exception e) {
    }
}
Also used : JsonArray(javax.json.JsonArray) 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) Endpoint(com.bordercloud.sparql.Endpoint)

Example 15 with JsonHelper

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

the class GettyAATHelper 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) XMLStreamException(javax.xml.stream.XMLStreamException)

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