Search in sources :

Example 1 with NodePermute

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

the class SearchHelper method getListPermute.

/**
 * Cette fonction permet de récupérer une liste des concepts sous forme
 * permutée par domaine
 *
 * renvoie les synonymes aussi
 *
 * @param ds
 * @param idThesaurus
 * @param idLang
 * @param value
 * @param idGroup
 * @return ArrayList de NodePermute
 */
public ArrayList<NodePermute> getListPermute(HikariDataSource ds, String idThesaurus, String idLang, String value, String idGroup) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodePermute> nodePermuteList = null;
    value = new StringPlus().convertString(value);
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT ord, id_concept, " + " id_lang, lexical_value, ispreferredterm, original_value" + " FROM permuted WHERE" + " id_lang = '" + idLang + "'" + " and id_group = '" + idGroup + "'" + " and id_thesaurus = '" + idThesaurus + "'" + " and unaccent_string(lexical_value) ilike" + " unaccent_string('" + value + "%')" + " order by lexical_value ASC LIMIT 200";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                nodePermuteList = new ArrayList<>();
                while (resultSet.next()) {
                    NodePermute nodePermute = new NodePermute();
                    nodePermute.setIdThesaurus(idThesaurus);
                    nodePermute.setIdConcept(resultSet.getString("id_concept"));
                    nodePermute.setIdLang(resultSet.getString("id_lang"));
                    nodePermute.setIdGroup(idGroup);
                    nodePermute.setSearchedValue(resultSet.getString("lexical_value"));
                    nodePermute.setIndexOfValue(resultSet.getInt("ord"));
                    nodePermute.setIsPreferredTerm(resultSet.getBoolean("ispreferredterm"));
                    // cas où le terme recherché est égal au terme retrouvé, on le place en premier
                    if (value.trim().equalsIgnoreCase(resultSet.getString("original_value").trim())) {
                        nodePermuteList.add(0, nodePermute);
                    } else {
                        nodePermuteList.add(nodePermute);
                    }
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting List Permute of Value by Group : " + value, sqle);
    }
    if (nodePermuteList != null) {
        nodePermuteList = addColumnsToPermute(ds, idThesaurus, nodePermuteList);
    }
    return nodePermuteList;
}
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) NodePermute(mom.trd.opentheso.bdd.helper.nodes.NodePermute)

Example 2 with NodePermute

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

the class SearchHelper method addColumnsToPermute.

/**
 * Cette fonction permet de compléter la colomne de gauche et la colonne de
 * droite avec les valeurs d'un concept Exp : Rhone Alpes Auvergne = colonne
 * de gauche = Rhone mot recherché = Alpes colonne de droite = Auvergne
 *
 * @param ds
 * @param idThesaurus
 * @param nodePermuteList
 * @return ArrayList de NodePermute
 */
public ArrayList<NodePermute> addColumnsToPermute(HikariDataSource ds, String idThesaurus, ArrayList<NodePermute> nodePermuteList) {
    ArrayList<String> tabValues;
    String firstColumn = "";
    String lastColumn = "";
    for (NodePermute nodePermute : nodePermuteList) {
        tabValues = getThisConceptPermute(ds, idThesaurus, nodePermute.getIdConcept(), nodePermute.getIdLang(), nodePermute.isIsPreferredTerm());
        if (tabValues != null) {
            for (int i = 0; i < nodePermute.getIndexOfValue() - 1; i++) {
                firstColumn = firstColumn + " " + tabValues.get(i);
            }
            for (int i = nodePermute.getIndexOfValue(); i < tabValues.size(); i++) {
                lastColumn = lastColumn + " " + tabValues.get(i);
            }
            nodePermute.setFirstColumn(firstColumn.trim());
            nodePermute.setLastColumn(lastColumn.trim());
        }
        firstColumn = "";
        lastColumn = "";
    }
    return nodePermuteList;
}
Also used : NodePermute(mom.trd.opentheso.bdd.helper.nodes.NodePermute)

Example 3 with NodePermute

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

the class SearchHelper method getListPermuteNonPreferredTerm.

/**
 * Cette fonction permet de récupérer une liste des concepts Synonymes sous
 * forme permutée
 *
 * @param ds
 * @param idThesaurus
 * @param idLang
 * @param value
 * @return ArrayList de NodePermute
 */
public ArrayList<NodePermute> getListPermuteNonPreferredTerm(HikariDataSource ds, String idThesaurus, String idLang, String value) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodePermute> nodePermuteList = null;
    value = new StringPlus().convertString(value);
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT DISTINCT ord, id_concept, " + " id_lang, lexical_value, id_group" + " FROM permuted WHERE" + " id_lang = '" + idLang + "'" + " and id_thesaurus = '" + idThesaurus + "'" + " and ispreferredterm = " + false + " and unaccent_string(lexical_value) ilike" + " unaccent_string('" + value + "%')" + " order by lexical_value ASC LIMIT 200";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                nodePermuteList = new ArrayList<>();
                while (resultSet.next()) {
                    NodePermute nodePermute = new NodePermute();
                    nodePermute.setIdThesaurus(idThesaurus);
                    nodePermute.setIdConcept(resultSet.getString("id_concept"));
                    nodePermute.setIdLang(resultSet.getString("id_lang"));
                    nodePermute.setSearchedValue(resultSet.getString("lexical_value"));
                    nodePermute.setIndexOfValue(resultSet.getInt("ord"));
                    nodePermute.setIdGroup(resultSet.getString("id_group"));
                    nodePermute.setIsPreferredTerm(false);
                    // cas où le terme recherché est égal au terme retrouvé, on le place en premier
                    if (value.trim().equalsIgnoreCase(nodePermute.getSearchedValue().trim())) {
                        nodePermuteList.add(0, nodePermute);
                    } else {
                        nodePermuteList.add(nodePermute);
                    }
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting List Permute of Value : " + value, sqle);
    }
    if (nodePermuteList != null) {
        nodePermuteList = addColumnsToPermute(ds, idThesaurus, nodePermuteList);
    }
    return nodePermuteList;
}
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) NodePermute(mom.trd.opentheso.bdd.helper.nodes.NodePermute)

Aggregations

NodePermute (mom.trd.opentheso.bdd.helper.nodes.NodePermute)3 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 StringPlus (mom.trd.opentheso.bdd.tools.StringPlus)2