Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Testing bibtex key patterns and fixing title_case/capitalize modifiers #2663

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ private static String getAddition(int number) {
* Determines "number" words out of the "title" field in the given BibTeX entry
*/
public static String getTitleWords(int number, String title) {
return keepLettersAndDigitsOnly(getTitleWordsWithSpaces(number, title));
return getTitleWordsWithSpaces(number, title);
}

/**
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/org/jabref/logic/formatter/Formatters.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter;
import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter;
import org.jabref.logic.formatter.bibtexfields.OrdinalsToSuperscriptFormatter;
import org.jabref.logic.formatter.bibtexfields.RegexFormatter;
import org.jabref.logic.formatter.bibtexfields.RemoveBracesFormatter;
import org.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter;
import org.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class Formatters {
new NormalizeNamesFormatter(),
new NormalizePagesFormatter(),
new OrdinalsToSuperscriptFormatter(),
new RegexFormatter(),
new RemoveBracesFormatter(),
new UnitsToLatexFormatter(),
new EscapeUnderscoresFormatter()
Expand All @@ -68,7 +70,16 @@ private Formatters() {

public static Optional<Formatter> getFormatterForModifier(String modifier) {
Objects.requireNonNull(modifier);
Optional<Formatter> formatter = ALL.stream().filter(f -> f.getKey().equals(modifier)).findAny();
Optional<Formatter> formatter;

if (modifier.matches("regex.*")) {
String regex = modifier.substring(5);
RegexFormatter.setRegex(regex);
formatter = ALL.stream().filter(f -> f.getKey().equals("regex")).findAny();

} else {
formatter = ALL.stream().filter(f -> f.getKey().equals(modifier)).findAny();
}
if (formatter.isPresent()) {
return formatter;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.jabref.logic.formatter.bibtexfields;

import org.jabref.logic.l10n.Localization;
import org.jabref.model.cleanup.Formatter;

public class RegexFormatter implements Formatter {

private static String[] regex;

@Override
public String getName() {
return Localization.lang("Regex");
}

@Override
public String getKey() {
return "regex";
}

@Override
public String format(String input) {
if (regex == null) {
return input;
}
return input.replaceAll(regex[0], regex[1]);
}

@Override
public String getDescription() {
return Localization.lang("Add a regular expression for the key pattern.");
}

@Override
public String getExampleInput() {
return "Please replace the spaces";
}

public static void setRegex(String rex) {
// formatting is like ("exp1","exp2"), we want to remove (" and ")
rex = rex.substring(2, rex.length() - 2);
String[] parts = rex.split("\",\"");
regex = parts;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public String getKey() {
}

/**
* Converts the first character of the first word of the given string to upper case (and the remaining characters of the first word to lower case), but does not change anything if word starts with "{"
* Converts the first character of the first word of the given string to upper case (and the remaining characters of the first word to lower case) and changes other words to lower case, but does not change anything if word starts with "{"
*/
@Override
public String format(String input) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=Referencelibrary

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Undergruppe\:_Vis_poster_indeholdt_både_i_denne_gruppe_og_gruppe_over

Regex=

regular_expression=Regulærudtryk

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=Referenz-Datenbank

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Obergruppe_einbeziehen\:_Einträge_aus_dieser_Gruppe_und_ihrer_übergeordneten_Gruppe_anzeigen

Regex=

regular_expression=Regulärer_Ausdruck

Related_articles=ähnliche_Dokumente
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ The_path_need_not_be_on_the_classpath_of_JabRef.=The_path_need_not_be_on_the_cla
Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.=Add_a_(compiled)_custom_Importer_class_from_a_ZIP-archive.
The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.=The_ZIP-archive_need_not_be_on_the_classpath_of_JabRef.

Add_a_regular_expression_for_the_key_pattern.=Add_a_regular_expression_for_the_key_pattern.

Add_entry_selection_to_this_group=Add_entry_selection_to_this_group

Add_from_folder=Add_from_folder
Expand Down Expand Up @@ -991,6 +993,8 @@ Reference_library=Reference_library

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup

Regex=Regex

regular_expression=regular_expression

Related_articles=Related_articles
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=Base_de_datos_de_referencia

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Refinar_supergrupo\:_Ver_entradas_contenidas_en_este_grupo_y_sus_subgrupos_cuando_estén_seleccionadas

Regex=

regular_expression=Expresión_Regular

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=

Regex=

regular_expression=

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=Fichier_de_référence

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Raffine_le_super-groupe_\:_Quand_sélectionné,_afficher_les_entrées_contenues_à_la_fois_dans_ce_groupe_et_son_super-groupe

Regex=

regular_expression=Expression_régulière

Related_articles=Articles_liés
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=Basisdata_acuan

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Perbaiki_supergrup\:_Ketika_dipilih,_lihat_entri_yang_ada_di_grup_ini_dan_supergrup

Regex=

regular_expression=Ekspresi_reguler

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=Library_di_riferimenti

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Perfeziona_il_super-gruppo\:_Quando_selezionato,_mostra_le_voci_contenute_sia_in_questo_gruppo_sia_nel_suo_super-gruppo

Regex=

regular_expression=Espressione_regolare

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=参照データベース

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=上層グループの絞り込み:このグループとその上層グループの両方に含まれている項目を表示

Regex=

regular_expression=正規表現

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=Referentie_library

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Verfijn_supergroep\:_Wanneer_geselecteerd,_toon_de_entries_die_in_deze_groep_en_zijn_supergroep_zitten

Regex=

regular_expression=Regular_Expression

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=Referanselibrary

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Undergruppe\:_Vis_enheter_innehold_b\u00e5de_i_denne_gruppen_og_gruppen_over

Regex=

regular_expression=Regul\u00e6ruttrykk

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=Base_de_dados_de_referência

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Refinar_supergrupo\:_Quando_selecionado,_visualiza_referências_contidas_em_ambos_os_grupos_e_seu_supergrupo.

Regex=

regular_expression=Expressão_regular

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=БД_для_ссылки

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Детализировать_супергруппу\:_Просмотр_записей,_содержащихся_в_группе_и_ее_супергруппе_(если_выбрано)

Regex=

regular_expression=Регулярное_выражение

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=Referensdatabas

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=

Regex=

regular_expression=reguljärt_uttryck

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=Başvuru_veritabanı

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Supergrubu_arıt\:_Seçildiğinde,_hem_bu_grubun,_hem_de_süpergrubunun_içerdiği_girdileri_görüntüle

Regex=

regular_expression=Düzenli_İfade

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=CSDL_tham_khảo

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=Tinh_chỉnh_nhóm_lớn\:_Khi_được_chọn,_xem_các_mục_chứa_các_trong_nhóm_này_và_nhóm_lớn_của_nó

Regex=

regular_expression=Biểu_thức_chính_tắc

Related_articles=
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ Reference_library=参考文献数据库

Refine_supergroup\:_When_selected,_view_entries_contained_in_both_this_group_and_its_supergroup=提炼父分组:当分组被选中时,显示同时包含在该分组和它父分组中的记录

Regex=

regular_expression=正则表达式

Related_articles=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,20 +651,20 @@ public void veryShortTitle() {
public void shortTitle() {
// shortTitle is getTitleWords with "3" as count
int count = 3;
assertEquals("applicationmigrationeffort",
assertEquals("application migration effort",
BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_ALL_LOWER_FOUR_SMALL_WORDS_ONE_EN_DASH));
assertEquals("BPELconformancein", BibtexKeyPatternUtil.getTitleWords(count,
assertEquals("BPEL conformance in", BibtexKeyPatternUtil.getTitleWords(count,
TITLE_STRING_ALL_LOWER_FIRST_WORD_IN_BRACKETS_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON));
assertEquals("ProcessViewingPatterns", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED));
assertEquals("BPMNConformancein",
assertEquals("Process Viewing Patterns", BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED));
assertEquals("BPMN Conformance in",
BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_ONE_UPPER_WORD_ONE_SMALL_WORD));
assertEquals("TheDifferenceBetween", BibtexKeyPatternUtil.getTitleWords(count,
assertEquals("The Difference Between", BibtexKeyPatternUtil.getTitleWords(count,
TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AT_THE_BEGINNING));
assertEquals("CloudComputingThe",
assertEquals("Cloud Computing: The",
BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_SMALL_WORD_AFTER_COLON));
assertEquals("TowardsChoreographybased",
assertEquals("Towards Choreography based",
BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_TWO_SMALL_WORDS_ONE_CONNECTED_WORD));
assertEquals("OntheMeasurement",
assertEquals("On the Measurement",
BibtexKeyPatternUtil.getTitleWords(count, TITLE_STRING_CASED_FOUR_SMALL_WORDS_TWO_CONNECTED_WORDS));
}

Expand Down Expand Up @@ -785,7 +785,7 @@ public void testApplyModifiers() {
BibEntry entry = new BibEntry();
entry.setField("title", "Green Scheduling of Whatever");
assertEquals("GSo", BibtexKeyPatternUtil.makeLabel(entry, "shorttitleINI", ',', new BibDatabase()));
assertEquals("GreenSchedulingof", BibtexKeyPatternUtil.makeLabel(entry, "shorttitle",
assertEquals("Green Scheduling of", BibtexKeyPatternUtil.makeLabel(entry, "shorttitle",
',', new BibDatabase()));
}

Expand Down
Loading