-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor search based fetcher based on website and parser * Refactor BibtexParser * Refactor cleanup preferences * Add search-based fetcher for the Astrophysics Data System * Introduce EntryBasedFetcher * Add ADS as EntyBasedFetcher * Add comment about new ADS API * Add MathSciNet entry based fetcher * Add MathSciNet search fetcher * Add zbMath fetcher * Add Changelog * Remove header * Remove more headers * Include feedback * Rename GVKParser * Remove big * Remove unused imports * Fix failing GVK tests * Fix failing tests due to no subscription
- Loading branch information
1 parent
2f73d74
commit 3bd3f6c
Showing
40 changed files
with
974 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/net/sf/jabref/logic/cleanup/CleanupPreferences.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.sf.jabref.logic.cleanup; | ||
|
||
import net.sf.jabref.FileDirectoryPreferences; | ||
import net.sf.jabref.logic.layout.LayoutFormatterPreferences; | ||
|
||
public class CleanupPreferences { | ||
|
||
private final String fileNamePattern; | ||
private final LayoutFormatterPreferences layoutFormatterPreferences; | ||
private final FileDirectoryPreferences fileDirectoryPreferences; | ||
|
||
public CleanupPreferences(String fileNamePattern, LayoutFormatterPreferences layoutFormatterPreferences, | ||
FileDirectoryPreferences fileDirectoryPreferences) { | ||
this.fileNamePattern = fileNamePattern; | ||
this.layoutFormatterPreferences = layoutFormatterPreferences; | ||
this.fileDirectoryPreferences = fileDirectoryPreferences; | ||
} | ||
|
||
public String getFileNamePattern() { | ||
return fileNamePattern; | ||
} | ||
|
||
public LayoutFormatterPreferences getLayoutFormatterPreferences() { | ||
return layoutFormatterPreferences; | ||
} | ||
|
||
public FileDirectoryPreferences getFileDirectoryPreferences() { | ||
return fileDirectoryPreferences; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/net/sf/jabref/logic/cleanup/MoveFieldCleanup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package net.sf.jabref.logic.cleanup; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import net.sf.jabref.logic.util.OptionalUtil; | ||
import net.sf.jabref.model.FieldChange; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* Moves the content of one field to another field. | ||
*/ | ||
public class MoveFieldCleanup implements CleanupJob { | ||
|
||
private String sourceField; | ||
private String targetField; | ||
|
||
public MoveFieldCleanup(String sourceField, String targetField) { | ||
this.sourceField = sourceField; | ||
this.targetField = targetField; | ||
} | ||
|
||
@Override | ||
public List<FieldChange> cleanup(BibEntry entry) { | ||
|
||
Optional<FieldChange> setFieldChange = entry.getField(sourceField).flatMap( | ||
value -> entry.setField(targetField, value)); | ||
Optional<FieldChange> clearFieldChange = entry.clearField(sourceField); | ||
return OptionalUtil.toList(setFieldChange, clearFieldChange); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/net/sf/jabref/logic/importer/EntryBasedFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.sf.jabref.logic.importer; | ||
|
||
import java.util.List; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* Searches web resources for bibliographic information based on a {@link BibEntry}. | ||
* Useful to complete an existing entry with fetched information. | ||
* May return multiple search hits. | ||
*/ | ||
public interface EntryBasedFetcher extends WebFetcher { | ||
|
||
/** | ||
* Looks for hits which are matched by the given {@link BibEntry}. | ||
* | ||
* @param entry entry to search bibliographic information for | ||
* @return a list of {@link BibEntry}, which are matched by the query (may be empty) | ||
*/ | ||
List<BibEntry> performSearch(BibEntry entry) throws FetcherException; | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/net/sf/jabref/logic/importer/EntryBasedParserFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package net.sf.jabref.logic.importer; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import net.sf.jabref.logic.formatter.Formatter; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* Provides a convenient interface for entry-based fetcher, which follow the usual three-step procedure: | ||
* 1. Open a URL based on the entry | ||
* 2. Parse the response to get a list of {@link BibEntry} | ||
* 3. Post-process fetched entries | ||
*/ | ||
public interface EntryBasedParserFetcher extends EntryBasedFetcher { | ||
|
||
/** | ||
* Constructs a URL based on the {@link BibEntry}. | ||
* @param entry the entry to look information for | ||
*/ | ||
URL getURLForEntry(BibEntry entry) throws URISyntaxException, MalformedURLException, FetcherException; | ||
|
||
/** | ||
* Returns the parser used to convert the response to a list of {@link BibEntry}. | ||
*/ | ||
Parser getParser(); | ||
|
||
/** | ||
* Performs a cleanup of the fetched entry. | ||
* | ||
* Only systematic errors of the fetcher should be corrected here | ||
* (i.e. if information is consistently contained in the wrong field or the wrong format) | ||
* but not cosmetic issues which may depend on the user's taste (for example, LateX code vs HTML in the abstract). | ||
* | ||
* Try to reuse existing {@link Formatter} for the cleanup. For example, | ||
* {@code new FieldFormatterCleanup(FieldName.TITLE, new RemoveBracesFormatter()).cleanup(entry);} | ||
* | ||
* By default, no cleanup is done. | ||
* @param entry the entry to be cleaned-up | ||
*/ | ||
default void doPostCleanup(BibEntry entry) { | ||
// Do nothing by default | ||
} | ||
|
||
@Override | ||
default List<BibEntry> performSearch(BibEntry entry) throws FetcherException { | ||
Objects.requireNonNull(entry); | ||
|
||
try (InputStream stream = new BufferedInputStream(getURLForEntry(entry).openStream())) { | ||
List<BibEntry> fetchedEntries = getParser().parseEntries(stream); | ||
|
||
// Post-cleanup | ||
fetchedEntries.forEach(this::doPostCleanup); | ||
|
||
return fetchedEntries; | ||
} catch (URISyntaxException e) { | ||
throw new FetcherException("Search URI is malformed", e); | ||
} catch (IOException e) { | ||
// TODO: Catch HTTP Response 401 errors and report that user has no rights to access resource | ||
throw new FetcherException("An I/O exception occurred", e); | ||
} catch (ParserException e) { | ||
throw new FetcherException("An internal parser error occurred", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package net.sf.jabref.logic.importer; | ||
|
||
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* A parser converts an {@link InputStream} into a list of {@link BibEntry}. | ||
*/ | ||
public interface Parser { | ||
|
||
List<BibEntry> parseEntries(InputStream inputStream) throws ParserException; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/net/sf/jabref/logic/importer/ParserException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package net.sf.jabref.logic.importer; | ||
|
||
public class ParserException extends Exception { | ||
|
||
|
||
public ParserException(String errorMessage, Exception cause) { | ||
super(errorMessage, cause); | ||
} | ||
|
||
public ParserException(String errorMessage) { | ||
super(errorMessage); | ||
} | ||
|
||
public ParserException(Exception cause) { | ||
super(cause); | ||
} | ||
} |
Oops, something went wrong.