1if not modules then modules = { } end modules ['publ-oth'] = {
2 version = 1.001,
3 comment = "this module part of publication support",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9local P, S, C, Ct, Cf, Cg, Cmt, Carg = lpeg.P, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cf, lpeg.Cg, lpeg.Cmt, lpeg.Carg
10local lpegmatch = lpeg.match
11
12local p_endofline = lpeg.patterns.newline
13
14local publications = publications
15
16local loaders = publications.loaders
17local getindex = publications.getindex
18
19local function addfield(t,k,v,fields)
20 k = fields[k]
21 if k then
22 local tk = t[k]
23 if tk then
24 t[k] = tk .. " and " .. v
25 else
26 t[k] = v
27 end
28 end
29 return t
30end
31
32local function checkfield(_,_,t,categories,all)
33 local tag = t.tag
34 if tag then
35 local category = t.category
36 t.tag = nil
37 t.category = categories[category] or category
38 all[tag] = t
39 end
40 return true
41end
42
43
44
45local fields = {
46 ["@"] = "tag",
47 ["0"] = "category",
48 ["A"] = "author",
49 ["E"] = "editor",
50 ["T"] = "title",
51 ["D"] = "year",
52 ["I"] = "publisher",
53}
54
55local categories = {
56 ["Journal Article"] = "article",
57}
58
59local entry = P("%") * Cg(C(1) * (S(" \t")^1) * C((1-p_endofline)^0) * Carg(1)) * p_endofline
60local record = Cf(Ct("") * (entry^1), addfield)
61local records = (Cmt(record * Carg(2) * Carg(3), checkfield) * P(1))^1
62
63function publications.endnotes_to_btx(data)
64 local all = { }
65 lpegmatch(records,data,1,fields,categories,all)
66 return all
67end
68
69function loaders.endnote(dataset,filename)
70
71 local dataset, fullname = publications.resolvedname(dataset,filename)
72 if fullname then
73 loaders.lua(dataset,publications.endnotes_to_btx(io.loaddata(fullname) or ""))
74 end
75end
76
77
78
79local entry = Cg(C((1-lpeg.S(" \t")-p_endofline)^1) * (S(" \t-")^1) * C((1-p_endofline)^0) * Carg(1)) * p_endofline
80local record = Cf(Ct("") * (entry^1), addfield)
81local records = (Cmt(record * Carg(2) * Carg(3), checkfield) * P(1))^1
82
83local fields = {
84 ["SN"] = "tag",
85 ["TY"] = "category",
86 ["A1"] = "author",
87 ["E1"] = "editor",
88 ["T1"] = "title",
89 ["Y1"] = "year",
90 ["PB"] = "publisher",
91}
92
93local categories = {
94 ["JOUR"] = "article",
95}
96
97function publications.refman_to_btx(data)
98 local all = { }
99 lpegmatch(records,data,1,fields,categories,all)
100 return all
101end
102
103function loaders.refman(dataset,filename)
104
105 local dataset, fullname = publications.resolvedname(dataset,filename)
106 if fullname then
107 loaders.lua(dataset,publications.refman_to_btx(io.loaddata(fullname) or ""))
108 end
109end
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 |