Search in sources :

Example 1 with SKOSLabel

use of skos.SKOSLabel in project opentheso by miledrousset.

the class WriteBranchSkosBDD method writeLabelsList.

public ArrayList<NodeEM> writeLabelsList(HikariDataSource ds, ArrayList<SKOSLabel> labelsList) {
    ArrayList<NodeEM> nodeEMList = new ArrayList<>();
    for (int i = 0; i < labelsList.size(); i++) {
        SKOSLabel label = labelsList.get(i);
        switch(label.getProperty()) {
            case SKOSProperty.altLabel:
                NodeEM nodeEM = new NodeEM();
                nodeEM.setLexical_value(label.getLabel());
                nodeEM.setLang(label.getLanguage());
                nodeEM.setSource("");
                nodeEM.setStatus("USE");
                nodeEM.setHiden(false);
                nodeEMList.add(nodeEM);
                break;
            default:
                break;
        }
    }
    return nodeEMList;
}
Also used : ArrayList(java.util.ArrayList) SKOSLabel(skos.SKOSLabel) NodeEM(mom.trd.opentheso.bdd.helper.nodes.NodeEM)

Example 2 with SKOSLabel

use of skos.SKOSLabel in project opentheso by miledrousset.

the class AlignmentQuery method queryOpentheso.

/**
 * Cette fonction permet de récupérer les alignements présents sur Opentheso
 * pour un concept passé en paramètre et un thésaurus donné
 *
 * @param idC
 * @param idTheso
 * @param lexicalValue
 * @param lang
 * @param requete
 * @param source
 * @return
 */
public ArrayList<NodeAlignment> queryOpentheso(String idC, String idTheso, String lexicalValue, String lang, String requete, String source) {
    if (requete.trim().equals("")) {
        return null;
    }
    if (lexicalValue.trim().equals("")) {
        return null;
    }
    listeAlign = new ArrayList<>();
    // construction de la requête de type (webservices Opentheso)
    lexicalValue = lexicalValue.replaceAll(" ", "%20");
    requete = requete.replace("##lang##", lang);
    requete = requete.replace("##value##", lexicalValue);
    try {
        URL url = new URL(requete);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/xml");
        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
        }
        BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
        String output;
        String xmlRecord = "";
        while ((output = br.readLine()) != null) {
            xmlRecord += output;
        }
        byte[] bytes = xmlRecord.getBytes();
        xmlRecord = new String(bytes, Charset.forName("UTF-8"));
        conn.disconnect();
        StringBuffer sb = new StringBuffer(xmlRecord);
        try {
            SKOSXmlDocument sxd = new ReadFileSKOS().readStringBuffer(sb);
            for (SKOSResource resource : sxd.getResourcesList()) {
                NodeAlignment na = new NodeAlignment();
                na.setInternal_id_concept(idC);
                na.setInternal_id_thesaurus(idTheso);
                // "Pactols");
                na.setThesaurus_target(source);
                na.setUri_target(resource.getUri());
                for (SKOSLabel label : resource.getLabelsList()) {
                    switch(label.getProperty()) {
                        case SKOSProperty.prefLabel:
                            if (label.getLanguage().equals(lang)) {
                                na.setConcept_target(label.getLabel());
                            }
                            break;
                        case SKOSProperty.altLabel:
                            if (label.getLanguage().equals(lang)) {
                                if (na.getConcept_target_alt().isEmpty()) {
                                    na.setConcept_target_alt(label.getLabel());
                                } else {
                                    na.setConcept_target_alt(na.getConcept_target_alt() + ";" + label.getLabel());
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
                for (SKOSDocumentation sd : resource.getDocumentationsList()) {
                    if (sd.getProperty() == SKOSProperty.definition && sd.getLanguage().equals(lang)) {
                        na.setDef_target(sd.getText());
                    }
                }
                listeAlign.add(na);
            }
        } catch (Exception ex) {
            Logger.getLogger(AlignmentQuery.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
    return listeAlign;
}
Also used : MalformedURLException(java.net.MalformedURLException) SKOSXmlDocument(skos.SKOSXmlDocument) SKOSLabel(skos.SKOSLabel) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) SAXException(org.xml.sax.SAXException) NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) HttpURLConnection(java.net.HttpURLConnection) SKOSResource(skos.SKOSResource) SKOSDocumentation(skos.SKOSDocumentation) ReadFileSKOS(mom.trd.opentheso.core.imports.old.ReadFileSKOS)

Example 3 with SKOSLabel

use of skos.SKOSLabel in project opentheso by miledrousset.

the class SkosToJsonldSchemaOrg method addLabels.

private void addLabels(ArrayList<SKOSLabel> sKOSLabels) {
    ArrayList<SKOSLabel> prefLabel = new ArrayList<>();
    ArrayList<SKOSLabel> altLabel = new ArrayList<>();
    for (SKOSLabel sKOSLabel : sKOSLabels) {
        switch(sKOSLabel.getProperty()) {
            case SKOSProperty.prefLabel:
                prefLabel.add(sKOSLabel);
                break;
            case SKOSProperty.altLabel:
                altLabel.add(sKOSLabel);
                break;
            default:
                break;
        }
    }
    // prefLabls
    String prefLabelString;
    if (!prefLabel.isEmpty()) {
        endElement();
        prefLabelString = "      \"name" + "\": [\n";
        boolean first = true;
        for (SKOSLabel prefLabel1 : prefLabel) {
            if (!first)
                prefLabelString += ",\n";
            prefLabelString += "        {\n";
            prefLabelString += "          \"@language\": \"" + prefLabel1.getLanguage() + "\",\n";
            prefLabelString += "          \"@value\": \"" + prefLabel1.getLabel() + "\"\n";
            prefLabelString += "        }";
            first = false;
        }
        prefLabelString += "\n      ]";
        jsonLd.append(prefLabelString);
    }
    // altLables
    String altLabelString;
    if (!altLabel.isEmpty()) {
        endElement();
        altLabelString = "      \"alternateName" + "\": [\n";
        boolean first = true;
        for (SKOSLabel altLabel1 : altLabel) {
            if (!first)
                altLabelString += ",\n";
            altLabelString += "        {\n";
            altLabelString += "          \"@language\": \"" + altLabel1.getLanguage() + "\",\n";
            altLabelString += "          \"@value\": \"" + altLabel1.getLabel() + "\"\n";
            altLabelString += "        }";
            first = false;
        }
        altLabelString += "\n      ]";
        jsonLd.append(altLabelString);
    }
}
Also used : ArrayList(java.util.ArrayList) SKOSLabel(skos.SKOSLabel)

Example 4 with SKOSLabel

use of skos.SKOSLabel in project opentheso by miledrousset.

the class WriteBranchSkosBDD method getTraductionConcept.

/*    public String getId(String uri) {
        if (uri.contains("#")) {
            uri = uri.substring(uri.indexOf("#") + 1, uri.length());
        }
        else
        {
            uri = uri.substring(uri.lastIndexOf("/") + 1, uri.length());
        }
        return uri;
    }
*/
/* Pour un concept */
public ArrayList<NodeTermTraduction> getTraductionConcept(ArrayList<SKOSLabel> labelsList) {
    ArrayList<NodeTermTraduction> nodeTermTraductionList = new ArrayList<>();
    for (int i = 0; i < labelsList.size(); i++) {
        SKOSLabel label = labelsList.get(i);
        switch(label.getProperty()) {
            case SKOSProperty.prefLabel:
                NodeTermTraduction nodeTermTraduction = new NodeTermTraduction();
                nodeTermTraduction.setLexicalValue(label.getLabel());
                nodeTermTraduction.setLang(label.getLanguage());
                nodeTermTraductionList.add(nodeTermTraduction);
                break;
            default:
                break;
        }
    }
    return nodeTermTraductionList;
}
Also used : ArrayList(java.util.ArrayList) SKOSLabel(skos.SKOSLabel) NodeTermTraduction(mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction)

Example 5 with SKOSLabel

use of skos.SKOSLabel in project opentheso by miledrousset.

the class WriteSkosBDD method writeLabelsList.

public ArrayList<NodeEM> writeLabelsList(HikariDataSource ds, ArrayList<SKOSLabel> labelsList) {
    ArrayList<NodeEM> nodeEMList = new ArrayList<>();
    for (int i = 0; i < labelsList.size(); i++) {
        SKOSLabel label = labelsList.get(i);
        switch(label.getProperty()) {
            case SKOSProperty.altLabel:
                NodeEM nodeEM = new NodeEM();
                nodeEM.setLexical_value(label.getLabel());
                nodeEM.setLang(label.getLanguage());
                nodeEM.setSource("");
                nodeEM.setStatus("USE");
                nodeEM.setHiden(false);
                nodeEMList.add(nodeEM);
                break;
            default:
                break;
        }
    }
    return nodeEMList;
}
Also used : ArrayList(java.util.ArrayList) SKOSLabel(skos.SKOSLabel) NodeEM(mom.trd.opentheso.bdd.helper.nodes.NodeEM)

Aggregations

SKOSLabel (skos.SKOSLabel)8 ArrayList (java.util.ArrayList)6 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)2 NodeTermTraduction (mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction)2 SKOSResource (skos.SKOSResource)2 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Thesaurus (mom.trd.opentheso.bdd.datas.Thesaurus)1 ThesaurusHelper (mom.trd.opentheso.bdd.helper.ThesaurusHelper)1 UserHelper (mom.trd.opentheso.bdd.helper.UserHelper)1 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)1 StringPlus (mom.trd.opentheso.bdd.tools.StringPlus)1 ReadFileSKOS (mom.trd.opentheso.core.imports.old.ReadFileSKOS)1 SAXException (org.xml.sax.SAXException)1 SKOSConceptScheme (skos.SKOSConceptScheme)1 SKOSDocumentation (skos.SKOSDocumentation)1 SKOSTopConcept (skos.SKOSTopConcept)1