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

Add Library of Congress as ID-fetcher #2865

Merged
merged 3 commits into from
May 24, 2017
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Removed the hidden feature that a double click in the editor inserted the current date.
- All authors and editors are separated using semicolons when exporting to csv. [#2762](https://github.com/JabRef/jabref/issues/2762)
- Improved wording of "Show recommendations: into "Show 'Related Articles' tab" in the preferences
- We added integration of the Library of Congress catalog as a fetcher based on the [LCCN identifier](https://en.wikipedia.org/wiki/Library_of_Congress_Control_Number). [Feature request 636 in the forum](http://discourse.jabref.org/t/loc-marc-mods-connection/636)

### Fixed
- We fixed the IEEE Xplore web search functionality [#2789](https://github.com/JabRef/jabref/issues/2789)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/logic/importer/WebFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.jabref.logic.importer.fetcher.GoogleScholar;
import org.jabref.logic.importer.fetcher.GvkFetcher;
import org.jabref.logic.importer.fetcher.IsbnFetcher;
import org.jabref.logic.importer.fetcher.LibraryOfCongress;
import org.jabref.logic.importer.fetcher.MathSciNet;
import org.jabref.logic.importer.fetcher.MedlineFetcher;
import org.jabref.logic.importer.fetcher.TitleFetcher;
Expand Down Expand Up @@ -88,6 +89,7 @@ public static List<IdBasedFetcher> getIdBasedFetchers(ImportFormatPreferences im
list.add(new TitleFetcher(importFormatPreferences));
list.add(new MathSciNet(importFormatPreferences));
list.add(new CrossRef());
list.add(new LibraryOfCongress());
list.sort(Comparator.comparing(WebFetcher::getName));
return list;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jabref.logic.importer.fetcher;

import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;

import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.IdBasedParserFetcher;
import org.jabref.logic.importer.Parser;
import org.jabref.logic.importer.fileformat.ModsImporter;

import org.apache.http.client.utils.URIBuilder;

/**
* Fetcher for the Library of Congress Control Number (LCCN) using https://lccn.loc.gov/
*/
public class LibraryOfCongress implements IdBasedParserFetcher {

@Override
public String getName() {
return "Library of Congress";
}

@Override
public URL getURLForID(String identifier) throws URISyntaxException, MalformedURLException, FetcherException {
URIBuilder uriBuilder = new URIBuilder("https://lccn.loc.gov/" + identifier + "/mods");
return uriBuilder.build().toURL();
}

@Override
public Parser getParser() {
return new ModsImporter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -17,6 +21,8 @@
import javax.xml.bind.Unmarshaller;

import org.jabref.logic.importer.Importer;
import org.jabref.logic.importer.ParseException;
import org.jabref.logic.importer.Parser;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fileformat.mods.AbstractDefinition;
import org.jabref.logic.importer.fileformat.mods.DateDefinition;
Expand Down Expand Up @@ -61,7 +67,7 @@
* More details about the format can be found here <a href="http://www.loc.gov/standards/mods/">http://www.loc.gov/standards/mods/</a>. <br>
* The newest xml schema can also be found here <a href="www.loc.gov/standards/mods/mods-schemas.html.">www.loc.gov/standards/mods/mods-schemas.html.</a>.
*/
public class ModsImporter extends Importer {
public class ModsImporter extends Importer implements Parser {

private static final Log LOGGER = LogFactory.getLog(ModsImporter.class);
private static final String KEYWORD_SEPARATOR = JabRefPreferences.getInstance().getImportFormatPreferences()
Expand Down Expand Up @@ -476,4 +482,13 @@ public String getDescription() {
return "Importer for the MODS format";
}

@Override
public List<BibEntry> parseEntries(InputStream inputStream) throws ParseException {
try {
return importDatabase(new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))).getDatabase().getEntries();
} catch (IOException e) {
LOGGER.error(e.getLocalizedMessage(), e);
}
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jabref.logic.importer.fetcher;

import java.util.Optional;

import org.jabref.model.entry.BibEntry;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class LibraryOfCongressTest {

private LibraryOfCongress fetcher = new LibraryOfCongress();

@Test
public void performSearchById() throws Exception {
BibEntry expected = new BibEntry();
expected.setField("address", "Burlington, MA");
expected.setField("author", "West, Matthew");
expected.setField("isbn", "0123751063 (pbk.)");
expected.setField("issuance", "monographic");
expected.setField("keywords", "Database design, Data structures (Computer science)");
expected.setField("language", "eng");
expected.setField("lccn", "2010045158");
expected.setField("note", "Matthew West., Includes index.");
expected.setField("oclc", "ocn665135773");
expected.setField("publisher", "Morgan Kaufmann");
expected.setField("source", "DLC");
expected.setField("title", "Developing high quality data models");
expected.setField("year", "2011");

assertEquals(Optional.of(expected), fetcher.performSearchById("2010045158"));
}
}