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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
|
if not modules then modules = { } end modules ['publ-oth'] = {
version = 1.001,
comment = "this module part of publication support",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
local P, S, C, Ct, Cf, Cg, Cmt, Carg = lpeg.P, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cf, lpeg.Cg, lpeg.Cmt, lpeg.Carg
local lpegmatch = lpeg.match
local p_endofline = lpeg.patterns.newline
local loaders = publications.loaders
local getindex = publications.getindex
local function addfield(t,k,v,fields)
k = fields[k]
if k then
local tk = t[k]
if tk then
t[k] = tk .. " and " .. v
else
t[k] = v
end
end
return t
end
local function checkfield(_,_,t,categories,all)
local tag = t.tag
if tag then
local category = t.category
t.tag = nil
t.category = categories[category] or category
all[tag] = t
end
return true
end
-- endnotes --
local fields = {
["@"] = "tag",
["0"] = "category",
["A"] = "author",
["E"] = "editor",
["T"] = "title",
["D"] = "year",
["I"] = "publisher",
}
local categories = {
["Journal Article"] = "article",
}
local entry = P("%") * Cg(C(1) * (S(" \t")^1) * C((1-p_endofline)^0) * Carg(1)) * p_endofline
local record = Cf(Ct("") * (entry^1), addfield)
local records = (Cmt(record * Carg(2) * Carg(3), checkfield) * P(1))^1
function publications.endnotes_to_btx(data)
local all = { }
lpegmatch(records,data,1,fields,categories,all)
return all
end
function loaders.endnote(dataset,filename)
-- we could combine the next into checkfield but let's not create too messy code
loaders.lua(dataset,publications.endnotes_to_btx(io.loaddata(filename) or ""))
end
-- refman --
local entry = Cg(C((1-lpeg.S(" \t")-p_endofline)^1) * (S(" \t-")^1) * C((1-p_endofline)^0) * Carg(1)) * p_endofline
local record = Cf(Ct("") * (entry^1), addfield)
local records = (Cmt(record * Carg(2) * Carg(3), checkfield) * P(1))^1
local fields = {
["SN"] = "tag",
["TY"] = "category",
["A1"] = "author",
["E1"] = "editor",
["T1"] = "title",
["Y1"] = "year",
["PB"] = "publisher",
}
local categories = {
["JOUR"] = "article",
}
function publications.refman_to_btx(data)
local all = { }
lpegmatch(records,data,1,fields,categories,all)
return all
end
function loaders.refman(dataset,filename)
-- we could combine the next into checkfield but let's not create too messy code
loaders.lua(dataset,publications.refman_to_btx(io.loaddata(filename) or ""))
end
-- test --
-- local endnote = [[
-- %0 Journal Article
-- %T Scientific Visualization, Overviews, Methodologies, and Techniques
-- %A Nielson, Gregory M
-- %A Hagen, Hans
-- %A Müller, Heinrich
-- %@ 0818677776
-- %D 1994
-- %I IEEE Computer Society
--
-- %0 Journal Article
-- %T Scientific Visualization, Overviews, Methodologies, and Techniques
-- %A Nielson, Gregory M
-- %A Hagen, Hans
-- %A Müller, Heinrich
-- %@ 0818677775
-- %D 1994
-- %I IEEE Computer Society
-- ]]
--
-- local refman = [[
-- TY - JOUR
-- T1 - Scientific Visualization, Overviews, Methodologies, and Techniques
-- A1 - Nielson, Gregory M
-- A1 - Hagen, Hans
-- A1 - Müller, Heinrich
-- SN - 0818677776
-- Y1 - 1994
-- PB - IEEE Computer Society
--
-- TY - JOUR
-- T1 - Scientific Visualization, Overviews, Methodologies, and Techniques
-- A1 - Nielson, Gregory M
-- A1 - Hagen, Hans
-- A1 - Müller, Heinrich
-- SN - 0818677775
-- Y1 - 1994
-- PB - IEEE Computer Society
-- ]]
--
-- inspect(publications.endnotes_to_btx(endnote))
-- inspect(publications.refman_to_btx(refman))
|