Skip to content

Commit

Permalink
Fix for issue 7633: Unable to download arXiv pdfs if Title contains c…
Browse files Browse the repository at this point in the history
…urly brackets (#7652)

* fix 7633

* Update CHANGELOG.md

* Update ArXivTest.java

* Update CHANGELOG.md

* Update ArXivTest.java

* Update StringUtil.java

* Update ArXiv.java

* add white space

* update checkstyle
  • Loading branch information
Pikayue11 committed Apr 20, 2021
1 parent d10db0c commit 23d7573
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where opening BibTex file (doubleclick) from Folder with spaces not working. [#6487](https://github.com/JabRef/jabref/issues/6487)
- We fixed an issue with saving large `.bib` files [#7265](https://github.com/JabRef/jabref/issues/7265)
- We fixed an issue with very large page numbers [#7590](https://github.com/JabRef/jabref/issues/7590)
- We fixed an issue where the article title with curly brackets fails to download the arXiv link (pdf file). [#7633](https://github.com/JabRef/jabref/issues/7633)

### Removed

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/importer/fetcher/ArXiv.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private List<ArXivEntry> searchForEntries(BibEntry entry) throws FetcherExceptio
query = "doi:" + doi.get();
} else {
Optional<String> authorQuery = entry.getField(StandardField.AUTHOR).map(author -> "au:" + author);
Optional<String> titleQuery = entry.getField(StandardField.TITLE).map(title -> "ti:" + title);
Optional<String> titleQuery = entry.getField(StandardField.TITLE).map(title -> "ti:" + StringUtil.ignoreCurlyBracket(title));
query = OptionalUtil.toList(authorQuery, titleQuery).stream().collect(Collectors.joining("+AND+"));
}

Expand All @@ -146,7 +146,7 @@ private List<ArXivEntry> searchForEntries(BibEntry entry) throws FetcherExceptio
// Check if entry is a match
StringSimilarity match = new StringSimilarity();
String arxivTitle = arxivEntry.get().title.orElse("");
String entryTitle = entry.getField(StandardField.TITLE).orElse("");
String entryTitle = StringUtil.ignoreCurlyBracket(entry.getField(StandardField.TITLE).orElse(""));

if (match.isSimilar(arxivTitle, entryTitle)) {
return OptionalUtil.toList(arxivEntry);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/model/strings/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -735,4 +735,8 @@ public static boolean containsIgnoreCase(String text, String searchString) {
public static String substringBetween(String str, String open, String close) {
return StringUtils.substringBetween(str, open, close);
}

public static String ignoreCurlyBracket(String title) {
return isNotBlank(title) ? title.replace("{", "").replace("}", "") : title;
}
}
15 changes: 15 additions & 0 deletions src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ void findFullTextByTitle() throws IOException {
assertEquals(Optional.of(new URL("http://arxiv.org/pdf/cond-mat/0406246v1")), fetcher.findFullText(entry));
}

@Test
void findFullTextByTitleWithCurlyBracket() throws IOException {
entry.setField(StandardField.TITLE, "Machine versus {Human} {Attention} in {Deep} {Reinforcement} {Learning} {Tasks}");

assertEquals(Optional.of(new URL("https://arxiv.org/pdf/2010.15942v2")), fetcher.findFullText(entry));
}

@Test
void findFullTextByTitleAndPartOfAuthor() throws IOException {
entry.setField(StandardField.TITLE, "Pause Point Spectra in DNA Constant-Force Unzipping");
Expand All @@ -103,6 +110,14 @@ void findFullTextByTitleAndPartOfAuthor() throws IOException {
assertEquals(Optional.of(new URL("http://arxiv.org/pdf/cond-mat/0406246v1")), fetcher.findFullText(entry));
}

@Test
void findFullTextByTitleWithCurlyBracketAndPartOfAuthor() throws IOException {
entry.setField(StandardField.TITLE, "Machine versus {Human} {Attention} in {Deep} {Reinforcement} {Learning} {Tasks}");
entry.setField(StandardField.AUTHOR, "Zhang, Ruohan and Guo");

assertEquals(Optional.of(new URL("https://arxiv.org/pdf/2010.15942v2")), fetcher.findFullText(entry));
}

@Test
void notFindFullTextByUnknownDOI() throws IOException {
entry.setField(StandardField.DOI, "10.1529/unknown");
Expand Down

0 comments on commit 23d7573

Please sign in to comment.