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;
}
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();
}
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();
}
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;
}
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;
}
Aggregations