Skip to content

Commit

Permalink
DOAB Fetcher now fetches ISBN field where possible
Browse files Browse the repository at this point in the history
This commit modifies the URL for DOAB query to include `BITSTREAM` data. The fetcher can then obtain the ISBN and add the field to the entry accordingly. fixes JabRef#8708.
  • Loading branch information
shafinkamal committed Oct 10, 2022
1 parent e48ed0c commit 5e055a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We reworked the Define study parameters dialog. [#9123](https://github.com/JabRef/jabref/pull/9123)
- We simplified the actions to fast-resolve duplicates to 'Keep Left', 'Keep Right', 'Keep Both' and 'Keep Merged'. [#9056](https://github.com/JabRef/jabref/issues/9056)
- We fixed an issue where a message about changed metadata would occur on saving although nothing changed. [#9159](https://github.com/JabRef/jabref/issues/9159)
- We modified the Directory of Open Access Books (DOAB) fetcher so that it will now also fetch the ISBN when possible. [#8708](https://github.com/JabRef/jabref/issues/8708)

### Fixed

Expand Down
30 changes: 25 additions & 5 deletions src/main/java/org/jabref/logic/importer/fetcher/DOABFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public URL getURLForQuery(QueryNode luceneQuery) throws URISyntaxException, Malf
// without the quotation the results returned are not relevant to the query
query = ("\"".concat(query)).concat("\"");
builder.addParameter("query", query);
builder.addParameter("expand", "metadata");
// bitstreams included in URL building to acquire ISBN's.
builder.addParameter("expand", "metadata,bitstreams");

return builder.build().toURL();
}
Expand All @@ -64,24 +65,43 @@ public Parser getParser() {
// the information used for bibtex entries are in an array inside the resulting jsonarray
// see this query for reference https://directory.doabooks.org/rest/search?query="i open fire"&expand=metadata
JSONArray metadataArray = response.getJSONObject(0).getJSONArray("metadata");
BibEntry entry = jsonToBibEntry(metadataArray);
JSONArray bitstreamArray = response.getJSONObject(0).getJSONArray("bitstreams");
BibEntry entry = jsonToBibEntry(metadataArray, bitstreamArray);
return Collections.singletonList(entry);
}
List<BibEntry> entries = new ArrayList<>(response.length());
for (int i = 0; i < response.length(); i++) {
JSONArray metadataArray = response.getJSONObject(i).getJSONArray("metadata");
BibEntry entry = jsonToBibEntry(metadataArray);
JSONArray bitstreamArray = response.getJSONObject(i).getJSONArray("bitstreams");
BibEntry entry = jsonToBibEntry(metadataArray, bitstreamArray);
entries.add(entry);
}
return entries;
};
}

private BibEntry jsonToBibEntry(JSONArray metadataArray) {
private BibEntry jsonToBibEntry(JSONArray metadataArray, JSONArray bitstreamArray) {
BibEntry entry = new BibEntry();
List<Author> authorsList = new ArrayList<>();
List<Author> editorsList = new ArrayList<>();
StringJoiner keywordJoiner = new StringJoiner(", ");

// Get the ISBN within the BITSTREAM. See the link below:
// https://directory.doabooks.org/rest/search?query=handle:%2220.500.12854/26303%22&expand=metadata,bitstreams
// Note that in many cases, an ISBN cannot be obtained in the metadata, even in the BITSTREAM. See the link below:
// https://directory.doabooks.org/rest/search?query=%22i%20open%20fire%22&expand=metadata,bitstreams
for (int i = 0; i < bitstreamArray.length(); i++) {
JSONObject bitstreamObject = bitstreamArray.getJSONObject(i);
// Subcategorise each instance of the BITSTREAM by "metadata" key
JSONArray array = bitstreamObject.getJSONArray("metadata");
for (int k = 0; k < array.length(); k++) {
JSONObject metadataInBitstreamObject = array.getJSONObject(k);
if (metadataInBitstreamObject.getString("key").equals("oapen.relation.isbn")) {
entry.setField(StandardField.ISBN, metadataInBitstreamObject.getString("value"));
}
}
}

for (int i = 0; i < metadataArray.length(); i++) {
JSONObject dataObject = metadataArray.getJSONObject(i);
switch (dataObject.getString("key")) {
Expand Down Expand Up @@ -123,7 +143,7 @@ private BibEntry jsonToBibEntry(JSONArray metadataArray) {
case "dc.contributor.editor" -> editorsList.add(toAuthor(dataObject.getString("value")));
case "oapen.volume" -> entry.setField(StandardField.VOLUME,
dataObject.getString("value"));
case "oapen.relation.isbn" -> entry.setField(StandardField.ISBN,
case "oapen.relation.isbn", "dc.identifier.isbn" -> entry.setField(StandardField.ISBN,
dataObject.getString("value"));
case "dc.title.alternative" -> entry.setField(StandardField.SUBTITLE,
dataObject.getString("value"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static Stream<Arguments> testPerformSearch() {
),
Arguments.of(
new BibEntry(StandardEntryType.Book)
.withField(StandardField.ISBN, "9789085551201")
.withField(StandardField.AUTHOR, "Ronald Snijder")
.withField(StandardField.TITLE, "The deliverance of open access books")
.withField(StandardField.SUBTITLE, "Examining usage and dissemination")
Expand Down

0 comments on commit 5e055a7

Please sign in to comment.