-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 Abbreviation for Escaped Ampersand #9288
Changes from 18 commits
ed40cc2
3dc87ae
e56af9e
ff15343
bc31f93
4479e19
03a996b
1beef73
26b6527
97fdb55
d34b5cd
d8d0850
64cc386
5426806
0ed991b
d8a69c8
0efdc5a
18d7d8b
e18c792
f4658bc
943fa5b
7815ba0
fc0907b
0657b7e
046498b
098bdac
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 |
---|---|---|
|
@@ -9,6 +9,9 @@ | |
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
|
||
import org.h2.mvstore.MVMap; | ||
import org.h2.mvstore.MVStore; | ||
|
||
|
@@ -48,7 +51,7 @@ private static boolean isMatchedAbbreviated(String name, Abbreviation abbreviati | |
* Letters) or its abbreviated form (e.g. Phys. Rev. Lett.). | ||
*/ | ||
public boolean isKnownName(String journalName) { | ||
String journal = journalName.trim(); | ||
String journal = getLatexFreeJournal(journalName.trim()); | ||
|
||
boolean isKnown = customAbbreviations.stream().anyMatch(abbreviation -> isMatched(journal, abbreviation)); | ||
if (isKnown) { | ||
|
@@ -58,6 +61,22 @@ public boolean isKnownName(String journalName) { | |
return fullToAbbreviation.containsKey(journal) || abbreviationToFull.containsKey(journal); | ||
} | ||
|
||
/** | ||
* Returns the LaTeX free version of a journal (e.g., IEEE Design \& Test would be returned as IEEE Design & Test) | ||
* i.e., the journal name should not contain any unnecessary LaTeX syntax such as escaped ampersands | ||
* | ||
* @param journal The journal name | ||
* @return The LaTeX free version of the journal name | ||
*/ | ||
private String getLatexFreeJournal(String journal) { | ||
BibEntry entry = new BibEntry(); | ||
entry.setField(StandardField.JOURNAL, journal); | ||
if (entry.getResolvedFieldOrAliasLatexFree(StandardField.JOURNAL, null).isPresent()) { | ||
journal = entry.getResolvedFieldOrAliasLatexFree(StandardField.JOURNAL, null).get(); | ||
} | ||
return journal; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was not the intention - sorry for that! Your old code with the replacement was better! I thought, you were reading the BibTeX field content at some place. Here, you seem to read the journal name from somewhere. |
||
/** | ||
* Returns true if the given journal name is in its abbreviated form (e.g. Phys. Rev. Lett.). The test is strict, | ||
* i.e. journals whose abbreviation is the same as the full name are not considered | ||
|
@@ -75,7 +94,7 @@ public boolean isAbbreviatedName(String journalName) { | |
* @param input The journal name (either abbreviated or full name). | ||
*/ | ||
public Optional<Abbreviation> get(String input) { | ||
String journal = input.trim(); | ||
String journal = getLatexFreeJournal(input.trim()); | ||
|
||
Optional<Abbreviation> customAbbreviation = customAbbreviations.stream() | ||
.filter(abbreviation -> isMatched(journal, abbreviation)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,4 +134,16 @@ void getFromFullName() { | |
void getFromAbbreviatedName() { | ||
assertEquals(new Abbreviation("American Journal of Public Health", "Am. J. Public Health"), repository.get("Am. J. Public Health").get()); | ||
} | ||
|
||
@Test | ||
void testAbbreviationsWithEscapedAmpersand() { | ||
assertEquals(new Abbreviation("ACS Applied Materials & Interfaces", "ACS Appl. Mater. Interfaces"), repository.get("ACS Applied Materials & Interfaces").get()); | ||
assertEquals(new Abbreviation("ACS Applied Materials & Interfaces", "ACS Appl. Mater. Interfaces"), repository.get("ACS Applied Materials \\& Interfaces").get()); | ||
assertEquals(new Abbreviation("Antioxidants & Redox Signaling", "Antioxid. Redox Signaling"), repository.get("Antioxidants & Redox Signaling").get()); | ||
assertEquals(new Abbreviation("Antioxidants & Redox Signaling", "Antioxid. Redox Signaling"), repository.get("Antioxidants \\& Redox Signaling").get()); | ||
|
||
repository.addCustomAbbreviation(new Abbreviation("Long & Name", "L. N.", "LN")); | ||
assertEquals(new Abbreviation("Long & Name", "L. N.", "LN"), repository.get("Long & Name").get()); | ||
assertEquals(new Abbreviation("Long & Name", "L. N.", "LN"), repository.get("Long \\& Name").get()); | ||
Comment on lines
+152
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally, we expect one assertation per test case. Thus, this method should be split into several ones. |
||
} | ||
} |
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.
I would remove the last part, that information should be made available in the internet elsewhere 😃