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

Fix #1271: Authors with compound first names are parsed properly #1282

Merged
merged 1 commit into from
Apr 29, 2016
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- Fixed [#1245](https://github.com/JabRef/jabref/issues/1245): Empty jstyle properties can now be specified as ""
- Fixed [#1259](https://github.com/JabRef/jabref/issues/1259): NPE when sorting tabs
- Fixed display bug in the cleanup dialog: field formatters are now correctly displayed using their name
- Fixed [#1245](https://github.com/JabRef/jabref/issues/1245): Empty jstyle properties can now be specified as ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

- Fixed [#1271](https://github.com/JabRef/jabref/issues/1271): Authors with compound first names are displayed properly

### Removed
- Removed possibility to export entries/databases to an `.sql` file, as the logic cannot easily use the correct escape logic
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/net/sf/jabref/model/entry/AuthorList.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package net.sf.jabref.model.entry;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.WeakHashMap;
Expand Down Expand Up @@ -156,6 +157,10 @@ protected AuthorList(List<Author> authors) {
this.authors = Objects.requireNonNull(authors);
}

protected AuthorList(Author author) {
this(Collections.singletonList(author));
}

/**
* Retrieve an AuthorList for the given string of authors or editors.
* <p>
Expand Down Expand Up @@ -416,7 +421,7 @@ public String getAsLastFirstNames(boolean abbreviate, boolean oxfordComma) {

@Override
public String toString() {
return getAsLastFirstNamesWithAnd(false);
return authors.toString();
}

/**
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/net/sf/jabref/model/entry/AuthorListParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public class AuthorListParser {
}


private static final int TOKEN_GROUP_LENGTH = 4; // number of entries for

// a token
private static final int TOKEN_GROUP_LENGTH = 4; // number of entries for a token

// the following are offsets of an entry in a group of entries for one token
private static final int OFFSET_TOKEN = 0; // String -- token itself;
Expand Down Expand Up @@ -137,6 +135,11 @@ private Author getAuthor() {
}
if (vonStart < 0) {
if (!tokenCase) {
int previousTermToken = tokens.size() - TOKEN_GROUP_LENGTH - TOKEN_GROUP_LENGTH + OFFSET_TOKEN_TERM;
if(previousTermToken >= 0 && tokens.get(previousTermToken).equals('-')) {
// We are in a first name which contained a hyphen
break;
}
vonStart = tokens.size() - TOKEN_GROUP_LENGTH;
break;
}
Expand Down Expand Up @@ -353,12 +356,12 @@ private int getToken() {
if (c == '{') {
bracesLevel++;
}
if ((c == '}') && (bracesLevel > 0)) {
bracesLevel--;
}
if (firstLetterIsFound && (tokenAbbr < 0) && (bracesLevel == 0)) {
tokenAbbr = tokenEnd;
}
if ((c == '}') && (bracesLevel > 0)) {
bracesLevel--;
}
if (!firstLetterIsFound && (currentBackslash < 0) && Character.isLetter(c)) {
if (bracesLevel == 0) {
tokenCase = Character.isUpperCase(c);
Expand Down Expand Up @@ -386,11 +389,6 @@ private int getToken() {
if ((bracesLevel == 0) && ((",;~-".indexOf(c) != -1) || Character.isWhitespace(c))) {
break;
}
// Morten Alver 18 Apr 2006: Removed check for hyphen '-' above to
// prevent
// problems with names like Bailey-Jones getting broken up and
// sorted wrong.
// Aaron Chen 14 Sep 2008: Enable hyphen check for first names like Chang-Chin
tokenEnd++;
}
if (tokenAbbr < 0) {
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/net/sf/jabref/model/entry/AuthorListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,29 @@ public void testRemoveStartAndEndBraces() {
public void createCorrectInitials() {
Assert.assertEquals("J. G.", AuthorList.parse("Hornberg, Johann Gottfried").getAuthor(0).getFirstAbbr());
}

@Test
public void parseNameWithBracesAroundFirstName() throws Exception {
//TODO: Be more intelligent and abbreviate the first name correctly
Author expected = new Author("Tse-tung", "{Tse-tung}.", null, "Mao", null);
Assert.assertEquals(new AuthorList(expected), AuthorList.parse("{Tse-tung} Mao"));
}

@Test
public void parseNameWithBracesAroundLastName() throws Exception {
Author expected = new Author("Hans", "H.", null, "van den Bergen", null);
Assert.assertEquals(new AuthorList(expected), AuthorList.parse("{van den Bergen}, Hans"));
}

@Test
public void parseNameWithHyphenInFirstName() throws Exception {
Author expected = new Author("Tse-tung", "T.-t.", null, "Mao", null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct abbreviation or should one deal with parts without capitals in a special way?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking again, maybe it is better to just leave it like this and work on the TODO above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand this Java code, but, for the record, the regular abbreviation of Tse-tung is T.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it depends a bit on the convention / citation style which abbreviation is "correct". In the end I decided to leave it like that because it is not a big deal.

@mlep thanks for reporting this issue in the first place. I think the author formatting has still some problems with not-so-common-cases.

Assert.assertEquals(new AuthorList(expected), AuthorList.parse("Tse-tung Mao"));
}

@Test
public void parseNameWithHyphenInLastName() throws Exception {
Author expected = new Author("Firstname", "F.", null, "Bailey-Jones", null);
Assert.assertEquals(new AuthorList(expected), AuthorList.parse("Firstname Bailey-Jones"));
}
}