-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fixes and Extends BibliographyConsistencyCheck.check to Handle Custom Entry Types #14257
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
ba9446d
c5c1b96
7941238
94ab173
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| import org.jabref.logic.quality.consistency.BibliographyConsistencyCheckResultTxtWriter; | ||
| import org.jabref.logic.quality.consistency.BibliographyConsistencyCheckResultWriter; | ||
| import org.jabref.model.database.BibDatabaseContext; | ||
| import org.jabref.model.entry.BibEntryTypesManager; | ||
| import org.jabref.toolkit.cli.converter.CygWinPathConverter; | ||
|
|
||
| import org.slf4j.Logger; | ||
|
|
@@ -65,7 +66,7 @@ public Integer call() { | |
| BibDatabaseContext databaseContext = parserResult.get().getDatabaseContext(); | ||
|
|
||
| BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck(); | ||
| BibliographyConsistencyCheck.Result result = consistencyCheck.check(databaseContext, (count, total) -> { | ||
| BibliographyConsistencyCheck.Result result = consistencyCheck.check(databaseContext, new BibEntryTypesManager(), (count, total) -> { | ||
|
||
| if (!sharedOptions.porcelain) { | ||
| System.out.println(Localization.lang("Checking consistency for entry type %0 of %1", count + 1, total)); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,12 @@ | |
| import org.jabref.model.database.BibDatabaseMode; | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.BibEntryType; | ||
| import org.jabref.model.entry.BibEntryTypesManager; | ||
| import org.jabref.model.entry.field.Field; | ||
| import org.jabref.model.entry.field.InternalField; | ||
| import org.jabref.model.entry.field.SpecialField; | ||
| import org.jabref.model.entry.field.StandardField; | ||
| import org.jabref.model.entry.field.UserSpecificCommentField; | ||
| import org.jabref.model.entry.types.BiblatexEntryTypeDefinitions; | ||
| import org.jabref.model.entry.types.BibtexEntryTypeDefinitions; | ||
| import org.jabref.model.entry.types.EntryType; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
|
|
@@ -102,22 +101,17 @@ public record EntryTypeResult(Collection<Field> fields, SequencedCollection<BibE | |
| * | ||
| * @implNote This class does not implement {@link org.jabref.logic.integrity.DatabaseChecker}, because it returns a list of {@link org.jabref.logic.integrity.IntegrityMessage}, which are too fine-grained. | ||
| */ | ||
| public Result check(BibDatabaseContext bibContext, BiConsumer<Integer, Integer> entriesGroupingProgress) { | ||
| public Result check(BibDatabaseContext bibContext, BibEntryTypesManager bibEntryTypesManager, BiConsumer<Integer, Integer> entriesGroupingProgress) { | ||
| // collects fields existing in any entry, scoped by entry type | ||
| Map<EntryType, Set<Field>> entryTypeToFieldsInAnyEntryMap = new HashMap<>(); | ||
| // collects fields existing in all entries, scoped by entry type | ||
| // collects fields existing in all entries, scoped by entry typed | ||
|
||
| Map<EntryType, Set<Field>> entryTypeToFieldsInAllEntriesMap = new HashMap<>(); | ||
| // collects entries of the same type | ||
| Map<EntryType, Set<BibEntry>> entryTypeToEntriesMap = new HashMap<>(); | ||
|
|
||
| collectEntriesIntoMaps(bibContext, entryTypeToFieldsInAnyEntryMap, entryTypeToFieldsInAllEntriesMap, entryTypeToEntriesMap); | ||
|
|
||
| List<BibEntryType> entryTypeDefinitions; | ||
| if (bibContext.getMode() == BibDatabaseMode.BIBLATEX) { | ||
| entryTypeDefinitions = BiblatexEntryTypeDefinitions.ALL; | ||
| } else { | ||
| entryTypeDefinitions = BibtexEntryTypeDefinitions.ALL; | ||
| } | ||
| List<BibEntryType> entryTypeDefinitions = bibEntryTypesManager.getAllTypes(bibContext.getMode()).stream().toList(); | ||
|
|
||
| // Use LinkedHashMap to preserve the order of Bib(tex|latex)EntryTypeDefinitions.ALL | ||
| Map<EntryType, EntryTypeResult> resultMap = new LinkedHashMap<>(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import org.jabref.model.database.BibDatabaseContext; | ||
| import org.jabref.model.database.BibDatabaseMode; | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.BibEntryTypesManager; | ||
| import org.jabref.model.entry.field.StandardField; | ||
| import org.jabref.model.entry.field.UnknownField; | ||
| import org.jabref.model.entry.types.StandardEntryType; | ||
|
|
@@ -42,7 +43,7 @@ void checkSimpleLibrary(@TempDir Path tempDir) throws IOException { | |
| database.insertEntry(second); | ||
|
|
||
| BibDatabaseContext bibContext = new BibDatabaseContext(database); | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (count, total) -> { | ||
|
||
| }); | ||
|
|
||
| Path csvFile = tempDir.resolve("checkSimpleLibrary-result.csv"); | ||
|
|
@@ -73,7 +74,7 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) throws IOException { | |
|
|
||
| BibDatabaseContext bibContext = new BibDatabaseContext(database); | ||
| bibContext.setMode(BibDatabaseMode.BIBTEX); | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (count, total) -> { | ||
| }); | ||
|
|
||
| Path csvFile = tempDir.resolve("checkDifferentOutputSymbols-result.csv"); | ||
|
|
@@ -119,7 +120,7 @@ void checkComplexLibrary(@TempDir Path tempDir) throws IOException { | |
| database.insertEntry(fifth); | ||
|
|
||
| BibDatabaseContext bibContext = new BibDatabaseContext(database); | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (count, total) -> { | ||
| }); | ||
|
|
||
| Path csvFile = tempDir.resolve("checkSimpleLibrary-result.csv"); | ||
|
|
@@ -151,7 +152,7 @@ void checkLibraryWithoutIssues(@TempDir Path tempDir) throws IOException { | |
|
|
||
| BibDatabaseContext bibContext = new BibDatabaseContext(database); | ||
| bibContext.setMode(BibDatabaseMode.BIBTEX); | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, new BibEntryTypesManager(), (count, total) -> { | ||
| }); | ||
|
|
||
| Path csvFile = tempDir.resolve("checkLibraryWithoutIssues-result.csv"); | ||
|
|
@@ -170,7 +171,7 @@ void checkManualInput() throws IOException { | |
| Path file = Path.of("C:\\TEMP\\JabRef\\biblio-anon.bib"); | ||
| Path csvFile = file.resolveSibling("biblio-cited.csv"); | ||
| BibDatabaseContext databaseContext = importer.importDatabase(file).getDatabaseContext(); | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, (_, _) -> { | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(databaseContext, new BibEntryTypesManager(), (_, _) -> { | ||
| }); | ||
| try (Writer writer = new OutputStreamWriter(Files.newOutputStream(csvFile)); | ||
| BibliographyConsistencyCheckResultCsvWriter paperConsistencyCheckResultCsvWriter = new BibliographyConsistencyCheckResultCsvWriter(result, writer, true)) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,20 +9,30 @@ | |
| import org.jabref.model.database.BibDatabaseContext; | ||
| import org.jabref.model.database.BibDatabaseMode; | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.BibEntryTypesManager; | ||
| import org.jabref.model.entry.field.Field; | ||
| import org.jabref.model.entry.field.SpecialField; | ||
| import org.jabref.model.entry.field.StandardField; | ||
| import org.jabref.model.entry.field.UnknownField; | ||
| import org.jabref.model.entry.field.UserSpecificCommentField; | ||
| import org.jabref.model.entry.types.StandardEntryType; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| class BibliographyConsistencyCheckTest { | ||
|
|
||
| private BibEntryTypesManager entryTypesManager; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| // TODO: add some custom entry types for this manager and test with it | ||
|
||
| entryTypesManager = new BibEntryTypesManager(); | ||
| } | ||
|
|
||
| @Test | ||
| void checkSimpleLibrary(@TempDir Path tempDir) { | ||
| BibEntry first = new BibEntry(StandardEntryType.Article, "first") | ||
|
|
@@ -34,7 +44,7 @@ void checkSimpleLibrary(@TempDir Path tempDir) { | |
| BibDatabase database = new BibDatabase(List.of(first, second)); | ||
| BibDatabaseContext bibContext = new BibDatabaseContext(database); | ||
| bibContext.setMode(BibDatabaseMode.BIBTEX); | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (count, total) -> { | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (count, total) -> { | ||
| }); | ||
|
|
||
| BibliographyConsistencyCheck.EntryTypeResult entryTypeResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER), List.of(first, second)); | ||
|
|
@@ -55,7 +65,7 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) { | |
| BibDatabase bibDatabase = new BibDatabase(List.of(first, second)); | ||
| BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); | ||
| bibContext.setMode(BibDatabaseMode.BIBTEX); | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (_, _) -> { | ||
| }); | ||
|
|
||
| BibliographyConsistencyCheck.EntryTypeResult entryTypeResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.TITLE, customField), List.of(first, second)); | ||
|
|
@@ -88,7 +98,7 @@ void checkComplexLibrary(@TempDir Path tempDir) { | |
| BibDatabase bibDatabase = new BibDatabase(List.of(first, second, third, fourth, fifth)); | ||
| BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); | ||
|
|
||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (_, _) -> { | ||
| }); | ||
|
|
||
| BibliographyConsistencyCheck.EntryTypeResult articleResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER), List.of(first, second)); | ||
|
|
@@ -111,7 +121,7 @@ void checkLibraryWithoutIssues(@TempDir Path tempDir) { | |
| BibDatabase bibDatabase = new BibDatabase(List.of(first, second)); | ||
| BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); | ||
|
|
||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (_, _) -> { | ||
| }); | ||
|
|
||
| BibliographyConsistencyCheck.Result expected = new BibliographyConsistencyCheck.Result(Map.of()); | ||
|
|
@@ -133,7 +143,7 @@ void filteredFieldsAreIgnored() { | |
| BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); | ||
|
|
||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() | ||
| .check(bibContext, (_, _) -> { | ||
| .check(bibContext, entryTypesManager, (_, _) -> { | ||
| }); | ||
|
|
||
| assertEquals(Map.of(), result.entryTypeToResultMap(), | ||
|
|
@@ -150,7 +160,7 @@ void nonFilteredFieldDifferenceIsReported() { | |
| BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); | ||
|
|
||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() | ||
| .check(bibContext, (_, _) -> { | ||
| .check(bibContext, entryTypesManager, (_, _) -> { | ||
| }); | ||
|
|
||
| BibliographyConsistencyCheck.EntryTypeResult typeResult = | ||
|
|
@@ -174,7 +184,7 @@ void unsetRequriedFieldsReported() { | |
| bibContext.setMode(BibDatabaseMode.BIBLATEX); | ||
|
|
||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() | ||
| .check(bibContext, (_, _) -> { | ||
| .check(bibContext, entryTypesManager, (_, _) -> { | ||
| }); | ||
|
|
||
| BibliographyConsistencyCheck.EntryTypeResult typeResult = | ||
|
|
@@ -198,7 +208,7 @@ void unsetFieldsReportedInBibtexMode() { | |
| BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); | ||
| bibContext.setMode(BibDatabaseMode.BIBTEX); | ||
| BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck() | ||
| .check(bibContext, (_, _) -> { | ||
| .check(bibContext, entryTypesManager, (_, _) -> { | ||
| }); | ||
| BibliographyConsistencyCheck.EntryTypeResult typeResult = | ||
| result.entryTypeToResultMap().get(StandardEntryType.Online); | ||
|
|
@@ -268,7 +278,7 @@ void checkComplexLibraryWithAdditionalEntry(@TempDir Path tempDir) { | |
| BibDatabase bibDatabase = new BibDatabase(List.of(first, second, third, fourth, fifth, sixth)); | ||
| BibDatabaseContext bibContext = new BibDatabaseContext(bibDatabase); | ||
|
|
||
| BibliographyConsistencyCheck.Result actualResult = new BibliographyConsistencyCheck().check(bibContext, (_, _) -> { | ||
| BibliographyConsistencyCheck.Result actualResult = new BibliographyConsistencyCheck().check(bibContext, entryTypesManager, (_, _) -> { | ||
| }); | ||
|
|
||
| BibliographyConsistencyCheck.EntryTypeResult articleResult = new BibliographyConsistencyCheck.EntryTypeResult(Set.of(StandardField.PAGES, StandardField.PUBLISHER), List.of(first, second)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't inject - we pass by constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update:
https://github.com/JabRef/jabref/pull/14257/files#diff-1b46713ccfa86a11ee5ea9a4e03b335425b8e5a8981b26fdb5bfb1fc32b3c544L32