Search in sources :

Example 1 with SKOSDocumentation

use of skos.SKOSDocumentation 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 2 with SKOSDocumentation

use of skos.SKOSDocumentation in project opentheso by miledrousset.

the class SkosToJsonld method addNote.

private void addNote(ArrayList<SKOSDocumentation> note, String noteType) {
    StringPlus stringPlus = new StringPlus();
    String labelString;
    if (!note.isEmpty()) {
        if (note.size() > 1) {
            endElement();
            labelString = "      \"" + nameSpaceSkosCore + noteType + "\": [\n";
            boolean first = true;
            for (SKOSDocumentation sKOSDocumentation : note) {
                if (!first)
                    labelString += ",\n";
                labelString += "        {\n";
                labelString += "          \"@language\": \"" + sKOSDocumentation.getLanguage() + "\",\n";
                labelString += "          \"@value\": \"" + stringPlus.normalizeStringForXml(sKOSDocumentation.getText()) + "\"\n";
                labelString += "        }";
                first = false;
            }
            labelString += "\n      ]";
        } else {
            endElement();
            labelString = "      \"" + nameSpaceSkosCore + noteType + "\": {\n";
            for (SKOSDocumentation sKOSDocumentation : note) {
                labelString += "        \"@language\": \"" + sKOSDocumentation.getLanguage() + "\",\n";
                labelString += "        \"@value\": \"" + stringPlus.normalizeStringForXml(sKOSDocumentation.getText()) + "\"\n";
                labelString += "      }";
            }
        }
        jsonLd.append(labelString);
    }
}
Also used : SKOSDocumentation(skos.SKOSDocumentation) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus)

Example 3 with SKOSDocumentation

use of skos.SKOSDocumentation in project opentheso by miledrousset.

the class SkosToJsonldSchemaOrg method addDocumentations.

private void addDocumentations(ArrayList<SKOSDocumentation> documentations) {
    for (SKOSDocumentation documentation : documentations) {
        switch(documentation.getProperty()) {
            case SKOSProperty.definition:
                endElement();
                addElementDocumentation(documentation, "definition");
                break;
            default:
                break;
        }
    }
}
Also used : SKOSDocumentation(skos.SKOSDocumentation)

Example 4 with SKOSDocumentation

use of skos.SKOSDocumentation in project opentheso by miledrousset.

the class WriteBranchSkosBDD method addNotes.

public ArrayList<NodeNote> addNotes(ArrayList<SKOSDocumentation> documentationsList) {
    ArrayList<NodeNote> nodeNotes = new ArrayList<>();
    for (int i = 0; i < documentationsList.size(); i++) {
        SKOSDocumentation documentation = documentationsList.get(i);
        switch(documentation.getProperty()) {
            case SKOSProperty.scopeNote:
                NodeNote nodeNote = new NodeNote();
                nodeNote.setLang(documentation.getLanguage());
                nodeNote.setLexicalvalue(documentation.getText());
                nodeNote.setNotetypecode("scopeNote");
                nodeNotes.add(nodeNote);
                break;
            case SKOSProperty.historyNote:
                NodeNote nodeNote2 = new NodeNote();
                nodeNote2.setLang(documentation.getLanguage());
                nodeNote2.setLexicalvalue(documentation.getText());
                nodeNote2.setNotetypecode("historyNote");
                nodeNotes.add(nodeNote2);
                break;
            case SKOSProperty.definition:
                NodeNote nodeNote3 = new NodeNote();
                nodeNote3.setLang(documentation.getLanguage());
                nodeNote3.setLexicalvalue(documentation.getText());
                nodeNote3.setNotetypecode("definition");
                nodeNotes.add(nodeNote3);
                break;
            case SKOSProperty.editorialNote:
                NodeNote nodeNote4 = new NodeNote();
                nodeNote4.setLang(documentation.getLanguage());
                nodeNote4.setLexicalvalue(documentation.getText());
                nodeNote4.setNotetypecode("editorialNote");
                nodeNotes.add(nodeNote4);
                break;
            default:
                break;
        }
    }
    return nodeNotes;
}
Also used : SKOSDocumentation(skos.SKOSDocumentation) ArrayList(java.util.ArrayList) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)

Example 5 with SKOSDocumentation

use of skos.SKOSDocumentation in project opentheso by miledrousset.

the class WriteSkosBDD method addNotes.

public ArrayList<NodeNote> addNotes(ArrayList<SKOSDocumentation> documentationsList) {
    ArrayList<NodeNote> nodeNotes = new ArrayList<>();
    for (int i = 0; i < documentationsList.size(); i++) {
        SKOSDocumentation documentation = documentationsList.get(i);
        switch(documentation.getProperty()) {
            case SKOSProperty.scopeNote:
                NodeNote nodeNote = new NodeNote();
                nodeNote.setLang(documentation.getLanguage());
                nodeNote.setLexicalvalue(documentation.getText());
                nodeNote.setNotetypecode("scopeNote");
                nodeNotes.add(nodeNote);
                break;
            case SKOSProperty.historyNote:
                NodeNote nodeNote2 = new NodeNote();
                nodeNote2.setLang(documentation.getLanguage());
                nodeNote2.setLexicalvalue(documentation.getText());
                nodeNote2.setNotetypecode("historyNote");
                nodeNotes.add(nodeNote2);
                break;
            case SKOSProperty.definition:
                NodeNote nodeNote3 = new NodeNote();
                nodeNote3.setLang(documentation.getLanguage());
                nodeNote3.setLexicalvalue(documentation.getText());
                nodeNote3.setNotetypecode("definition");
                nodeNotes.add(nodeNote3);
                break;
            case SKOSProperty.editorialNote:
                NodeNote nodeNote4 = new NodeNote();
                nodeNote4.setLang(documentation.getLanguage());
                nodeNote4.setLexicalvalue(documentation.getText());
                nodeNote4.setNotetypecode("editorialNote");
                nodeNotes.add(nodeNote4);
                break;
            case SKOSProperty.note:
                NodeNote nodeNote5 = new NodeNote();
                nodeNote5.setLang(documentation.getLanguage());
                nodeNote5.setLexicalvalue(documentation.getText());
                nodeNote5.setNotetypecode("note");
                nodeNotes.add(nodeNote5);
                break;
            default:
                break;
        }
    }
    return nodeNotes;
}
Also used : SKOSDocumentation(skos.SKOSDocumentation) ArrayList(java.util.ArrayList) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)

Aggregations

SKOSDocumentation (skos.SKOSDocumentation)6 ArrayList (java.util.ArrayList)3 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)2 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)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 SKOSLabel (skos.SKOSLabel)1 SKOSResource (skos.SKOSResource)1 SKOSXmlDocument (skos.SKOSXmlDocument)1