-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathfetch-publications.js
More file actions
194 lines (187 loc) · 7.07 KB
/
Copy pathfetch-publications.js
File metadata and controls
194 lines (187 loc) · 7.07 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import fs from "fs";
let author = "";
const dblpUrl = "https://dblp.org/search/publ/api?h=1000&format=json&q=";
const inputDir = "./content/input";
const inputPubDir = `${inputDir}/publications`;
const pubDir = "./content/publications";
if(process.argv.length === 3){
author = process.argv.slice(-1)[0];
}
else{
console.log(`Append author between quotes as argument.`)
process.exit(2)
}
console.log(`Fetching publications for author ${author}`)
const authorFile = author.toLowerCase().replaceAll(" ", "-");
const authorFilePath = `${inputPubDir}/${authorFile}.json`;
/// Fetch JSON data from DBLP
async function fetchDBLPJSON(author) {
let data = undefined;
if (!fs.existsSync(authorFilePath)) {
const query = dblpUrl + encodeURI(author);
console.log(`Fetching ${authorFilePath} via query ${query}.`);
/// Note: fs-extra supports recursive `mkdir -p`
if (!fs.existsSync(inputDir)) {
fs.mkdirSync(inputDir);
}
if (!fs.existsSync(inputPubDir)) {
fs.mkdirSync(inputPubDir);
}
const response = await fetch(query);
data = await response.json();
console.log("response", response)
if(data.result.status.text !== "OK"){
console.log(`Fetching ${authorFilePath} via query ${query} failed.`);
}
fs.writeFileSync(authorFilePath, JSON.stringify(data, null, 2));
} else {
console.log(`Reading data from ${authorFilePath}.`);
data = fs.readFileSync(authorFilePath, { encoding: "utf8", flag: "r" });
data = JSON.parse(data)
}
return data;
}
const data = await fetchDBLPJSON(author).catch(console.error);
/// Fix author name
function fixAuthorName(author){
/// Remove last word if number
let authorLastWord = author.split(" ").slice(-1)[0];
if(Number.isInteger(Number(authorLastWord))){
author = author.replace(" "+authorLastWord,"")
}
return author;
}
async function parseDBLP(){
/// Parse each hit
if(!data){
console.log(`Failed to fetch data from DBLP.`)
process.exit(2)
}
const nHits = data.result.hits["@total"];
console.log(`Found ${nHits} hits.`);
const hits = data.result.hits.hit;
data.result.hits.hit.forEach(async hit => {
/// Compute first author family name lower case
let authors = hit.info.authors.author;
let firstAuthor = undefined;
if(Array.isArray(authors)){
firstAuthor = authors[0];
}
else{
firstAuthor = authors;
}
firstAuthor = fixAuthorName(firstAuthor.text.toLowerCase());
const firstAuthorFamily = firstAuthor.split(" ").slice(-1)[0];
/// Compute venue identifier for conferences and journals
let venue = hit.info.venue;
if(venue === "CoRR"){
console.log(`Skipping id ${hit["@id"]} with venue ${venue}`)
}
else if(venue !== undefined){
/// Handle edge cases
if(venue.includes("Proc. ACM Hum. Comput. Interact.")){
if(hit.info.number.includes("CSCW")){
venue = "CSCW"
}
else {
venue = "PACMHCI"
}
}
else if(venue.includes("ACM Trans. Comput. Hum. Interact.")){
venue = "TOCHI"
}
else if(venue.includes("ACM Trans. Access. Comput.")){
venue = "TACCESS"
}
else if(venue.includes("EAI Endorsed Trans. Pervasive Health Technol.")){
venue = "PATH"
}
else if(venue.includes("Conference on Designing Interactive Systems")){
venue = "DIS"
}
else if(venue.includes("IEEE Trans. Vis. Comput. Graph.")){
venue = "TVCG"
}
else if(venue.includes("Graphics Interface")){
venue = "GI"
}
else if(venue.includes("CHI Extended Abstracts")){
venue = "CHI EA"
}
/// Remove publishers and stop words
const removeWords = ['ACM','IEEE','Conference on'];
removeWords.forEach(r => {
venue = venue.replaceAll(r+" ","");
})
let venueWords = []
if(venue.includes("@")){
/// Handle workshops
venue = venue.split("@").reverse().join("-")
venueWords = [venue];
}else{
venue = venue.replaceAll("/"," ")
venueWords = venue.split(" ");
}
let venueFile = '';
if(venueWords.length === 1){
/// Handle venue consisting of a single acronym
venueFile = venue.toLowerCase();
}
else{
/// Handle venue consisting of multiple words
venueFile = '';
let acronym = false;
console.log("venueWords",venueWords)
venueWords.forEach(w => {
/// Handle venue starting with acronym
if(acronym===true){
venueFile += "-";
acronym = false;
}
if(w === w.toUpperCase() && !w.endsWith(".")){
venueFile += w.toLowerCase();
acronym = true;
}
else{
/// Append subproceedings
if(w[0].toLowerCase() !== w[0]){
venueFile += w[0].toLowerCase();
}
}
})
}
const pubFileName = `${venueFile}-${hit.info.year}-${firstAuthorFamily}`;
console.log(`Parsing id ${hit["@id"]} as ${pubFileName}`)
/// Test if file exists
const pubFilePath = `${pubDir}/${pubFileName}.yaml`
if (fs.existsSync(pubFilePath)) {
console.log(`Skipping id ${hit["@id"]} as ${pubFilePath} exists`)
}
else{
console.log(`Creating ${pubFilePath} for id ${hit["@id"]}`)
let contents = "";
contents += `date: "${hit.info.year}"\n`
contents += `title: "${hit.info.title}"\n`
contents += `authors: \n`
if(!Array.isArray(authors)){
authors=[authors];
}
authors.forEach(a => {
/// Remove numbers
let author = fixAuthorName(a.text);
contents += ` - ${author}\n`
})
contents += `series: ${venue} ${hit.info.year}\n`
if(hit.info.doi) {contents += `doi: ${hit.info.doi}\n`}
if(hit.info.pages) {contents += `pages: ${hit.info.pages}\n`}
if(hit.info.volume) {contents += `volume: ${hit.info.volume}\n`}
if(hit.info.number) {contents += `number: ${hit.info.number}\n`}
fs.writeFileSync(pubFilePath, contents);
}
}
else{
console.log(`Failed to parse venue for id ${hit["@id"]}`)
}
});
}
await parseDBLP();