Skip to content

Commit 494098f

Browse files
feat: implement RIS.toMendeley to convert bibliographic records to
Mendeley references
1 parent 9f7641c commit 494098f

File tree

15 files changed

+4571
-18
lines changed

15 files changed

+4571
-18
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
CC=java -jar /devtools/closure-compiler/compiler.jar
21
src_files=$(shell find src -type f)
32
dist_files=$(patsubst src/%,dist/%,$(src_files)) dist/browser.min.js
43

@@ -13,6 +12,9 @@ parse: src/grammar.js
1312
src/grammar.js: src/grammar.ne src/lexer.js
1413
yarn -s nearleyc $< > $@
1514

15+
resources/all.ris: resources/all.jq resources/all.json
16+
jq -M -S -r -f $^ > $@
17+
1618
resources/fields-map.csv: resources/fields-map.jq src/fields-map.json
1719
jq -M -S -r -f $^ > $@
1820

@@ -34,8 +36,7 @@ dist: $(dist_files) dist/browser.min.js
3436

3537
dist/browser.min.js: $(src_files)
3638
mkdir -p $(@D)
37-
yarn -s browserify --standalone RIS src/index.js > /tmp/ris.js
38-
$(CC) --js /tmp/ris.js --language_in ECMASCRIPT_NEXT --language_out ECMASCRIPT5_STRICT > $@
39+
yarn -s browserify --standalone RIS src/index.js >$@
3940

4041
dist/%: src/%
4142
mkdir -p $(@D)

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,122 @@ See the complete [map for each type of RIS reference](./resources/fields-map.csv
7979

8080
See [list of reference types](./resources/types.csv). Based on https://en.wikipedia.org/wiki/RIS_(file_format).
8181

82+
## Mendeley
83+
84+
Bibliographic records in RIS format can be converted to Mendeley references:
85+
86+
```javascript
87+
RIS.toMendeley(`
88+
TY - JOUR
89+
TI - Mission to the Moon
90+
AU - Armstrong, Neil
91+
DA - 1969/07/20
92+
ER -
93+
`);
94+
//=> [{ type: 'journal'
95+
//=> , authors: [{last_name: 'Armstrong', first_name: 'Neil'}]
96+
//=> , accessed: '1969-07-20'
97+
//=> , title: 'Mission to the Moon' }]
98+
```
99+
100+
**Warning:** not all RIS fields can be mapped to a Mendeley fields. The following tables show which RIS fields are supported by Mendeley.
101+
102+
**Warning:** each Mendeley references is validated before it is returned. If one field in the reference is invalid the _entire_ reference is discarded. e.g.,
103+
104+
105+
```javascript
106+
RIS.toMendeley(`
107+
TY - JOUR
108+
AU - Armstrong, Neil
109+
DA - 1969/07/20
110+
ER -
111+
`);
112+
//=> []
113+
// In Mendeley all references MUST have a title!
114+
```
115+
116+
### All Records
117+
118+
| RIS | Mendeley |
119+
|:----|:-----------------|
120+
| A1 | authors |
121+
| A2 | editors |
122+
| A3 | authors |
123+
| A4 | authors |
124+
| AB | abstract |
125+
| AN | identifiers.pmid |
126+
| AU | authors |
127+
| CY | city |
128+
| DA | accessed |
129+
| DO | identifiers.doi |
130+
| ET | edition |
131+
| IS | issue |
132+
| KW | keywords |
133+
| L1 | websites |
134+
| L4 | websites |
135+
| LA | language |
136+
| LB | tags |
137+
| N1 | notes |
138+
| PB | publisher |
139+
| PY | year |
140+
| RN | notes |
141+
| SE | chapter |
142+
| SN | identifiers.isbn |
143+
| SP | pages |
144+
| ST | short_title |
145+
| T2 | source |
146+
| T3 | series |
147+
| TA | authors |
148+
| TI | title |
149+
| UR | websites |
150+
| VL | volume |
151+
152+
### PAT Records
153+
154+
| RIS | Mendeley |
155+
|:----|:--------------------------|
156+
| C6 | patent_legal_status |
157+
| M1 | patent_application_number |
158+
159+
### JOUR & JFULL Records
160+
161+
| RIS | Mendeley |
162+
|:----|:-----------------|
163+
| SN | identifiers.issn |
164+
165+
### RPRT Records
166+
167+
| RIS | Mendeley |
168+
|:----|:-----------------|
169+
| VL | series_number |
170+
171+
### Types Conversion
172+
173+
| RIS | Mendeley |
174+
|:----------|:-----------------------|
175+
| BILL | bill |
176+
| BOOK | book |
177+
| CASE | case |
178+
| CHAP | book_section |
179+
| COMP | computer_program |
180+
| CONF | conference_proceedings |
181+
| ENCYC | encyclopedia_article |
182+
| GEN | generic |
183+
| HEAR | hearing |
184+
| ICOMM | web_page |
185+
| JFULL | journal |
186+
| JOUR | journal |
187+
| MGZN | magazine_article |
188+
| MPCT | film |
189+
| NEWS | newspaper_article |
190+
| PAT | patent |
191+
| RPRT | report |
192+
| STAT | statute |
193+
| THES | thesis |
194+
| UNPB | working_paper |
195+
| *Others* | generic |
196+
197+
82198
## Development
83199

84200
The following command will:

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"academia",
2222
"bibliography",
2323
"citation",
24+
"mendeley",
2425
"reference-manager",
2526
"ris-format"
2627
],
@@ -39,6 +40,8 @@
3940
"access": "public"
4041
},
4142
"dependencies": {
43+
"ajv": "^8.1.0",
44+
"ajv-formats": "^2.0.2",
4245
"moo": "^0.5.1",
4346
"nearley": "^2.20.1"
4447
}

resources/all.jq

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Some RIS fields have specific formatting rules.
2+
# Default is to set the field value to the field name
3+
def generate_value:
4+
if . == "A1" or . == "A2" or . == "A3" or . == "A4" or . == "AU" or . == "TA" then
5+
"\(.)Doe, \(.)John"
6+
elif . == "PY" then
7+
"1666"
8+
elif . == "DA" then
9+
"1969/07/20"
10+
elif . == "RP" then
11+
"IN FILE"
12+
else
13+
.
14+
end;
15+
16+
.fields as $f
17+
| .types[]
18+
| ["TY - \(.)"] + ($f | map("\(.) - \(. | generate_value)")) + ["ER - \n"]
19+
| join("\n")

resources/all.json

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"//1": "Used to generate a .ris file with all types and fields to see how different reference managers handle RIS records",
3+
"//2": "The original list of types and fields comes from https://web.archive.org/web/20120526103719/http://refman.com/support/risformat_intro.asp",
4+
"//3": "However some database providers have defined other fields. These can be included here too.",
5+
"types": [
6+
"ABST",
7+
"ADVS",
8+
"AGGR",
9+
"ANCIENT",
10+
"ART",
11+
"BILL",
12+
"BLOG",
13+
"BOOK",
14+
"CASE",
15+
"CHAP",
16+
"CHART",
17+
"CLSWK",
18+
"COMP",
19+
"CONF",
20+
"CPAPER",
21+
"CTLG",
22+
"DATA",
23+
"DBASE",
24+
"DICT",
25+
"EBOOK",
26+
"ECHAP",
27+
"EDBOOK",
28+
"EJOUR",
29+
"ELEC",
30+
"ENCYC",
31+
"EQUA",
32+
"FIGURE",
33+
"GEN",
34+
"GOVDOC",
35+
"GRANT",
36+
"HEAR",
37+
"ICOMM",
38+
"INPR",
39+
"JFULL",
40+
"JOUR",
41+
"LEGAL",
42+
"MANSCPT",
43+
"MAP",
44+
"MGZN",
45+
"MPCT",
46+
"MULTI",
47+
"MUSIC",
48+
"NEWS",
49+
"PAMP",
50+
"PAT",
51+
"PCOMM",
52+
"RPRT",
53+
"SER",
54+
"SLIDE",
55+
"SOUND",
56+
"STAND",
57+
"STAT",
58+
"THES",
59+
"UNBILL",
60+
"UNPB",
61+
"VIDEO"
62+
],
63+
"fields": [
64+
"A1",
65+
"A2",
66+
"A3",
67+
"A4",
68+
"AB",
69+
"AD",
70+
"AN",
71+
"AU",
72+
"C1",
73+
"C2",
74+
"C3",
75+
"C4",
76+
"C5",
77+
"C6",
78+
"C7",
79+
"C8",
80+
"CA",
81+
"CN",
82+
"CT",
83+
"CY",
84+
"DA",
85+
"DB",
86+
"DO",
87+
"DP",
88+
"ET",
89+
"IS",
90+
"J2",
91+
"KW",
92+
"L1",
93+
"L4",
94+
"LA",
95+
"LB",
96+
"M1",
97+
"M2",
98+
"M3",
99+
"N1",
100+
"NV",
101+
"OP",
102+
"PB",
103+
"PY",
104+
"RI",
105+
"RN",
106+
"RP",
107+
"SE",
108+
"SN",
109+
"SP",
110+
"ST",
111+
"SV",
112+
"T2",
113+
"T3",
114+
"TA",
115+
"TI",
116+
"TT",
117+
"UR",
118+
"VL",
119+
"Y2"
120+
]
121+
}

0 commit comments

Comments
 (0)