Search in sources :

Example 6 with SKOSLabel

use of skos.SKOSLabel in project opentheso by miledrousset.

the class WriteSkosBDD method getTraductionConcept.

/*
    public String getId(SKOSResource resource) {
        
        String id = "";
        
        if(resource.getSdc() != null){
            if(resource.getSdc().getIdentifier()!= null) {
                if(!resource.getSdc().getIdentifier().isEmpty()){
                    id = resource.getSdc().getIdentifier();
                }
            }
        }
        if(id.isEmpty()) {
            if (resource.getUri().contains("#")) {
                id = resource.getUri().substring(resource.getUri().indexOf("#") + 1, resource.getUri().length());
            }
            else
            {
                id = resource.getUri().substring(resource.getUri().lastIndexOf("/") + 1, resource.getUri().length());
            }
        }
        return id;
    }*/
/* 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 7 with SKOSLabel

use of skos.SKOSLabel in project opentheso by miledrousset.

the class WriteSkosBDD method writeThesaurus.

public void writeThesaurus(SKOSXmlDocument skosDocument, String dateFormat, boolean useArk, String adressSite, int idUser, String langueSource) {
    SKOSConceptScheme conceptScheme = skosDocument.getConceptScheme();
    ArrayList<SKOSTopConcept> topConceptsList = conceptScheme.getTopConceptsList();
    ArrayList<SKOSResource> resourcesList = skosDocument.getResourcesList();
    /*
         * Création du Thésaurus
         */
    String descriptionThesaurus = getThesaurusName(conceptScheme.getUri());
    // if(!query.thesaurusExistLangue(descriptionThesaurus, id_langueSource)) {
    ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
    Thesaurus thesaurus = new Thesaurus();
    thesaurus.setTitle(descriptionThesaurus);
    thesaurus.setLanguage(langueSource);
    String idThesaurus = thesaurusHelper.addThesaurus(ds, thesaurus, adressSite, useArk);
    if (idThesaurus == null)
        return;
    thesaurus.setId_thesaurus(idThesaurus);
    try {
        Connection conn = ds.getConnection();
        conn.setAutoCommit(false);
        UserHelper userHelper = new UserHelper();
        int idRole = userHelper.getRoleOfUser(ds, idUser);
        if (!userHelper.addRole(conn, idUser, idRole, idThesaurus, "")) {
            conn.rollback();
            conn.close();
            return;
        }
        conn.commit();
        conn.close();
    } catch (SQLException ex) {
        Logger.getLogger(WriteSkosBDD.class.getName()).log(Level.SEVERE, null, ex);
    }
    // Si le Titre du thésaurus n'est pas detecter, on donne un nom par defaut
    if (conceptScheme.getSkosLabels().isEmpty()) {
        if (thesaurus.getTitle().isEmpty()) {
            thesaurus.setTitle("Theso_" + idThesaurus);
            thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
        }
    }
    for (SKOSLabel skosLabel : conceptScheme.getSkosLabels()) {
        thesaurus.setTitle(skosLabel.getLabel());
        thesaurus.setLanguage(skosLabel.getLanguage());
        thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
    }
    idsTopConcept = new ArrayList<>();
    for (SKOSResource resource : resourcesList) {
        if (resource != null) {
            if (!isDescriptor(resource, topConceptsList)) {
                // on insère un domaine
                writeDomaine(resource, idThesaurus, "fr", adressSite, useArk, idUser);
            } else {
                // on insère un concept
                writeConcept(resource, idThesaurus, "fr", dateFormat, adressSite, useArk, idUser);
            }
        }
    }
    // ici la fin du fichier on controle si le thésaurus a toutes les langues des concepts
    // Vérifier l'existence de la langue et l'ajouter si elle n'existe pas déjà
    addLangsToThesaurus(ds, idThesaurus);
}
Also used : UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SKOSLabel(skos.SKOSLabel) SKOSResource(skos.SKOSResource) Thesaurus(mom.trd.opentheso.bdd.datas.Thesaurus) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) SKOSConceptScheme(skos.SKOSConceptScheme) SKOSTopConcept(skos.SKOSTopConcept)

Example 8 with SKOSLabel

use of skos.SKOSLabel in project opentheso by miledrousset.

the class SkosToJsonld method addLabels.

private void addLabels(ArrayList<SKOSLabel> sKOSLabels) {
    ArrayList<SKOSLabel> prefLabel = new ArrayList<>();
    ArrayList<SKOSLabel> altLabel = new ArrayList<>();
    StringPlus stringPlus = new StringPlus();
    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()) {
        if (prefLabel.size() > 1) {
            endElement();
            prefLabelString = "      \"" + nameSpaceSkosCore + "prefLabel" + "\": [\n";
            boolean first = true;
            for (SKOSLabel prefLabel1 : prefLabel) {
                if (!first)
                    prefLabelString += ",\n";
                prefLabelString += "        {\n";
                prefLabelString += "          \"@language\": \"" + prefLabel1.getLanguage() + "\",\n";
                prefLabelString += "          \"@value\": \"" + stringPlus.normalizeStringForXml(prefLabel1.getLabel()) + "\"\n";
                prefLabelString += "        }";
                first = false;
            }
            prefLabelString += "\n      ]";
        } else {
            endElement();
            prefLabelString = "      \"" + nameSpaceSkosCore + "prefLabel" + "\": {\n";
            for (SKOSLabel prefLabel1 : prefLabel) {
                prefLabelString += "        \"@language\": \"" + prefLabel1.getLanguage() + "\",\n";
                prefLabelString += "        \"@value\": \"" + stringPlus.normalizeStringForXml(prefLabel1.getLabel()) + "\"\n";
                prefLabelString += "      }";
            }
        }
        jsonLd.append(prefLabelString);
    }
    // altLables
    String altLabelString;
    if (!altLabel.isEmpty()) {
        if (altLabel.size() > 1) {
            endElement();
            altLabelString = "      \"" + nameSpaceSkosCore + "altLabel" + "\": [\n";
            boolean first = true;
            for (SKOSLabel altLabel1 : altLabel) {
                if (!first)
                    altLabelString += ",\n";
                altLabelString += "        {\n";
                altLabelString += "          \"@language\": \"" + altLabel1.getLanguage() + "\",\n";
                altLabelString += "          \"@value\": \"" + stringPlus.normalizeStringForXml(altLabel1.getLabel()) + "\"\n";
                altLabelString += "        }";
                first = false;
            }
            altLabelString += "\n      ]";
        } else {
            endElement();
            altLabelString = "      \"" + nameSpaceSkosCore + "altLabel" + "\": {\n";
            for (SKOSLabel altLabel1 : altLabel) {
                altLabelString += "        \"@language\": \"" + altLabel1.getLanguage() + "\",\n";
                altLabelString += "        \"@value\": \"" + stringPlus.normalizeStringForXml(altLabel1.getLabel()) + "\"\n";
                altLabelString += "      }";
            }
        }
        jsonLd.append(altLabelString);
    }
}
Also used : StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) ArrayList(java.util.ArrayList) SKOSLabel(skos.SKOSLabel)

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