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