Search in sources :

Example 26 with ConceptHelper

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

the class ExportTxtHelper method writeConceptsInfo.

/**
 * Permet d'écrire les concepts en bouclant par récursivité pour définir les
 * niveaux
 *
 * @return
 */
private void writeConceptsInfo(String idConcept, String indentation) {
    ConceptHelper conceptHelper = new ConceptHelper();
    NodeConcept nodeConcept = conceptHelper.getConcept(ds, idConcept, idTheso, selectedLang);
    StringPlus stringPlus = new StringPlus();
    boolean first = true;
    if (nodeConcept == null) {
        return;
    }
    // id numérique séquentiel
    txtBuff.append(++number);
    txtBuff.append("\t");
    // Id_concept
    txtBuff.append(idConcept);
    txtBuff.append("\t");
    // on écrit le Term_concept
    txtBuff.append(indentation);
    if (nodeConcept.getTerm().getLexical_value().isEmpty()) {
        txtBuff.append("(");
        txtBuff.append(idConcept);
        txtBuff.append(")");
    } else {
        txtBuff.append(nodeConcept.getTerm().getLexical_value());
    }
    int tot = StringUtils.countMatches(indentation, "\t");
    if (tot < indentationConcept) {
        addTabulate(indentationConcept - (tot + 1));
    }
    if (selectedOptions.contains("occ")) {
        // on écrit les occurences
        txtBuff.append("\t");
        txtBuff.append(totalOfNotices(idConcept));
    }
    first = true;
    if (selectedOptions.contains("nt")) {
        // on écrit la relation NT
        if (!nodeConcept.getNodeNT().isEmpty()) {
            txtBuff.append("\t");
            for (NodeNT nodeNT : nodeConcept.getNodeNT()) {
                if (!first)
                    txtBuff.append("\t");
                // txtBuff.append("NT: ");
                txtBuff.append(nodeNT.getTitle());
                first = false;
            }
        }
        if (nodeConcept.getNodeNT().size() < indentationNT) {
            addTabulate(indentationNT - nodeConcept.getNodeNT().size());
        }
    }
    first = true;
    // on écrit la relation UF
    if (selectedOptions.contains("uf")) {
        if (!nodeConcept.getNodeEM().isEmpty()) {
            txtBuff.append("\t");
            for (NodeEM nodeEm : nodeConcept.getNodeEM()) {
                if (!first)
                    txtBuff.append("\t");
                // txtBuff.append("UF: ");
                txtBuff.append(nodeEm.getLexical_value());
                first = false;
            }
        }
        if (nodeConcept.getNodeEM().size() < indentationUF) {
            addTabulate(indentationUF - nodeConcept.getNodeEM().size());
        }
    }
    first = true;
    if (selectedOptions.contains("bt")) {
        // on écrit la relation TG
        if (!nodeConcept.getNodeBT().isEmpty()) {
            txtBuff.append("\t");
            for (NodeBT nodeBT : nodeConcept.getNodeBT()) {
                if (!first)
                    txtBuff.append("\t");
                // txtBuff.append("BT: ");
                txtBuff.append(nodeBT.getTitle());
                first = false;
            }
        }
        if (nodeConcept.getNodeBT().size() < indentationBT) {
            addTabulate(indentationBT - nodeConcept.getNodeBT().size());
        }
    }
    first = true;
    // on écrit la relation RT
    if (selectedOptions.contains("rt")) {
        if (!nodeConcept.getNodeRT().isEmpty()) {
            txtBuff.append("\t");
            for (NodeRT nodeRT : nodeConcept.getNodeRT()) {
                if (!first)
                    txtBuff.append("\t");
                // txtBuff.append("RT: ");
                txtBuff.append(nodeRT.getTitle());
                first = false;
            }
        }
        if (nodeConcept.getNodeRT().size() < indentationRT) {
            addTabulate(indentationRT - nodeConcept.getNodeRT().size());
        }
    }
    first = true;
    // on écrit les Groupes
    if (selectedOptions.contains("groups")) {
        if (!nodeConcept.getNodeConceptGroup().isEmpty()) {
            txtBuff.append("\t");
            for (NodeGroup nodeGroup : nodeConcept.getNodeConceptGroup()) {
                if (!first)
                    txtBuff.append("\t");
                // txtBuff.append("MT: ");
                txtBuff.append(nodeGroup.getLexicalValue());
                first = false;
            }
        }
        if (nodeConcept.getNodeConceptGroup().size() < indentationGroups) {
            addTabulate(indentationGroups - nodeConcept.getNodeConceptGroup().size());
        }
    }
    first = true;
    // on écrit les traductions
    if (selectedOptions.contains("traductions")) {
        if (!nodeConcept.getNodeTermTraductions().isEmpty()) {
            txtBuff.append("\t");
            for (NodeTermTraduction nodeTermTraduction : nodeConcept.getNodeTermTraductions()) {
                if (!first)
                    txtBuff.append("\t");
                // txtBuff.append("Tr: ");
                txtBuff.append(nodeTermTraduction.getLexicalValue());
                txtBuff.append("(");
                txtBuff.append(nodeTermTraduction.getLang());
                txtBuff.append(")");
                first = false;
            }
        }
        if (nodeConcept.getNodeTermTraductions().size() < indentationTraductions) {
            addTabulate(indentationTraductions - nodeConcept.getNodeTermTraductions().size());
        }
    }
    first = true;
    // on écrit les notes de type Term
    if (selectedOptions.contains("notes")) {
        if ((!nodeConcept.getNodeNotesTerm().isEmpty()) || (!nodeConcept.getNodeNotesConcept().isEmpty())) {
            txtBuff.append("\t");
            for (NodeNote nodeNote : nodeConcept.getNodeNotesTerm()) {
                if (!first)
                    txtBuff.append("\t");
                // txtBuff.append("noteT: ");
                txtBuff.append(stringPlus.clearNewLine(nodeNote.getLexicalvalue()));
                first = false;
            }
            for (NodeNote nodeNote : nodeConcept.getNodeNotesConcept()) {
                if (!first)
                    txtBuff.append("\t");
                // txtBuff.append("noteC: ");
                txtBuff.append(stringPlus.clearNewLine(nodeNote.getLexicalvalue()));
                first = false;
            }
        }
        if (nodeConcept.getNodeNotesTerm().size() < indentationNotes) {
            addTabulate(indentationNotes - (nodeConcept.getNodeNotesConcept().size() + nodeConcept.getNodeNotesTerm().size()));
        }
    }
    txtBuff.append("\n");
}
Also used : NodeBT(mom.trd.opentheso.bdd.helper.nodes.NodeBT) NodeRT(mom.trd.opentheso.bdd.helper.nodes.NodeRT) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) NodeTermTraduction(mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote) NodeNT(mom.trd.opentheso.bdd.helper.nodes.NodeNT) NodeEM(mom.trd.opentheso.bdd.helper.nodes.NodeEM) NodeGroup(mom.trd.opentheso.bdd.helper.nodes.group.NodeGroup)

Example 27 with ConceptHelper

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

the class VerifyArkIdTest method regerateArkId.

@Test
public void regerateArkId() {
    String idConcept = "13241";
    String idTheso = "TH_1";
    String idLang = "fr";
    String urlSite = "http://test.frantiq.fr/";
    ConnexionTest connexionTest = new ConnexionTest();
    HikariDataSource ds = connexionTest.getConnexionPool();
    if (ds == null) {
        return;
    }
    ConceptHelper conceptHelper = new ConceptHelper();
    conceptHelper.regenerateArkId(ds, idConcept, idLang, idTheso);
    ds.close();
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) ConnexionTest(connexion.ConnexionTest) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) ConnexionTest(connexion.ConnexionTest) Test(org.junit.Test)

Example 28 with ConceptHelper

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

the class CompareConceptTest method testExportAllDatas.

/**
 * Test of Get datas for SiteMap.
 */
@org.junit.Test
public void testExportAllDatas() {
    ConnexionTest connexionTest = new ConnexionTest();
    HikariDataSource conn = connexionTest.getConnexionPool();
    String idTheso = "TH_1";
    String idLang = "fr";
    String idGroup = "6";
    ConceptHelper conceptHelper = new ConceptHelper();
    StringPlus stringPlus = new StringPlus();
    NodeConcept nodeConcept;
    SearchHelper searchHelper = new SearchHelper();
    ArrayList<NodeSearch> nodeSearchs;
    StringBuilder stringBuilder = new StringBuilder();
    // lecture du fichier tabulé /Users/Miled/
    String path = "/Users/Miled/Desktop/inist.csv";
    FileInputStream file = readFile(path);
    if (file == null)
        return;
    String line;
    String lineTmp;
    String[] lineOrigine;
    boolean first = true;
    stringBuilder.append("Numéro BDD\tnom d'origine\tnom PACTOLS\tId PACTOLS\tURL Ark\tDéfinition\tTerme générique\tSynonyme\n");
    BufferedReader bf = new BufferedReader(new InputStreamReader(file));
    try {
        while ((line = bf.readLine()) != null) {
            lineOrigine = line.split("\t");
            if (lineOrigine.length < 2)
                continue;
            lineTmp = removeStopWords(lineOrigine[1]);
            nodeSearchs = searchHelper.searchTerm(conn, lineTmp, idLang, idTheso, idGroup, 2, false);
            stringBuilder.append(lineOrigine[0]);
            stringBuilder.append("\t");
            stringBuilder.append(lineOrigine[1]);
            // stringBuilder.append(" #### ");
            stringBuilder.append("\t");
            first = true;
            for (NodeSearch nodeSearch : nodeSearchs) {
                if (!first) {
                    // stringBuilder.append(" $$$$ ");
                    stringBuilder.append("\n");
                    stringBuilder.append("\t");
                    stringBuilder.append("\t");
                }
                stringBuilder.append(nodeSearch.getLexical_value());
                stringBuilder.append("\t");
                stringBuilder.append(nodeSearch.getIdConcept());
                // récupération des données d'un Concept
                nodeConcept = conceptHelper.getConcept(conn, nodeSearch.getIdConcept(), idTheso, idLang);
                // URL
                stringBuilder.append("\t");
                if (nodeConcept.getConcept().getIdArk() != null || !nodeConcept.getConcept().getIdArk().isEmpty()) {
                    stringBuilder.append("http://ark.frantiq.fr/ark:/");
                    stringBuilder.append(nodeConcept.getConcept().getIdArk());
                }
                // définition
                stringBuilder.append("\t");
                for (NodeNote nodeNote : nodeConcept.getNodeNotesTerm()) {
                    if (nodeNote.getNotetypecode().equalsIgnoreCase("definition"))
                        stringBuilder.append(stringPlus.clearNewLine(nodeNote.getLexicalvalue()));
                }
                // BT
                stringBuilder.append("\t");
                for (NodeBT nodeBT : nodeConcept.getNodeBT()) {
                    stringBuilder.append(nodeBT.getTitle());
                }
                // UF
                stringBuilder.append("\t");
                for (NodeEM nodeEM : nodeConcept.getNodeEM()) {
                    stringBuilder.append(nodeEM.getLexical_value());
                }
                first = false;
            }
            System.out.println(stringBuilder.toString());
            stringBuilder.delete(0, stringBuilder.capacity());
        }
    } catch (IOException ex) {
        Logger.getLogger(CompareConceptTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    // ArrayList<NodeConceptArkId> allIds = conceptHelper.getAllConceptArkIdOfThesaurus(conn, idTheso);
    // StringBuilder file = new StringBuilder();
    /*  ArrayList<String> allIds = conceptHelper.getAllIdConceptOfThesaurusByGroup(conn, idTheso, idGroup);
        
        
        for (String idConcept : allIds) {

            nodeConcept = conceptHelper.getConcept(conn, idConcept, idTheso, idLang);
            System.out.println("idConcept = " + idConcept + "  " + nodeConcept.getTerm().getLexical_value());
            
        }*/
    conn.close();
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) ConnexionTest(connexion.ConnexionTest) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) InputStreamReader(java.io.InputStreamReader) NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) IOException(java.io.IOException) SearchHelper(mom.trd.opentheso.bdd.helper.SearchHelper) FileInputStream(java.io.FileInputStream) NodeEM(mom.trd.opentheso.bdd.helper.nodes.NodeEM) NodeBT(mom.trd.opentheso.bdd.helper.nodes.NodeBT) BufferedReader(java.io.BufferedReader) NodeSearch(mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)

Example 29 with ConceptHelper

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

the class ImportRdf4jHelper method addConcepts.

public void addConcepts(rdf4jFileBean fileBean) throws SQLException, ParseException {
    AddConceptsStruct acs = new AddConceptsStruct();
    acs.conceptHelper = new ConceptHelper();
    for (SKOSResource conceptResource : skosXmlDocument.getConceptList()) {
        fileBean.setAbs_progress(fileBean.getAbs_progress() + 1);
        fileBean.setProgress(fileBean.getAbs_progress() / fileBean.getTotal() * 100);
        initAddConceptsStruct(acs, conceptResource);
        addRelation(acs);
        // envoie du concept à la BDD
        if (!isConceptEmpty(acs.nodeTermTraductionList)) {
            if (acs.idGrps.isEmpty()) {
                acs.concept.setTopConcept(acs.isTopConcept);
                acs.concept.setIdGroup(idGroupDefault);
                acs.conceptHelper.insertConceptInTable(ds, acs.concept, idUser);
                new GroupHelper().addConceptGroupConcept(ds, idGroupDefault, acs.concept.getIdConcept(), acs.concept.getIdThesaurus());
                defaultGroupToAdd = true;
            } else {
                for (String idGrp : acs.idGrps) {
                    acs.concept.setTopConcept(acs.isTopConcept);
                    acs.concept.setIdGroup(idGrp);
                    if (!acs.conceptHelper.insertConceptInTable(ds, acs.concept, idUser)) {
                        System.out.println("Erreur sur le Concept = " + acs.concept.getIdConcept());
                    }
                }
            }
            finalizeAddConceptStruct(acs);
        }
    }
    addLangsToThesaurus(ds, idTheso);
    addGroupDefault();
}
Also used : SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper)

Example 30 with ConceptHelper

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

the class ImportTabuleIntoBDD method writeRelationsList.

private boolean writeRelationsList(HikariDataSource ds, TabulateDocument tabulateDocument, String idThesaurus, int idUser) {
    ConceptHelper conceptHelper = new ConceptHelper();
    HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
    for (String broader : tabulateDocument.getBroader()) {
        hierarchicalRelationship.setIdConcept1(tabulateDocument.getId());
        hierarchicalRelationship.setIdConcept2(broader);
        hierarchicalRelationship.setIdThesaurus(idThesaurus);
        hierarchicalRelationship.setRole("BT");
        try {
            Connection conn = ds.getConnection();
            conn.setAutoCommit(false);
            if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
                conn.rollback();
                conn.close();
                return false;
            }
            conn.commit();
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(ImportTabuleIntoBDD.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    for (String narrower : tabulateDocument.getNarrower()) {
        hierarchicalRelationship.setIdConcept1(tabulateDocument.getId());
        hierarchicalRelationship.setIdConcept2(narrower);
        hierarchicalRelationship.setIdThesaurus(idThesaurus);
        hierarchicalRelationship.setRole("NT");
        try {
            Connection conn = ds.getConnection();
            conn.setAutoCommit(false);
            if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
                conn.rollback();
                conn.close();
                return false;
            }
            conn.commit();
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(ImportTabuleIntoBDD.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    for (String related : tabulateDocument.getRelated()) {
        hierarchicalRelationship.setIdConcept1(tabulateDocument.getId());
        hierarchicalRelationship.setIdConcept2(related);
        hierarchicalRelationship.setIdThesaurus(idThesaurus);
        hierarchicalRelationship.setRole("RT");
        try {
            Connection conn = ds.getConnection();
            conn.setAutoCommit(false);
            if (conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
                conn.rollback();
                conn.close();
                return false;
            }
            conn.commit();
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(ImportTabuleIntoBDD.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return true;
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Aggregations

ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)125 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)38 SQLException (java.sql.SQLException)36 Connection (java.sql.Connection)29 ArrayList (java.util.ArrayList)28 FacesMessage (javax.faces.application.FacesMessage)23 Concept (mom.trd.opentheso.bdd.datas.Concept)18 AlignmentHelper (mom.trd.opentheso.bdd.helper.AlignmentHelper)16 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)16 Term (mom.trd.opentheso.bdd.datas.Term)15 PrefixString (com.k_int.IR.QueryModels.PrefixString)14 RelationsHelper (mom.trd.opentheso.bdd.helper.RelationsHelper)14 HierarchicalRelationship (mom.trd.opentheso.bdd.datas.HierarchicalRelationship)13 NoteHelper (mom.trd.opentheso.bdd.helper.NoteHelper)12 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)12 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)12 HashMap (java.util.HashMap)9 MyTreeNode (mom.trd.opentheso.bdd.helper.nodes.MyTreeNode)9 NodeConceptExport (mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptExport)9 NodeTerm (mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm)9