forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First draft. Currently fails, because the CSV files have issues.
- Loading branch information
Showing
4 changed files
with
68 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,67 @@ | ||
package org.jabref.cli; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.DirectoryStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jabref.logic.journals.Abbreviation; | ||
import org.jabref.logic.journals.JournalAbbreviationLoader; | ||
|
||
import org.h2.mvstore.MVMap; | ||
import org.h2.mvstore.MVStore; | ||
import org.jooq.lambda.Unchecked; | ||
|
||
public class JournalListMvGenerator { | ||
|
||
public static void main(String[] args) { | ||
public static void main(String[] args) throws IOException { | ||
Path abbreviationsDirectory = Path.of("buildres", "abbrv.jabref.org", "journals"); | ||
if (!Files.exists(abbreviationsDirectory)) { | ||
System.out.println("Path " + abbreviationsDirectory.toAbsolutePath() + " does not exist"); | ||
System.exit(1); | ||
} | ||
Set<String> ignoredNames = Set.of( | ||
// remove all lists without dot in them: | ||
// we use abbreviation lists containing dots in them only (to be consistent) | ||
"journal_abbreviations_entrez.csv", | ||
"journal_abbreviations_medicus.csv", | ||
"journal_abbreviations_webofscience-dotless.csv", | ||
|
||
// we currently do not have good support for BibTeX strings | ||
"journal_abbreviations_ieee_strings.csv" | ||
); | ||
|
||
Path journalListMvFile = Path.of("build", "resources", "main", "journals"); | ||
Files.deleteIfExists(journalListMvFile); | ||
|
||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(abbreviationsDirectory, "*.csv"); | ||
MVStore store = MVStore.open(journalListMvFile.toString())) { | ||
MVMap<String, Abbreviation> fullToAbbreviation = store.openMap("FullToAbbreviation"); | ||
stream.forEach(Unchecked.consumer(path -> { | ||
String fileName = path.getFileName().toString(); | ||
System.out.print("Checking "); | ||
System.out.print(fileName); | ||
if (ignoredNames.contains(fileName)) { | ||
System.out.println(" ignored"); | ||
} else { | ||
System.out.println("..."); | ||
Collection<Abbreviation> abbreviations = JournalAbbreviationLoader.readAbbreviationsFromCsvFile(path); | ||
Map<String, Abbreviation> abbreviationMap = abbreviations | ||
.stream() | ||
.collect(Collectors.toMap( | ||
Abbreviation::getName, | ||
abbreviation -> abbreviation, | ||
(abbreviation1, abbreviation2) -> { | ||
System.out.println("Double entry " + abbreviation1.getName()); | ||
return abbreviation2; | ||
})); | ||
fullToAbbreviation.putAll(abbreviationMap); | ||
} | ||
})); | ||
} | ||
} | ||
} |
Binary file not shown.