Skip to content

Commit

Permalink
Fixes generated bibtex key and display of institute authors (JabRef#6479
Browse files Browse the repository at this point in the history
)

* Fix Pattern.compile for frequently used regexes

* Fix one additional Pattern.compile

* Fix style and unnecessary escape sequences

* Fix invalid index in call to substring

The original condition is evaluated to false.
The substring is shorter than "uni".

* Refactor name and javadoc of a regex

* Fix use of compiled regex for matching department

* Fix check for uppercase letter

Perhaps the assumption should be that the letters are ASCII.
If all letters are ASCII checking 'A' <= k.charAt(0) <= 'Z'
might make more sense.
I am not convinced about doing this with a regex.

* Fix usage of uncompiled regex

* Fix readability?

* Add test cases

Both test cases involves an author name containing department or school
 without university or institute of technology.

* Fix `null` appearing as part of author name

Corporate authors without university/institute of technology

* Refactor name of capital regex pattern

* Add debug output for reordering of names in fields

* Add helper methods

* Fix missing negation in "uni" matching

* Fix test cases for corporate authors

* Fix to keep all uppercase letters in abbreviation

* Fix commented out code

* Fix key for institution's name containing keyword

If the name of an institution can't be split, assume that
"School"/"Department" is part of the name.

* Fix test case for short institution name

* Refactor check for institution types

* Refactor comments and names improving readability?

* Refactor to improve readability and closure

* Fix JavaDoc

Minor typos and the "rest" part is now created differently.

* Fix JavaDoc typos

* Fix preliminary order for authors -> latexfree

* Drop logger

* Add convenience methods for cached latexfree names

* Add name format method for names containing latex

* Add call to formatNameLatexFree

* Fix unclear statement in JavaDoc

* Fix to only keep the first character of each word

There are some examples that will turn out wrong if only capital letters
 are kept, e.g., "iOS Developer University Program".
 The original problem with "The School of Life" becoming too short is
 avoided by only removing school/department for names containing two or
  more ',' separated strings. This will still produce an unexpected
   result if the address of the institution is part of the authors field

* Add latexfree Natbib test cases

* Fix typo in latex-free test cases

* Add Natbib test with escaped brackets

* Add Natbib institution test with escaped brackets

* Add test for latex-free comma separated lastnames

* Add test for latex-free comma separated first name

First name first and abbreviated first name first

* Add test for latex-free comma separated last name

Last name first and abbreviated first names

* Fix adherence to JavaDoc and readability(?)

* Fix readability(?)

* Fix CheckStyle issues

The deprecated static methods BibtexKeyGenerator.generateKey are moved
to the test file as a similar convenience method is required for
the test cases. Suppress warning has been added for some methods.

* Fix CHANGELOG.md

* Fix mistake in BibtexKeyGeneratorTest

generateKey was not copy-pasted properly.

* Add test for oxford comma

* Fix miss-capitalization of enum

* Fix fields not displayed latex-free

* Fix in-line methods in MainTableNameFormatter

* Fix in-line of generateKey() method

* Fix separating tests into parsing/representation

* Fix cache check and simplify expressions

* Drop inlined methods

* Fix most abbreviated abbreviations

* Drop old formatName method

* Refactor formatNameLatexFree

The author list parsing is moved outside of the if/else statements

* Refactor new parse tests

* Add more parse tests

* Drop all test cases containing escaped brackets

* Refactor parse with latex tests

Move them close to other parse tests

* Fix my own spelling mistakes

* Refactor abbreviation name
  • Loading branch information
k3KAW8Pnf7mkmdSMPHz27 authored May 28, 2020
1 parent c119ca2 commit 08eccb6
Show file tree
Hide file tree
Showing 7 changed files with 894 additions and 287 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where brackets in regular expressions were not working. [6469](https://github.com/JabRef/jabref/pull/6469)
- We fixed an issue where LaTeX citations for specific commands (\autocites) of biblatex-mla were not recognized. [#6476](https://github.com/JabRef/jabref/issues/6476)
- We fixed an issue where drag and drop was not working on empty database. [#6487](https://github.com/JabRef/jabref/issues/6487)
- We fixed an issue where "null" appeared in generated BibTeX keys. [#6459](https://github.com/JabRef/jabref/issues/6459)
- We fixed an issue where the authors' names were incorrectly displayed in the authors' column when they were bracketed. [#6465](https://github.com/JabRef/jabref/issues/6465) [#6459](https://github.com/JabRef/jabref/issues/6459)

### Removed

Expand Down
37 changes: 18 additions & 19 deletions src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,27 @@ public ObservableValue<String> getFields(OrFields fields) {
ObservableValue<String> value = fieldValues.get(fields);
if (value != null) {
return value;
} else {
value = Bindings.createStringBinding(() -> {
boolean isName = false;
}

Optional<String> content = Optional.empty();
for (Field field : fields) {
content = entry.getResolvedFieldOrAliasLatexFree(field, database);
if (content.isPresent()) {
isName = field.getProperties().contains(FieldProperty.PERSON_NAMES);
break;
}
}
value = Bindings.createStringBinding(() -> {
for (Field field : fields) {
if (field.getProperties().contains(FieldProperty.PERSON_NAMES)) {
Optional<String> name = entry.getResolvedFieldOrAlias(field, database);

String result = content.orElse(null);
if (isName) {
return nameFormatter.formatName(result);
if (name.isPresent()) {
return nameFormatter.formatNameLatexFree(name.get());
}
} else {
return result;
Optional<String> content = entry.getResolvedFieldOrAliasLatexFree(field, database);

if (content.isPresent()) {
return content.get();
}
}
}, entry.getObservables());
fieldValues.put(fields, value);
return value;
}
}
return "";
}, entry.getObservables());
fieldValues.put(fields, value);
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,28 @@ public class MainTableNameFormatter {
}

/**
* Format a name field for the table, according to user preferences.
* Format a name field for the table, according to user preferences and with latex expressions translated if
* possible.
*
* @param nameToFormat The contents of the name field.
* @return The formatted name field.
*/
public String formatName(final String nameToFormat) {
public String formatNameLatexFree(final String nameToFormat) {
if (nameToFormat == null) {
return null;
}
AuthorList authors = AuthorList.parse(nameToFormat);

if (namesAsIs) {
return nameToFormat;
} else if (namesNatbib) {
return AuthorList.fixAuthorNatbib(nameToFormat);
return authors.getAsNatbibLatexFree();
} else if (namesLastOnly) {
return AuthorList.fixAuthorLastNameOnlyCommas(nameToFormat, false);
return authors.getAsLastNamesLatexFree(false);
} else if (namesFf) {
return AuthorList.fixAuthorFirstNameFirstCommas(nameToFormat, abbrAuthorNames, false);
return authors.getAsFirstLastNamesLatexFree(abbrAuthorNames, false);
} else {
return AuthorList.fixAuthorLastNameFirstCommas(nameToFormat, abbrAuthorNames, false);
return authors.getAsLastFirstNamesLatexFree(abbrAuthorNames, false);
}
}
}
Loading

0 comments on commit 08eccb6

Please sign in to comment.