-
-
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.
* Fix #1420 Auto downloader should respect file pattern and propose correct filename * Improve DOI detection #1424 * Add tests * Resolves #1421 Auto downloader should try to retrieve DOI if not present and fetch afterwards * Add external library, document test class * Changelog
- Loading branch information
1 parent
781bbf1
commit 4a6f191
Showing
9 changed files
with
188 additions
and
14 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
86 changes: 86 additions & 0 deletions
86
src/main/java/net/sf/jabref/importer/fetcher/CrossrefFetcherEvaluator.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,86 @@ | ||
package net.sf.jabref.importer.fetcher; | ||
|
||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import net.sf.jabref.Globals; | ||
import net.sf.jabref.JabRefPreferences; | ||
import net.sf.jabref.importer.ParserResult; | ||
import net.sf.jabref.importer.fileformat.BibtexParser; | ||
import net.sf.jabref.logic.util.DOI; | ||
import net.sf.jabref.model.database.BibDatabase; | ||
import net.sf.jabref.model.entry.BibEntry; | ||
|
||
/** | ||
* Useful for checking out new algorithm improvements and thresholds. Not used inside the JabRef code itself. | ||
*/ | ||
public class CrossrefFetcherEvaluator { | ||
public static void main(String[] args) throws IOException, InterruptedException { | ||
Globals.prefs = JabRefPreferences.getInstance(); | ||
|
||
BibtexParser parser = new BibtexParser(new FileReader(args[0])); | ||
ParserResult result = parser.parse(); | ||
BibDatabase db = result.getDatabase(); | ||
|
||
int total = result.getDatabase().getEntryCount(); | ||
|
||
AtomicInteger dois = new AtomicInteger(); | ||
AtomicInteger doiFound = new AtomicInteger(); | ||
AtomicInteger doiNew = new AtomicInteger(); | ||
AtomicInteger doiIdentical = new AtomicInteger(); | ||
|
||
|
||
List<BibEntry> entries = db.getEntries(); | ||
CountDownLatch countDownLatch = new CountDownLatch(entries.size()); | ||
|
||
ExecutorService executorService = Executors.newFixedThreadPool(5); | ||
|
||
for (BibEntry entry : entries) { | ||
executorService.execute(new Runnable() { | ||
|
||
@Override | ||
public void run() { | ||
Optional<DOI> origDOI = DOI.build(entry.getField("doi")); | ||
if (origDOI.isPresent()) { | ||
dois.incrementAndGet(); | ||
Optional<DOI> crossrefDOI = CrossRef.findDOI(entry); | ||
if (crossrefDOI.isPresent()) { | ||
doiFound.incrementAndGet(); | ||
if (origDOI.get().getDOI().equalsIgnoreCase(crossrefDOI.get().getDOI())) { | ||
doiIdentical.incrementAndGet(); | ||
} else { | ||
System.out.println("DOI not identical for : " + entry); | ||
} | ||
} else { | ||
System.out.println("DOI not found for: " + entry); | ||
} | ||
} else { | ||
Optional<DOI> crossrefDOI = CrossRef.findDOI(entry); | ||
if (crossrefDOI.isPresent()) { | ||
System.out.println("New DOI found for: " + entry); | ||
doiNew.incrementAndGet(); | ||
} | ||
} | ||
countDownLatch.countDown(); | ||
} | ||
}); | ||
|
||
} | ||
countDownLatch.await(); | ||
|
||
System.out.println("---------------------------------"); | ||
System.out.println("Total DB size: " + total); | ||
System.out.println("Total DOIs: " + dois); | ||
System.out.println("DOIs found: " + doiFound); | ||
System.out.println("DOIs identical: " + doiIdentical); | ||
System.out.println("New DOIs found: " + doiNew); | ||
|
||
executorService.shutdown(); | ||
} | ||
} |
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