Skip to content

Fix citation key table #13151

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

Merged
merged 6 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -64,35 +64,21 @@ public void writeFindings() throws IOException {
private void initializeColumnWidths() {
columnWidths = new ArrayList<>(columnNames.size());

Integer max = getColumnWidthOfEntryTypes();
columnWidths.add(max);
int entryTypeWidth = "entry type".length();
int citationKeyWidth = "citation key".length();

max = getColumnWidthOfCitationKeys(max);
columnWidths.add(max);
for (var keysAndValue : result.entryTypeToResultMap().entrySet()) {
entryTypeWidth = Math.max(entryTypeWidth, keysAndValue.getKey().getDisplayName().length());
for (var entry : keysAndValue.getValue().sortedEntries()) {
citationKeyWidth = Math.max(citationKeyWidth, entry.getCitationKey().orElse("").length());
}
}

columnWidths.add(entryTypeWidth);
columnWidths.add(citationKeyWidth);
columnWidths.addAll(columnNames.stream().skip(2).map(String::length).toList());
}

private Integer getColumnWidthOfEntryTypes() {
int max = result.entryTypeToResultMap().keySet()
.stream()
.map(entryType -> entryType.getDisplayName().length())
.max(Integer::compareTo)
.get();
max = Math.max(max, "entry type".length());
return max;
}

private Integer getColumnWidthOfCitationKeys(Integer max) {
result.entryTypeToResultMap().values()
.stream()
.flatMap(entryTypeResult -> entryTypeResult.sortedEntries().stream())
.map(entry -> entry.getCitationKey().orElse("").length())
.max(Integer::compareTo)
.get();
return Math.max(max, "citation key".length());
}

@Override
protected void writeBibEntry(BibEntry bibEntry, String entryType, Set<Field> requiredFields, Set<Field> optionalFields) throws IOException {
List<String> theRecord = getFindingsAsList(bibEntry, entryType, requiredFields, optionalFields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ void checkDifferentOutputSymbols(@TempDir Path tempDir) throws IOException {
""", Files.readString(txtFile).replace("\r\n", "\n"));
}

@Test
void checkVeryLongCitationKey(@TempDir Path tempDir) throws IOException {
UnknownField customField = new UnknownField("custom");
BibEntry first = new BibEntry(StandardEntryType.Article, "first-very-long-key")
.withField(StandardField.AUTHOR, "Author One") // required
.withField(StandardField.TITLE, "Title") // required
.withField(StandardField.PAGES, "some pages") // optional
.withField(customField, "custom"); // unknown
BibEntry second = new BibEntry(StandardEntryType.Article, "second")
.withField(StandardField.AUTHOR, "Author One");
BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(List.of(first, second));

Path txtFile = tempDir.resolve("checkDifferentOutputSymbols-result.txt");
try (Writer writer = new OutputStreamWriter(Files.newOutputStream(txtFile));
BibliographyConsistencyCheckResultTxtWriter BibliographyConsistencyCheckResultTxtWriter = new BibliographyConsistencyCheckResultTxtWriter(result, writer, false)) {
BibliographyConsistencyCheckResultTxtWriter.writeFindings();
}
assertEquals("""
Field Presence Consistency Check Result

| entry type | citation key | Custom | Pages | Title |
| ---------- | ------------------- | ------ | ----- | ----- |
| Article | first-very-long-key | ? | o | x |

x | required field is present
o | optional field is present
? | unknown field is present
- | field is absent
""", Files.readString(txtFile).replace("\r\n", "\n"));
}

@Test
void checkComplexLibrary(@TempDir Path tempDir) throws IOException {
BibEntry first = new BibEntry(StandardEntryType.Article, "first")
Expand Down Expand Up @@ -120,12 +151,12 @@ void checkComplexLibrary(@TempDir Path tempDir) throws IOException {
assertEquals("""
Field Presence Consistency Check Result

| entry type | citation key | Location | Pages | Publisher |
| ------------- | ------------- | -------- | ----- | --------- |
| Article | first | - | o | - |
| Article | second | - | - | ? |
| InProceedings | fourth | - | - | o |
| InProceedings | third | ? | o | - |
| entry type | citation key | Location | Pages | Publisher |
| ------------- | ------------ | -------- | ----- | --------- |
| Article | first | - | o | - |
| Article | second | - | - | ? |
| InProceedings | fourth | - | - | o |
| InProceedings | third | ? | o | - |

x | required field is present
o | optional field is present
Expand Down