forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJournalListMvGenerator.java
More file actions
109 lines (93 loc) · 5.21 KB
/
JournalListMvGenerator.java
File metadata and controls
109 lines (93 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/// usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 24
//RUNTIME_OPTIONS --enable-native-access=ALL-UNNAMED
//DEPS com.h2database:h2:2.2.224
//DEPS org.antlr:antlr4-runtime:4.13.2
//DEPS org.apache.commons:commons-csv:1.14.0
//DEPS info.debatty:java-string-similarity:2.0.0
//DEPS org.jooq:jool:0.9.14
//DEPS org.openjfx:javafx-base:24.0.1
//DEPS org.slf4j:slf4j-api:2.0.13
//DEPS org.slf4j:slf4j-simple:2.0.13
//SOURCES ../../../../jablib/src/main/java/org/jabref/logic/journals/Abbreviation.java
//SOURCES ../../../../jablib/src/main/java/org/jabref/logic/journals/AbbreviationFormat.java
//SOURCES ../../../../jablib/src/main/java/org/jabref/logic/journals/AbbreviationParser.java
//SOURCES ../../../../jablib/src/main/java/org/jabref/logic/journals/JournalAbbreviationLoader.java
//SOURCES ../../../../jablib/src/main/java/org/jabref/logic/journals/JournalAbbreviationPreferences.java
//SOURCES ../../../../jablib/src/main/java/org/jabref/logic/journals/JournalAbbreviationRepository.java
//SOURCES ../../../../jablib/src/main/java/org/jabref/logic/journals/ltwa/LtwaEntry.java
//SOURCES ../../../../jablib/src/main/java/org/jabref/logic/journals/ltwa/LtwaRepository.java
//SOURCES ../../../../jablib/src/main/java/org/jabref/logic/journals/ltwa/NormalizeUtils.java
//SOURCES ../../../../jablib/src/main/java/org/jabref/logic/journals/ltwa/PrefixTree.java
//SOURCES ../../../../jablib/src/main/java/org/jabref/logic/util/strings/StringSimilarity.java
//SOURCES ../../../../jablib/build/generated-src/antlr/main/org/jabref/logic/journals/ltwa/*.java
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/// Has to be started in the root of the repository due to <https://github.com/jbangdev/jbang-gradle-plugin/issues/11>
public class JournalListMvGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(JournalListMvGenerator.class);
public static void main(String[] args) throws IOException {
boolean verbose = (args.length == 1) && ("--verbose".equals(args[0]));
Path abbreviationsDirectory = Path.of("jablib", "src", "main", "abbrv.jabref.org", "journals");
if (!Files.exists(abbreviationsDirectory)) {
System.out.println("Path " + abbreviationsDirectory.toAbsolutePath() + " does not exist");
System.exit(0);
}
// Directory layout aligns to other plugins (e.g., XJF plugin (https://github.com/bjornvester/xjc-gradle-plugin))
Path journalListMvFile = Path.of("jablib", "build", "generated", "resources", "journals", "journal-list.mv");
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"
);
Files.createDirectories(journalListMvFile.getParent());
try (DirectoryStream<Path> stream = Files.newDirectoryStream(abbreviationsDirectory, "*.csv");
MVStore store = new MVStore.Builder().
fileName(journalListMvFile.toString()).
compressHigh().
open()) {
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) -> {
if (verbose) {
System.out.println("Double entry " + abbreviation1.getName());
}
return abbreviation2;
}));
fullToAbbreviation.putAll(abbreviationMap);
}
}));
}
LOGGER.info("Generated journal list at {}", journalListMvFile.toAbsolutePath());
}
}