-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathciteparser.js
62 lines (52 loc) · 1.76 KB
/
citeparser.js
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
'use strict';
const {parseRoman}=require("pengine");
/* parse Sutta Central PED citation */
const bookVolPage=(m,book,roman,page)=>{
const v=parseRoman(roman);
book=book.toLowerCase().replace("pts","ps");
const bk=book.indexOf("-")>0?book.replace("-",v):book+v;
//PTS jataka is cs jataka att j6 ==> j6a
return bk+","+page;
}
const bookPage=(m,book,page)=>{
const bk=book.toLowerCase()
.replace("dhs","ds")
.replace("netti","ne")
.replace("tha-ap","thap");
return bk.replace("-","0")+","+page;
}
const bookGroupGatha=(m,book,group,gatha)=>{
return book.toLowerCase()+"_"+(gatha)+"g"+parseRoman(group);
}
const bookVaggaVatthuGatha=(m,book,vagga,vatthu,gatha)=>{
return book.toLowerCase()+parseRoman(vagga)+"."+vatthu+"."+gatha;
}
const patterns=[
[/^(V)in\.([iv]{1,3})\.(\d+)/ , bookVolPage],
[/^([DMSA])N\.([iv]{1,3})\.(\d+)/,bookVolPage],
[/^(Ja)\.([iv]{1,3})\.(\d+)/ , bookVolPage],
[/^(Dhp-a|Pts|Dhp-a)\.([iv]{1,3})\.(\d+)/ ,bookVolPage],
[/^(Dhp-a|Pts|Dhp-a)\.([iv]{1,3})\.(\d+)/ ,bookVolPage],
[/^(Bv)\.([ivx]{1,5})\.(\d+)/ ,bookGroupGatha],
[/^(Vb|Pp|Ud|Mil|Kv|Iti|Mnd|Ne|Netti)\.(\d+)/,bookPage],
[/^(Vv-a|Vb-a|Pv-a|Pp-a|Kv-a|Dhs-a|Snp-a|Tha-ap)\.(\d+)/,bookPage],
//[/^(Pv-a)\.(\d+)/,bookPage],
//[/^(Vb)\.(\d+)/,bookPage],
[/^(Pv|Cp)\.([iv]{1,3})\.(\d+)#(\d+)/,bookVaggaVatthuGatha],
[/^Snp\.(\d+)/,"snp_$1g1"],
[/^Dhp\.(\d+)/,"dhp_$1"],
[/^Vv\.(\d+)#(\d+)/,"vv$1.$2"],
[/^Dhs\.(\d+)/,"ds_$1g3"],
[/^Vism\.(\d+)/,"vism_$1"],
[/^Th([ai])g\.(\d+)/,"th$1g_$2"],
]
const parsePEDCite=cite=>{
for (var i=0;i<patterns.length;i++) {
const pat=patterns[i][0];
const func=patterns[i][1];
const o=cite.replace(pat,func);
if (o!==cite) return o;
}
return cite;
}
module.exports={parsePEDCite};