Skip to content

Commit

Permalink
feat: implement RIS.toMendeley to convert bibliographic records to
Browse files Browse the repository at this point in the history
Mendeley references
  • Loading branch information
customcommander committed May 6, 2021
1 parent 9f7641c commit 494098f
Show file tree
Hide file tree
Showing 15 changed files with 4,571 additions and 18 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CC=java -jar /devtools/closure-compiler/compiler.jar
src_files=$(shell find src -type f)
dist_files=$(patsubst src/%,dist/%,$(src_files)) dist/browser.min.js

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

resources/all.ris: resources/all.jq resources/all.json
jq -M -S -r -f $^ > $@

resources/fields-map.csv: resources/fields-map.jq src/fields-map.json
jq -M -S -r -f $^ > $@

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

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

dist/%: src/%
mkdir -p $(@D)
Expand Down
116 changes: 116 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,122 @@ See the complete [map for each type of RIS reference](./resources/fields-map.csv

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

## Mendeley

Bibliographic records in RIS format can be converted to Mendeley references:

```javascript
RIS.toMendeley(`
TY - JOUR
TI - Mission to the Moon
AU - Armstrong, Neil
DA - 1969/07/20
ER -
`);
//=> [{ type: 'journal'
//=> , authors: [{last_name: 'Armstrong', first_name: 'Neil'}]
//=> , accessed: '1969-07-20'
//=> , title: 'Mission to the Moon' }]
```

**Warning:** not all RIS fields can be mapped to a Mendeley fields. The following tables show which RIS fields are supported by Mendeley.

**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.,


```javascript
RIS.toMendeley(`
TY - JOUR
AU - Armstrong, Neil
DA - 1969/07/20
ER -
`);
//=> []
// In Mendeley all references MUST have a title!
```

### All Records

| RIS | Mendeley |
|:----|:-----------------|
| A1 | authors |
| A2 | editors |
| A3 | authors |
| A4 | authors |
| AB | abstract |
| AN | identifiers.pmid |
| AU | authors |
| CY | city |
| DA | accessed |
| DO | identifiers.doi |
| ET | edition |
| IS | issue |
| KW | keywords |
| L1 | websites |
| L4 | websites |
| LA | language |
| LB | tags |
| N1 | notes |
| PB | publisher |
| PY | year |
| RN | notes |
| SE | chapter |
| SN | identifiers.isbn |
| SP | pages |
| ST | short_title |
| T2 | source |
| T3 | series |
| TA | authors |
| TI | title |
| UR | websites |
| VL | volume |

### PAT Records

| RIS | Mendeley |
|:----|:--------------------------|
| C6 | patent_legal_status |
| M1 | patent_application_number |

### JOUR & JFULL Records

| RIS | Mendeley |
|:----|:-----------------|
| SN | identifiers.issn |

### RPRT Records

| RIS | Mendeley |
|:----|:-----------------|
| VL | series_number |

### Types Conversion

| RIS | Mendeley |
|:----------|:-----------------------|
| BILL | bill |
| BOOK | book |
| CASE | case |
| CHAP | book_section |
| COMP | computer_program |
| CONF | conference_proceedings |
| ENCYC | encyclopedia_article |
| GEN | generic |
| HEAR | hearing |
| ICOMM | web_page |
| JFULL | journal |
| JOUR | journal |
| MGZN | magazine_article |
| MPCT | film |
| NEWS | newspaper_article |
| PAT | patent |
| RPRT | report |
| STAT | statute |
| THES | thesis |
| UNPB | working_paper |
| *Others* | generic |


## Development

The following command will:
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"academia",
"bibliography",
"citation",
"mendeley",
"reference-manager",
"ris-format"
],
Expand All @@ -39,6 +40,8 @@
"access": "public"
},
"dependencies": {
"ajv": "^8.1.0",
"ajv-formats": "^2.0.2",
"moo": "^0.5.1",
"nearley": "^2.20.1"
}
Expand Down
19 changes: 19 additions & 0 deletions resources/all.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Some RIS fields have specific formatting rules.
# Default is to set the field value to the field name
def generate_value:
if . == "A1" or . == "A2" or . == "A3" or . == "A4" or . == "AU" or . == "TA" then
"\(.)Doe, \(.)John"
elif . == "PY" then
"1666"
elif . == "DA" then
"1969/07/20"
elif . == "RP" then
"IN FILE"
else
.
end;

.fields as $f
| .types[]
| ["TY - \(.)"] + ($f | map("\(.) - \(. | generate_value)")) + ["ER - \n"]
| join("\n")
121 changes: 121 additions & 0 deletions resources/all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"//1": "Used to generate a .ris file with all types and fields to see how different reference managers handle RIS records",
"//2": "The original list of types and fields comes from https://web.archive.org/web/20120526103719/http://refman.com/support/risformat_intro.asp",
"//3": "However some database providers have defined other fields. These can be included here too.",
"types": [
"ABST",
"ADVS",
"AGGR",
"ANCIENT",
"ART",
"BILL",
"BLOG",
"BOOK",
"CASE",
"CHAP",
"CHART",
"CLSWK",
"COMP",
"CONF",
"CPAPER",
"CTLG",
"DATA",
"DBASE",
"DICT",
"EBOOK",
"ECHAP",
"EDBOOK",
"EJOUR",
"ELEC",
"ENCYC",
"EQUA",
"FIGURE",
"GEN",
"GOVDOC",
"GRANT",
"HEAR",
"ICOMM",
"INPR",
"JFULL",
"JOUR",
"LEGAL",
"MANSCPT",
"MAP",
"MGZN",
"MPCT",
"MULTI",
"MUSIC",
"NEWS",
"PAMP",
"PAT",
"PCOMM",
"RPRT",
"SER",
"SLIDE",
"SOUND",
"STAND",
"STAT",
"THES",
"UNBILL",
"UNPB",
"VIDEO"
],
"fields": [
"A1",
"A2",
"A3",
"A4",
"AB",
"AD",
"AN",
"AU",
"C1",
"C2",
"C3",
"C4",
"C5",
"C6",
"C7",
"C8",
"CA",
"CN",
"CT",
"CY",
"DA",
"DB",
"DO",
"DP",
"ET",
"IS",
"J2",
"KW",
"L1",
"L4",
"LA",
"LB",
"M1",
"M2",
"M3",
"N1",
"NV",
"OP",
"PB",
"PY",
"RI",
"RN",
"RP",
"SE",
"SN",
"SP",
"ST",
"SV",
"T2",
"T3",
"TA",
"TI",
"TT",
"UR",
"VL",
"Y2"
]
}
Loading

0 comments on commit 494098f

Please sign in to comment.