Skip to content

Commit

Permalink
Merge pull request #111 from abes-esr/develop
Browse files Browse the repository at this point in the history
Merge dev dans main
  • Loading branch information
SamuelQuetin authored Jan 9, 2025
2 parents 6e6fa70 + 5aa3377 commit c5c0d85
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
</parent>
<groupId>fr.abes</groupId>
<artifactId>sudoc</artifactId>
<version>1.1.1</version>
<version>1.1.2-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sudoc</name>
<description>webservices de récupération de ppns dans le sudoc</description>
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ public List<String> datToPpn(Integer date, String auteur, String titre) throws U
if (titre == null || titre.isEmpty()) {
throw new IllegalArgumentException("Le titre ne peut pas être null");
}
log.debug("params : date : " + date + " auteur : " + auteur + " titre : " + titre);
StringBuilder request = new StringBuilder("SELECT DISTINCT a.PPN");
if (date != null) {
request.append(" FROM AUTORITES.biblio_table_generale a");
21 changes: 15 additions & 6 deletions src/main/java/fr/abes/sudoc/utils/Utilitaire.java
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ public static String replaceDiacritics(String src) {

public static String formatString(String chaine) {
if (chaine != null && !chaine.isEmpty()) {
return suppReservedWords(suppCaracters(chaine));
return ajoutNearBetweenWords(banalisationReservedWords(suppCaracters(chaine)));
}
return chaine;
}
@@ -112,12 +112,21 @@ private static String suppCaracters(String chaine) {
return chaine.replaceAll(regex, "");
}

private static String suppReservedWords(String chaine) {
List<String> wordsToRemove = Arrays.asList("ABOUT", "ACCUM", "AND", "BT", "BTG", "BTI", "BTP", "EQUIV", "FUZZY", "HASPATH", "INPATH", "MDATA", "MINUS", "NEAR", "NOT", "NT", "NTG", "NTI", "NTP", "OR", "PATTERN", "PT", "RT", "SQE", "SYN", "TR", "TRSYN", "TT", "WITHIN");
// Construire une expression régulière avec les caractères à supprimer
String regex = "\\b(" + String.join("|", wordsToRemove) + ")\\b";
return chaine.replaceAll("(?i)" + regex, "").replaceAll("\\s+", " ").trim();
private static String banalisationReservedWords(String chaine) {
List<String> reservedWords = Arrays.asList("ABOUT", "ACCUM", "AND", "BT", "BTG", "BTI", "BTP", "EQUIV", "FUZZY", "HASPATH", "INPATH", "MDATA", "MINUS", "NEAR", "NOT", "NT", "NTG", "NTI", "NTP", "OR", "PATTERN", "PT", "RT", "SQE", "SYN", "TR", "TRSYN", "TT", "WITHIN");
// Transformer la liste des mots réservés en une expression régulière
String regex = "\\b(" + String.join("|", reservedWords) + ")\\b";

// Remplacer les mots réservés par eux-mêmes entourés d'accolades
return chaine.toUpperCase().replaceAll(regex, "{$1}");
}

private static String ajoutNearBetweenWords(String chaine) {
// Split la chaîne en mots en éliminant les espaces multiples
String[] words = chaine.trim().split("\\s+");

// Utilise String.join pour insérer "NEAR" entre les mots
return String.join(" NEAR ", words);
}


6 changes: 3 additions & 3 deletions src/test/java/fr/abes/sudoc/utils/UtilitaireTest.java
Original file line number Diff line number Diff line change
@@ -110,8 +110,8 @@ void testReplaceDiacritics() {
@Test
@DisplayName("test reformatage chaine DAT")
void testReformatageChaineDat() {
Assertions.assertEquals("Assez de ces fichus TU", Utilitaire.formatString("Assez ! de _ ces ~fichus *TU"));
Assertions.assertEquals("Je suis content", Utilitaire.formatString("Je AND suis! WITHIN content"));
Assertions.assertEquals("Je suis content", Utilitaire.formatString("Je AND suis! 'WITHIN' content"));
Assertions.assertEquals("Assez NEAR de NEAR ces NEAR fichus NEAR TU".toUpperCase(), Utilitaire.formatString("Assez ! de _ ces ~fichus *TU"));
Assertions.assertEquals("Je NEAR {AND} NEAR suis NEAR {WITHIN} NEAR content".toUpperCase(), Utilitaire.formatString("Je AND suis! within content"));
Assertions.assertEquals("Je NEAR {AND} NEAR suis NEAR {WITHIN} NEAR content".toUpperCase(), Utilitaire.formatString("Je AND suis! 'WITHIN' content"));
}
}

0 comments on commit c5c0d85

Please sign in to comment.