Search in sources :

Example 1 with NodeSearch

use of mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch in project opentheso by miledrousset.

the class Rest method getListId.

/**
 * Fin Temporaire à refaire (Miled)
 */
private ArrayList<String> getListId(String value, String idLang, String idTheso) {
    ArrayList<String> listId = new ArrayList<>();
    ArrayList<NodeSearch> listRes = new SearchHelper().searchTerm(ds, value, idLang, idTheso, "", 1, false);
    for (NodeSearch listRe : listRes) {
        listId.add(listRe.getIdConcept());
    }
    return listId;
}
Also used : ArrayList(java.util.ArrayList) NodeSearch(mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch) SearchHelper(mom.trd.opentheso.bdd.helper.SearchHelper)

Example 2 with NodeSearch

use of mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch 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 3 with NodeSearch

use of mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch in project opentheso by miledrousset.

the class CompareConceptTest method testSearchGIN.

@Test
public void testSearchGIN() {
    ConnexionTest connexionTest = new ConnexionTest();
    HikariDataSource conn = connexionTest.getConnexionPool();
    String idTheso = "2";
    String idLang = "fr";
    String idGroup = "5";
    ConceptHelper conceptHelper = new ConceptHelper();
    StringPlus stringPlus = new StringPlus();
    NodeConcept nodeConcept;
    SearchHelper searchHelper = new SearchHelper();
    ArrayList<NodeSearch> nodeSearchs;
    // nodeSearchs = searchHelper.searchTermNew(conn, "saint", idLang, idTheso, idGroup, 1, true);
    TermHelper termHelper = new TermHelper();
    List<NodeAutoCompletion> nodeAutoCompletionList = termHelper.getAutoCompletionTerm(conn, idTheso, idLang, "saint");
    String test = "écolÉôïçèù";
    test = test.toLowerCase();
    test = stringPlus.unaccentLowerString(test);
    test = "مزهرية";
    test = stringPlus.unaccentLowerString(test);
    test = test.toUpperCase();
    test = test.toLowerCase();
    conn.close();
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) ConnexionTest(connexion.ConnexionTest) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) NodeSearch(mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch) SearchHelper(mom.trd.opentheso.bdd.helper.SearchHelper) NodeAutoCompletion(mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper) ConnexionTest(connexion.ConnexionTest) Test(org.junit.Test)

Example 4 with NodeSearch

use of mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch in project opentheso by miledrousset.

the class SearchHelper method searchIdConcept.

/**
 * Cette fonction permet de faire une recherche par idConcept sans tenir compte de la langue
 * on retourne un tableau du Concept dans toutes les langues disponibles
 *
 * @param ds
 * @param id
 * @param idThesaurus
 * @return
 */
public ArrayList<NodeSearch> searchIdConcept(HikariDataSource ds, String id, String idThesaurus) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeSearch> nodeSearchList = null;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT term.lexical_value," + " preferred_term.id_term, term.lang, term.id_thesaurus," + " idgroup, concept.top_concept" + " FROM term, preferred_term, concept, concept_group_concept WHERE " + "concept_group_concept.idconcept = preferred_term.id_term AND " + "concept_group_concept.idthesaurus = term.id_thesaurus AND" + " concept.id_concept = preferred_term.id_concept AND" + " concept.id_thesaurus = preferred_term.id_thesaurus AND" + " preferred_term.id_term = term.id_term AND" + " preferred_term.id_thesaurus = term.id_thesaurus" + " and concept.id_concept = '" + id + "'" + " and term.id_thesaurus = '" + idThesaurus + "'" + " order by lexical_value ASC";
                resultSet = stmt.executeQuery(query);
                nodeSearchList = new ArrayList<>();
                while (resultSet.next()) {
                    NodeSearch nodeSearch = new NodeSearch();
                    nodeSearch.setLexical_value(resultSet.getString("lexical_value"));
                    nodeSearch.setIdConcept(id);
                    nodeSearch.setIdTerm(resultSet.getString("id_term"));
                    nodeSearch.setIdGroup(resultSet.getString("idgroup"));
                    nodeSearch.setIdLang(resultSet.getString("lang"));
                    nodeSearch.setIdThesaurus(idThesaurus);
                    nodeSearch.setTopConcept(resultSet.getBoolean("top_concept"));
                    nodeSearch.setPreferredLabel(true);
                    nodeSearchList.add(nodeSearch);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(SearchHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return nodeSearchList;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NodeSearch(mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch)

Example 5 with NodeSearch

use of mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch in project opentheso by miledrousset.

the class SearchHelper method searchNote.

/**
 * Cette fonction permet de faire une recherche par value sur les notes
 *
 * @param ds
 * @param value
 * @param idLang
 * @param idThesaurus
 * @param idGroup
 * @param startByOrContain //1=contient 2=commence par
 * @return
 */
public ArrayList<NodeSearch> searchNote(HikariDataSource ds, String value, String idLang, String idThesaurus, String idGroup, int startByOrContain) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeSearch> nodeSearchList = new ArrayList<>();
    value = new StringPlus().convertString(value);
    String[] values = value.trim().split(" ");
    String query;
    String langNote;
    String group;
    String multivaluesNote = "";
    // préparation de la valeur à rechercher
    if (startByOrContain == 1) {
        // contient
        for (String value1 : values) {
            multivaluesNote += " and unaccent_string(note.lexicalvalue) ilike" + " unaccent_string('%" + value1 + "%')";
        }
    }
    if (startByOrContain == 2) {
        // commence par
        multivaluesNote += " and (unaccent_string(note.lexicalvalue) ilike" + " unaccent_string('" + value + "%')" + " OR unaccent_string(note.lexicalvalue) ilike" + " unaccent_string('% " + value + "%'))";
    }
    // préparation de la requête en focntion du choix (toutes les langues ou langue donnée)
    if (idLang.isEmpty()) {
        langNote = "";
    } else {
        langNote = " and note.lang ='" + idLang + "'";
    }
    // cas du choix d'un group
    if (idGroup.isEmpty()) {
        group = "";
    } else {
        group = " and idgroup = '" + idGroup + "'";
    }
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                // notes des terms
                query = "SELECT concept.id_concept, concept.id_thesaurus," + " concept.top_concept, idgroup," + " note.lang, note.lexicalvalue," + " note.id_term " + " FROM preferred_term, note, concept,concept_group_concept" + " WHERE " + "concept_group_concept.idthesaurus = concept.id_thesaurus AND " + "concept.id_concept = concept_group_concept.idconcept AND " + " preferred_term.id_term = note.id_term" + " AND" + " preferred_term.id_thesaurus = note.id_thesaurus" + " AND" + " concept.id_concept = preferred_term.id_concept" + " AND" + " concept.id_thesaurus = preferred_term.id_thesaurus" + " AND" + " note.id_thesaurus = '" + idThesaurus + "'" + multivaluesNote + langNote + group + " order by lexicalvalue ASC LIMIT 200";
                resultSet = stmt.executeQuery(query);
                while (resultSet.next()) {
                    NodeSearch nodeSearch = new NodeSearch();
                    nodeSearch.setLexical_value(resultSet.getString("lexicalvalue"));
                    nodeSearch.setIdConcept(resultSet.getString("id_concept"));
                    nodeSearch.setIdTerm(resultSet.getString("id_term"));
                    nodeSearch.setIdGroup(resultSet.getString("idgroup"));
                    nodeSearch.setIdLang(resultSet.getString("lang"));
                    nodeSearch.setIdThesaurus(idThesaurus);
                    nodeSearch.setTopConcept(resultSet.getBoolean("top_concept"));
                    nodeSearch.setPreferredLabel(true);
                    nodeSearchList.add(nodeSearch);
                }
                // notes des concepts
                query = "SELECT concept.id_concept, concept.id_thesaurus," + " concept.top_concept, idgroup," + " note.lang, note.lexicalvalue," + " preferred_term.id_term " + " FROM preferred_term, note, concept, concept_group_concept" + " WHERE " + "concept_group_concept.idconcept = concept.id_concept AND " + "concept_group_concept.idthesaurus = concept.id_thesaurus AND " + " preferred_term.id_concept = note.id_concept" + " AND" + " preferred_term.id_thesaurus = note.id_thesaurus" + " AND" + " concept.id_concept = preferred_term.id_concept" + " AND" + " concept.id_thesaurus = preferred_term.id_thesaurus" + " AND" + " note.id_thesaurus = '" + idThesaurus + "'" + multivaluesNote + langNote + group + " order by lexicalvalue ASC LIMIT 200";
                resultSet = stmt.executeQuery(query);
                while (resultSet.next()) {
                    NodeSearch nodeSearch = new NodeSearch();
                    nodeSearch.setLexical_value(resultSet.getString("lexicalvalue"));
                    nodeSearch.setIdConcept(resultSet.getString("id_concept"));
                    nodeSearch.setIdTerm(resultSet.getString("id_term"));
                    nodeSearch.setIdGroup(resultSet.getString("idgroup"));
                    nodeSearch.setIdLang(resultSet.getString("lang"));
                    nodeSearch.setIdThesaurus(idThesaurus);
                    nodeSearch.setTopConcept(resultSet.getBoolean("top_concept"));
                    nodeSearch.setPreferredLabel(true);
                    nodeSearchList.add(nodeSearch);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(SearchHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return nodeSearchList;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) NodeSearch(mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch)

Aggregations

NodeSearch (mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch)16 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 SQLException (java.sql.SQLException)8 Statement (java.sql.Statement)8 StringPlus (mom.trd.opentheso.bdd.tools.StringPlus)8 ArrayList (java.util.ArrayList)5 SearchHelper (mom.trd.opentheso.bdd.helper.SearchHelper)5 NodeConcept (mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept)3 HikariDataSource (com.zaxxer.hikari.HikariDataSource)2 ConnexionTest (connexion.ConnexionTest)2 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)2 DefaultTreeNode (org.primefaces.model.DefaultTreeNode)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Concept (mom.trd.opentheso.bdd.datas.Concept)1 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)1 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)1