-
-
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 11 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 | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,7 @@ | |||||
import java.util.Objects; | ||||||
import java.util.Optional; | ||||||
import java.util.Set; | ||||||
import java.util.regex.Matcher; | ||||||
import java.util.stream.Collectors; | ||||||
|
||||||
import org.h2.mvstore.MVMap; | ||||||
|
@@ -48,7 +49,8 @@ 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(); | ||||||
// Trims the String and also replaces any instances of "\&" with "&" for abbreviation search purposes | ||||||
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.
Suggested change
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. Removed! |
||||||
String journal = journalName.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); | ||||||
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. I think, there is the possibility to pre-compile the Regex. Was it with the |
||||||
|
||||||
boolean isKnown = customAbbreviations.stream().anyMatch(abbreviation -> isMatched(journal, abbreviation)); | ||||||
if (isKnown) { | ||||||
|
@@ -75,7 +77,8 @@ 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(); | ||||||
// Trims the String and also replaces any instances of "\&" with "&" for abbreviation search purposes | ||||||
String journal = input.trim().replaceAll(Matcher.quoteReplacement("\\&"), "&"); | ||||||
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. See above 😇 |
||||||
|
||||||
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 😃