Search in sources :

Example 21 with NoteHelper

use of mom.trd.opentheso.bdd.helper.NoteHelper in project opentheso by miledrousset.

the class WriteBranchSkosBDD method writeConcept.

private void writeConcept(SKOSResource resource, String idConcept, String idGroup, String idThesaurus, String id_langueSource, String dateFormat, String adressSite, boolean useArk, int idUser) {
    // ajout du concept dans la base
    Concept concept = new Concept();
    ConceptHelper conceptHelper = new ConceptHelper();
    if (idConcept.trim().isEmpty())
        return;
    String idC = getId(resource.getUri());
    concept.setIdConcept(idC);
    // concept.setCreated(null);
    concept.setIdThesaurus(idThesaurus);
    concept.setNotation("");
    concept.setStatus("");
    concept.setTopConcept(false);
    concept.setIdGroup(idGroup);
    concept = addDates(resource.getDateList(), concept, dateFormat);
    if (idGroup.trim().isEmpty())
        return;
    conceptHelper.insertConceptInTable(ds, concept, idUser);
    // ajout des termes et traductions
    NodeTerm nodeTerm = new NodeTerm();
    nodeTerm.setNodeTermTraduction(getTraductionConcept(resource.getLabelsList()));
    nodeTerm.setIdTerm(idC);
    nodeTerm.setIdConcept(idC);
    nodeTerm.setIdThesaurus(idThesaurus);
    nodeTerm.setSource("");
    nodeTerm.setStatus("");
    nodeTerm = addDatesTerm(resource.getDateList(), nodeTerm, dateFormat);
    TermHelper termHelper = new TermHelper();
    termHelper.insertTerm(ds, nodeTerm, idUser);
    // ajouter les notes
    ArrayList<NodeNote> nodeNoteList = addNotes(resource.getDocumentationsList());
    NoteHelper noteHelper = new NoteHelper();
    for (NodeNote nodeNoteList1 : nodeNoteList) {
        if (nodeNoteList1.getNotetypecode().contains("scopeNote")) {
            noteHelper.addConceptNote(ds, concept.getIdConcept(), nodeNoteList1.getLang(), idThesaurus, nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
        }
        if (nodeNoteList1.getNotetypecode().contains("historyNote")) {
            noteHelper.addConceptNote(ds, concept.getIdConcept(), nodeNoteList1.getLang(), idThesaurus, nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
        }
        if (nodeNoteList1.getNotetypecode().contains("definition")) {
            noteHelper.addTermNote(ds, nodeTerm.getIdTerm(), nodeNoteList1.getLang(), idThesaurus, nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
        }
        if (nodeNoteList1.getNotetypecode().contains("editorialNote")) {
            noteHelper.addTermNote(ds, nodeTerm.getIdTerm(), nodeNoteList1.getLang(), idThesaurus, nodeNoteList1.getLexicalvalue(), nodeNoteList1.getNotetypecode(), idUser);
        }
    }
    // Enregistrer les relations
    writeRelationsList(resource.getRelationsList(), concept.getIdConcept(), idThesaurus, idUser);
    ArrayList<SKOSMapping> sKOSMappings = resource.getMappings();
    // Enregistrer les Mappings (alignements)
    AlignmentHelper alignmentHelper = new AlignmentHelper();
    for (SKOSMapping sKOSMapping : sKOSMappings) {
        if (sKOSMapping.getProperty() == SKOSProperty.exactMatch) {
            alignmentHelper.addNewAlignment(ds, // user
            1, // concept target
            "", // thesaurus target
            "", // URI
            sKOSMapping.getTargetUri(), 1, concept.getIdConcept(), idThesaurus, 0);
        }
        if (sKOSMapping.getProperty() == SKOSProperty.closeMatch) {
            alignmentHelper.addNewAlignment(ds, // user
            1, // concept target
            "", // thesaurus target
            "", // URI
            sKOSMapping.getTargetUri(), 2, concept.getIdConcept(), idThesaurus, 0);
        }
    }
    // Ajouter l'id du concept importé pour l'aligner avec le thésaurus source
    alignmentHelper.addNewAlignment(ds, // user
    1, // concept target
    "", // thesaurus target
    "", // URI de la source
    resource.getUri(), // sKOSMapping.getTargetUri(), // URI
    1, concept.getIdConcept(), idThesaurus, 0);
    // Enregister les synonymes et traductions
    ArrayList<NodeEM> nodeEMs = writeLabelsList(ds, resource.getLabelsList());
    Term term = new Term();
    for (int i = 0; i < nodeEMs.size(); i++) {
        term.setId_concept(concept.getIdConcept());
        term.setId_term(nodeTerm.getIdTerm());
        term.setLexical_value(nodeEMs.get(i).getLexical_value());
        term.setLang(nodeEMs.get(i).getLang());
        term.setId_thesaurus(idThesaurus);
        term.setSource(nodeEMs.get(i).getSource());
        term.setStatus(nodeEMs.get(i).getStatus());
        termHelper.addNonPreferredTerm(ds, term, idUser);
    }
}
Also used : SKOSTopConcept(skos.SKOSTopConcept) Concept(mom.trd.opentheso.bdd.datas.Concept) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) NodeTerm(mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm) NoteHelper(mom.trd.opentheso.bdd.helper.NoteHelper) AlignmentHelper(mom.trd.opentheso.bdd.helper.AlignmentHelper) Term(mom.trd.opentheso.bdd.datas.Term) NodeTerm(mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm) NodeEM(mom.trd.opentheso.bdd.helper.nodes.NodeEM) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote) SKOSMapping(skos.SKOSMapping) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper)

Example 22 with NoteHelper

use of mom.trd.opentheso.bdd.helper.NoteHelper in project opentheso by miledrousset.

the class GetAltLabelTest method testExportAllDatas.

/**
 * Test of Get datas for SiteMap.
 */
@org.junit.Test
public void testExportAllDatas() {
    HikariDataSource conn = openConnexionPool();
    String idTheso = "TH_1";
    String idLang = "fr";
    String idGroup = "6";
    boolean passed = false;
    // ConceptHelper conceptHelper = new ConceptHelper();
    TermHelper termHelper = new TermHelper();
    NoteHelper noteHelper = new NoteHelper();
    // ArrayList<NodeConceptArkId> allIds = conceptHelper.getAllConceptArkIdOfThesaurus(conn, idTheso);
    StringBuilder file = new StringBuilder();
    ArrayList<NodeEM> nodeEMs;
    ArrayList<NodeTab2Levels> nodeConceptTermId = termHelper.getAllIdOfNonPreferredTermsByGroup(conn, idTheso, idGroup);
    Term term;
    ArrayList<NodeNote> nodeNotes;
    file.append("Id_concept");
    file.append("\t");
    file.append("prefLabel");
    file.append("\t");
    file.append("altLabel");
    file.append("\t");
    file.append("définition");
    file.append("\n");
    for (NodeTab2Levels nodeTab2Levels : nodeConceptTermId) {
        nodeEMs = termHelper.getNonPreferredTerms(conn, nodeTab2Levels.getIdTerm(), idTheso, idLang);
        if (!nodeEMs.isEmpty()) {
            term = termHelper.getThisTerm(conn, nodeTab2Levels.getIdConcept(), idTheso, idLang);
            nodeNotes = noteHelper.getListNotesTerm(conn, nodeTab2Levels.getIdTerm(), idTheso, idLang);
            // écriture dans le fichier
            file.append(nodeTab2Levels.getIdConcept());
            file.append("\t");
            file.append(term.getLexical_value());
            file.append("\t");
            for (NodeEM nodeEM : nodeEMs) {
                if (passed) {
                    file.append("##");
                }
                file.append(nodeEM.getLexical_value());
                passed = true;
            }
            file.append("\t");
            for (NodeNote nodeNote : nodeNotes) {
                if (nodeNote.getNotetypecode().equalsIgnoreCase("definition")) {
                    file.append(nodeNote.getLexicalvalue());
                }
            }
            file.append("\n");
        }
        passed = false;
    }
    System.out.println(file.toString());
    conn.close();
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) NodeTab2Levels(mom.trd.opentheso.bdd.helper.nodes.NodeTab2Levels) NoteHelper(mom.trd.opentheso.bdd.helper.NoteHelper) Term(mom.trd.opentheso.bdd.datas.Term) NodeEM(mom.trd.opentheso.bdd.helper.nodes.NodeEM) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper)

Example 23 with NoteHelper

use of mom.trd.opentheso.bdd.helper.NoteHelper in project opentheso by miledrousset.

the class ExportTxtHelper method countIndentation.

/**
 * permet de compter le nombre de décalalge pour chaque type de données
 * concept : pour l'hiérarchie NT : pour le nombre maxi de NT existant dans
 * le thésaurus ou le domaine choisi RT ... UF ....
 *
 * @param idConcept
 * @param indentation
 */
private void countIndentation(String idConcept, String indentation) {
    ArrayList<NodeNT> childList = new RelationsHelper().getListNT(ds, idConcept, idTheso, selectedLang);
    if (childList == null) {
        return;
    }
    // indentation des concepts par hiérarchie
    indentation += "\t";
    int tot = StringUtils.countMatches(indentation, "\t");
    if (tot > indentationConcept) {
        indentationConcept = tot;
    }
    // indentation des NT nombre maxi
    if (selectedOptions.contains("nt")) {
        int totNT = new RelationsHelper().getCountOfNT(ds, idConcept, idTheso);
        if (totNT > indentationNT) {
            indentationNT = totNT;
        }
    }
    // indentation des BT nombre maxi
    if (selectedOptions.contains("bt")) {
        int totBT = new RelationsHelper().getCountOfBT(ds, idConcept, idTheso);
        if (totBT > indentationBT) {
            indentationBT = totBT;
        }
    }
    // indentation des RT nombre maxi
    if (selectedOptions.contains("rt")) {
        int totRT = new RelationsHelper().getCountOfRT(ds, idConcept, idTheso);
        if (totRT > indentationRT) {
            indentationRT = totRT;
        }
    }
    // indentation des UF nombre maxi
    if (selectedOptions.contains("uf")) {
        int totUF = new RelationsHelper().getCountOfUF(ds, idConcept, idTheso, selectedLang);
        if (totUF > indentationUF) {
            indentationUF = totUF;
        }
    }
    // indentation des Groups nombre maxi
    if (selectedOptions.contains("groups")) {
        int totGroup = new GroupHelper().getCountOfGroups(ds, idConcept, idTheso);
        if (totGroup > indentationGroups) {
            indentationGroups = totGroup;
        }
    }
    // indentation traductions
    if (selectedOptions.contains("traductions")) {
        int totTraductions = new TermHelper().getCountOfTraductions(ds, idConcept, idTheso, selectedLang);
        if (totTraductions > indentationTraductions) {
            indentationTraductions = totTraductions;
        }
    }
    // indentation notes
    if (selectedOptions.contains("notes")) {
        int totNotes = new NoteHelper().getCountOfNotes(ds, idConcept, idTheso, selectedLang);
        if (totNotes > indentationNotes) {
            indentationNotes = totNotes;
        }
    }
    for (NodeNT nodeNT : childList) {
        countIndentation(nodeNT.getIdConcept(), indentation);
    }
}
Also used : NoteHelper(mom.trd.opentheso.bdd.helper.NoteHelper) NodeNT(mom.trd.opentheso.bdd.helper.nodes.NodeNT) RelationsHelper(mom.trd.opentheso.bdd.helper.RelationsHelper) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper)

Example 24 with NoteHelper

use of mom.trd.opentheso.bdd.helper.NoteHelper in project opentheso by miledrousset.

the class ImportTabuleIntoBDD method insertConcept.

private boolean insertConcept(HikariDataSource ds, TabulateDocument tabulateDocument, String idThesaurus, boolean istopConcept, int idUser) {
    // ajout du concept dans la base
    Concept concept = new Concept();
    ConceptHelper conceptHelper = new ConceptHelper();
    concept.setIdConcept(tabulateDocument.getId());
    concept.setIdThesaurus(idThesaurus);
    concept.setNotation("");
    concept.setStatus("");
    concept.setTopConcept(istopConcept);
    concept.setCreated(tabulateDocument.getCreated());
    concept.setModified(tabulateDocument.getModified());
    // cas de plusieurs Domaines (MT)
    if (!tabulateDocument.getInScheme().isEmpty()) {
        for (String idGroup : tabulateDocument.getInScheme()) {
            concept.setIdGroup(idGroup);
            conceptHelper.insertConceptInTable(ds, concept, idUser);
        }
    } else {
        return false;
    }
    // ajout des termes et traductions
    NodeTerm nodeTerm = new NodeTerm();
    ArrayList<NodeTermTraduction> nodeTermTraductionList = new ArrayList<>();
    for (Label prefLabel : tabulateDocument.getPrefLabels()) {
        NodeTermTraduction nodeTermTraduction = new NodeTermTraduction();
        nodeTermTraduction.setLexicalValue(prefLabel.getLabel());
        nodeTermTraduction.setLang(prefLabel.getLang());
        nodeTermTraductionList.add(nodeTermTraduction);
    }
    nodeTerm.setNodeTermTraduction(nodeTermTraductionList);
    nodeTerm.setIdTerm(tabulateDocument.getId());
    nodeTerm.setIdConcept(tabulateDocument.getId());
    nodeTerm.setIdThesaurus(idThesaurus);
    nodeTerm.setSource("");
    nodeTerm.setStatus("");
    nodeTerm.setCreated(tabulateDocument.getCreated());
    nodeTerm.setModified(tabulateDocument.getModified());
    TermHelper termHelper = new TermHelper();
    termHelper.insertTerm(ds, nodeTerm, idUser);
    // Enregister les synonymes et traductions (AltLabel)
    ArrayList<NodeEM> nodeEMList = new ArrayList<>();
    for (Label altLabel : tabulateDocument.getAltLabels()) {
        NodeEM nodeEM = new NodeEM();
        nodeEM.setLexical_value(altLabel.getLabel());
        nodeEM.setLang(altLabel.getLang());
        nodeEM.setSource("");
        nodeEM.setStatus("USE");
        nodeEM.setHiden(false);
        nodeEMList.add(nodeEM);
    }
    Term term = new Term();
    for (NodeEM nodeEMList1 : nodeEMList) {
        term.setId_concept(tabulateDocument.getId());
        term.setId_term(tabulateDocument.getId());
        term.setLexical_value(nodeEMList1.getLexical_value());
        term.setLang(nodeEMList1.getLang());
        term.setId_thesaurus(idThesaurus);
        term.setSource(nodeEMList1.getSource());
        term.setStatus(nodeEMList1.getStatus());
        termHelper.addNonPreferredTerm(ds, term, idUser);
    }
    // ajouter les notes
    NoteHelper noteHelper = new NoteHelper();
    for (Note note : tabulateDocument.getDefinition()) {
        noteHelper.addTermNote(ds, tabulateDocument.getId(), note.getLang(), idThesaurus, note.getNote(), "definition", idUser);
    }
    for (Note note : tabulateDocument.getScopeNote()) {
        noteHelper.addTermNote(ds, tabulateDocument.getId(), note.getLang(), idThesaurus, note.getNote(), "scopeNote", idUser);
    }
    for (Note note : tabulateDocument.getHistoryNote()) {
        noteHelper.addTermNote(ds, tabulateDocument.getId(), note.getLang(), idThesaurus, note.getNote(), "historyNote", idUser);
    }
    for (Note note : tabulateDocument.getEditorialNote()) {
        noteHelper.addTermNote(ds, tabulateDocument.getId(), note.getLang(), idThesaurus, note.getNote(), "editorialNote", idUser);
    }
    // Enregistrer les relations
    writeRelationsList(ds, tabulateDocument, idThesaurus, idUser);
    // Enregistrer les Mappings (alignements)
    AlignmentHelper alignmentHelper = new AlignmentHelper();
    for (Alignment alignment : tabulateDocument.getAlignments()) {
        if (alignment.getType().equalsIgnoreCase("exactMatch")) {
            alignmentHelper.addNewAlignment(ds, // user
            1, // concept target
            "", // thesaurus target
            "", // URI
            alignment.getUri(), 1, tabulateDocument.getId(), idThesaurus, 0);
        }
        if (alignment.getType().equalsIgnoreCase("closeMatch")) {
            alignmentHelper.addNewAlignment(ds, // user
            1, // concept target
            "", // thesaurus target
            "", // URI
            alignment.getUri(), 2, tabulateDocument.getId(), idThesaurus, 0);
        }
    }
    return true;
}
Also used : Concept(mom.trd.opentheso.bdd.datas.Concept) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) NodeTerm(mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm) ArrayList(java.util.ArrayList) Label(mom.trd.opentheso.core.exports.tabulate.Label) ConceptGroupLabel(mom.trd.opentheso.bdd.datas.ConceptGroupLabel) NoteHelper(mom.trd.opentheso.bdd.helper.NoteHelper) AlignmentHelper(mom.trd.opentheso.bdd.helper.AlignmentHelper) Term(mom.trd.opentheso.bdd.datas.Term) NodeTerm(mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm) NodeTermTraduction(mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction) NodeEM(mom.trd.opentheso.bdd.helper.nodes.NodeEM) Alignment(mom.trd.opentheso.core.exports.tabulate.Alignment) Note(mom.trd.opentheso.core.exports.tabulate.Note) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper)

Aggregations

NoteHelper (mom.trd.opentheso.bdd.helper.NoteHelper)24 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)14 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)12 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)12 Term (mom.trd.opentheso.bdd.datas.Term)11 AlignmentHelper (mom.trd.opentheso.bdd.helper.AlignmentHelper)11 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)11 Concept (mom.trd.opentheso.bdd.datas.Concept)9 NodeTerm (mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm)9 FacesMessage (javax.faces.application.FacesMessage)8 SQLException (java.sql.SQLException)5 NodeTermTraduction (mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction)5 SKOSMapping (skos.SKOSMapping)5 SKOSTopConcept (skos.SKOSTopConcept)5 ArrayList (java.util.ArrayList)4 RelationsHelper (mom.trd.opentheso.bdd.helper.RelationsHelper)4 Connection (java.sql.Connection)3 HierarchicalRelationship (mom.trd.opentheso.bdd.datas.HierarchicalRelationship)3 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)3 SKOSAnnotation (org.semanticweb.skos.SKOSAnnotation)3