Search in sources :

Example 1 with SKOSLabel

use of mom.trd.opentheso.skosapi.SKOSLabel in project opentheso by miledrousset.

the class rdf4jFileBean method insertCandidatesBDD.

/**
 * insrt un thésaurus dans la BDD
 *
 * #### temporaire ###
 * ### permet d'ajouter une liste de candidats d'après un fichier SKOS ####
 */
public void insertCandidatesBDD() {
    error = new StringBuffer();
    info = "";
    warning = "";
    CandidateHelper candidateHelper = new CandidateHelper();
    String idParentConcept;
    String notes;
    String idArk;
    String idConcept = null;
    progress = 0;
    progress_abs = 0;
    for (SKOSResource sKOSResource : sKOSXmlDocument.getConceptList()) {
        for (SKOSLabel sKOSLabel : sKOSResource.getLabelsList()) {
            idParentConcept = "";
            if (sKOSLabel.getProperty() == SKOSProperty.prefLabel) {
                if (sKOSLabel.getLanguage().equalsIgnoreCase("fr")) {
                    notes = getNotes(sKOSResource);
                    idArk = getIdParentConcept(sKOSResource);
                    if (idArk != null)
                        idParentConcept = new ConceptHelper().getIdConceptFromArkId(connect.getPoolConnexion(), idArk);
                    try {
                        Connection conn = connect.getPoolConnexion().getConnection();
                        idConcept = candidateHelper.addCandidat_rollBack(conn, sKOSLabel.getLabel(), sKOSLabel.getLanguage(), roleOnTheso.getIdTheso(), currentUser.getUser().getIdUser(), notes, idParentConcept, "");
                        if (idConcept == null) {
                            conn.rollback();
                            conn.close();
                            continue;
                        }
                        conn.commit();
                        conn.close();
                    } catch (SQLException ex) {
                        java.util.logging.Logger.getLogger(rdf4jFileBean.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    if (idConcept != null) {
                        candidateHelper.addTermCandidatTraduction(connect.getPoolConnexion(), idConcept, sKOSLabel.getLabel(), sKOSLabel.getLanguage(), roleOnTheso.getIdTheso(), currentUser.getUser().getIdUser());
                    }
                }
            }
        }
    }
}
Also used : SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel) CandidateHelper(mom.trd.opentheso.bdd.helper.CandidateHelper)

Example 2 with SKOSLabel

use of mom.trd.opentheso.skosapi.SKOSLabel 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 3 with SKOSLabel

use of mom.trd.opentheso.skosapi.SKOSLabel in project opentheso by miledrousset.

the class WriteRdf4j method writeLabel.

private void writeLabel(SKOSResource resource) {
    int prop;
    for (SKOSLabel label : resource.getLabelsList()) {
        prop = label.getProperty();
        Literal literal = vf.createLiteral(label.getLabel(), label.getLanguage());
        switch(prop) {
            case SKOSProperty.prefLabel:
                builder.add(SKOS.PREF_LABEL, literal);
                break;
            case SKOSProperty.altLabel:
                builder.add(SKOS.ALT_LABEL, literal);
                break;
            case SKOSProperty.hiddenLabel:
                builder.add(SKOS.HIDDEN_LABEL, literal);
                break;
            default:
                break;
        }
    }
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel)

Example 4 with SKOSLabel

use of mom.trd.opentheso.skosapi.SKOSLabel in project opentheso by miledrousset.

the class ImportRdf4jHelper method addGroup.

private String addGroup(SKOSResource group) {
    // récupération des groups ou domaine
    GroupHelper groupHelper = new GroupHelper();
    String idGroup = getIdFromUri(group.getUri());
    ArrayList<SKOSNotation> notationList = group.getNotationList();
    SKOSNotation notation = null;
    if (notationList != null && !notationList.isEmpty()) {
        notation = notationList.get(0);
    }
    String notationValue;
    if (notation == null) {
        notationValue = "";
    } else {
        notationValue = notation.getNotation();
    }
    String type;
    switch(group.getProperty()) {
        case SKOSProperty.Collection:
            type = "C";
            break;
        case SKOSProperty.ConceptGroup:
            type = "G";
            break;
        case SKOSProperty.MicroThesaurus:
        default:
            type = "MT";
            break;
        case SKOSProperty.Theme:
            type = "T";
            break;
    }
    groupHelper.insertGroup(ds, idGroup, idTheso, type, notationValue, "", false, idUser);
    // sub group
    String idSubGroup;
    // concept group concept
    String idSubConcept;
    for (SKOSRelation relation : group.getRelationsList()) {
        int prop = relation.getProperty();
        switch(prop) {
            case SKOSProperty.subGroup:
                idSubGroup = getIdFromUri(relation.getTargetUri());
                groupHelper.addSubGroup(ds, idGroup, idSubGroup, idTheso);
                break;
            case SKOSProperty.member:
                // option cochée
                /*   if(identifierType.equalsIgnoreCase("sans")){
                            idSubConcept = getIdFromUri(relation.getTargetUri());
                        } else {*/
                // Récupération de l'Id d'origine sauvegardé à l'import (idArk -> identifier)
                idSubConcept = getOriginalId(relation.getTargetUri());
                // }
                groupHelper.addConceptGroupConcept(ds, idGroup, idSubConcept, idTheso);
                memberHashMap.put(relation.getTargetUri(), idGroup);
                break;
            case SKOSProperty.hasTopConcept:
                hasTopConcceptList.add(relation.getTargetUri());
                break;
            default:
                break;
        }
    }
    for (SKOSLabel label : group.getLabelsList()) {
        // ajouter les traductions des Groupes
        ConceptGroupLabel conceptGroupLabel = new ConceptGroupLabel();
        conceptGroupLabel.setIdgroup(idGroup);
        conceptGroupLabel.setIdthesaurus(idTheso);
        conceptGroupLabel.setLang(label.getLanguage());
        conceptGroupLabel.setLexicalvalue(label.getLabel());
        groupHelper.addGroupTraduction(ds, conceptGroupLabel, idUser);
    }
    return idGroup;
}
Also used : ConceptGroupLabel(mom.trd.opentheso.bdd.datas.ConceptGroupLabel) SKOSRelation(mom.trd.opentheso.skosapi.SKOSRelation) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) SKOSNotation(mom.trd.opentheso.skosapi.SKOSNotation)

Example 5 with SKOSLabel

use of mom.trd.opentheso.skosapi.SKOSLabel in project opentheso by miledrousset.

the class ImportRdf4jHelper method addGroups.

public void addGroups(rdf4jFileBean fileBean) {
    // récupération des groups ou domaine
    GroupHelper groupHelper = new GroupHelper();
    String idGroup;
    for (SKOSResource group : skosXmlDocument.getGroupList()) {
        fileBean.setAbs_progress(fileBean.getAbs_progress() + 1);
        fileBean.setProgress(fileBean.getAbs_progress() / fileBean.getTotal() * 100);
        idGroup = getIdFromUri(group.getUri());
        if (idGroup == null || idGroup.isEmpty())
            idGroup = group.getUri();
        ArrayList<SKOSNotation> notationList = group.getNotationList();
        SKOSNotation notation = null;
        if (notationList != null && !notationList.isEmpty()) {
            notation = notationList.get(0);
        }
        String notationValue;
        if (notation == null) {
            notationValue = "";
        } else {
            notationValue = notation.getNotation();
        }
        String type;
        switch(group.getProperty()) {
            case SKOSProperty.Collection:
                type = "C";
                break;
            case SKOSProperty.ConceptGroup:
                type = "G";
                break;
            case SKOSProperty.MicroThesaurus:
            default:
                type = "MT";
                break;
            case SKOSProperty.Theme:
                type = "T";
                break;
        }
        groupHelper.insertGroup(ds, idGroup, thesaurus.getId_thesaurus(), type, notationValue, "", false, idUser);
        // / permet de grouper tous les id des groupes du thésaurus à importer.
        idGroups.add(idGroup);
        // sub group
        String idSubGroup;
        // concept group concept
        String idSubConcept;
        for (SKOSRelation relation : group.getRelationsList()) {
            int prop = relation.getProperty();
            switch(prop) {
                case SKOSProperty.subGroup:
                    idSubGroup = getIdFromUri(relation.getTargetUri());
                    groupHelper.addSubGroup(ds, idGroup, idSubGroup, thesaurus.getId_thesaurus());
                    break;
                case SKOSProperty.member:
                    // option cochée
                    /*   if(identifierType.equalsIgnoreCase("sans")){
                            idSubConcept = getIdFromUri(relation.getTargetUri());
                        } else {*/
                    // Récupération de l'Id d'origine sauvegardé à l'import (idArk -> identifier)
                    idSubConcept = getOriginalId(relation.getTargetUri());
                    // }
                    groupSubGroup.put(idSubConcept, idGroup);
                    // groupHelper.addConceptGroupConcept(ds, idGroup, idSubConcept, thesaurus.getId_thesaurus());
                    memberHashMap.put(relation.getTargetUri(), idGroup);
                    break;
                case SKOSProperty.hasTopConcept:
                    hasTopConcceptList.add(relation.getTargetUri());
                    break;
                default:
                    break;
            }
        }
        for (SKOSLabel label : group.getLabelsList()) {
            // ajouter les traductions des Groupes
            ConceptGroupLabel conceptGroupLabel = new ConceptGroupLabel();
            conceptGroupLabel.setIdgroup(idGroup);
            conceptGroupLabel.setIdthesaurus(thesaurus.getId_thesaurus());
            conceptGroupLabel.setLang(label.getLanguage());
            conceptGroupLabel.setLexicalvalue(label.getLabel());
            groupHelper.addGroupTraduction(ds, conceptGroupLabel, idUser);
        }
    }
    addGroupConceptGroup();
/*
        groupHelper.insertGroup(ds,
                idGroupDefault,
                thesaurus.getId_thesaurus(),
                "MT",
                "", //notation
                adressSite,
                useArk,
                idUser);
         */
// Création du domaine par défaut
// ajouter les traductions des Groupes
/*ConceptGroupLabel conceptGroupLabel = new ConceptGroupLabel();
        conceptGroupLabel.setIdgroup(idGroupDefault);
        conceptGroupLabel.setIdthesaurus(thesaurus.getId_thesaurus());
        
        conceptGroupLabel.setLang(langueSource);
        conceptGroupLabel.setLexicalvalue("groupDefault");
        groupHelper.addGroupTraduction(ds, conceptGroupLabel, idUser);*/
}
Also used : SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) ConceptGroupLabel(mom.trd.opentheso.bdd.datas.ConceptGroupLabel) SKOSRelation(mom.trd.opentheso.skosapi.SKOSRelation) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) SKOSNotation(mom.trd.opentheso.skosapi.SKOSNotation)

Aggregations

SKOSLabel (mom.trd.opentheso.skosapi.SKOSLabel)11 SKOSResource (mom.trd.opentheso.skosapi.SKOSResource)7 SKOSRelation (mom.trd.opentheso.skosapi.SKOSRelation)4 Connection (java.sql.Connection)3 SKOSDocumentation (mom.trd.opentheso.skosapi.SKOSDocumentation)3 Paragraph (com.itextpdf.text.Paragraph)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 DownloadBean (mom.trd.opentheso.SelectedBeans.DownloadBean)2 ConceptGroupLabel (mom.trd.opentheso.bdd.datas.ConceptGroupLabel)2 CandidateHelper (mom.trd.opentheso.bdd.helper.CandidateHelper)2 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)2 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)2 ReadRdf4j (mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j)2 SKOSNotation (mom.trd.opentheso.skosapi.SKOSNotation)2 SKOSXmlDocument (mom.trd.opentheso.skosapi.SKOSXmlDocument)2