publ-jrn.lua /size: 5868 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
publ-jrn
'
]
=
{
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 9
-- http://jabref.sourceforge.net/journals/journal_abbreviations_general.txt
10
--
11
-- <full name> = <abbreviation> [;shortest unique abbreviation[;frequency]].
12 13
-- require("char-utf")
14 15
-- Abhandlungen aus dem Westfälischen Museum für Naturkunde = Abh. Westfäl. Mus. Nat.kd.
16
-- Abhandlungen der Naturforschenden Gesellschaft in Zürich = Abh. Nat.forsch. Ges. Zür.
17
-- Abhandlungen des Naturwissenschaftlichen Vereins zu Bremen = Abh. Nat.wiss. Ver. Bremen
18 19
local
context
=
context
20
local
commands
=
commands
21 22
local
type
=
type
23
local
find
=
string
.
find
24
local
P
,
C
,
S
,
Cs
,
lpegmatch
,
lpegpatterns
=
lpeg
.
P
,
lpeg
.
C
,
lpeg
.
S
,
lpeg
.
Cs
,
lpeg
.
match
,
lpeg
.
patterns
25 26
local
report_journals
=
logs
.
reporter
(
"
publications
"
,
"
journals
"
)
27 28
local
publications
=
publications
29
local
journals
=
{
}
30
publications
.
journals
=
journals
31 32
local
lowercase
=
characters
.
lower
33 34
local
expansions
=
{
}
35
local
abbreviations
=
{
}
36
local
nofexpansions
=
0
37
local
nofabbreviations
=
0
38 39
local
valid
=
1
-
S
(
[[
."':;,-
]]
)
40
local
pattern
=
Cs
(
(
valid
^
1
+
P
(
1
)
/
"
"
)
^
1
)
41 42
local
function
simplify
(
name
)
43
-- we have utf but it doesn't matter much if we lower the bytes
44
return
name
and
lowercase
(
lpegmatch
(
pattern
,
name
)
)
or
name
45
end
46 47
local
function
add
(
expansion
,
abbreviation
)
48
if
expansion
and
abbreviation
then
49
local
se
=
simplify
(
expansion
)
50
local
sa
=
simplify
(
abbreviation
)
51
if
not
expansions
[
sa
]
then
52
expansions
[
sa
]
=
expansion
53
nofexpansions
=
nofexpansions
+
1
54
end
55
if
not
abbreviations
[
se
]
then
56
abbreviations
[
se
]
=
abbreviation
57
nofabbreviations
=
nofabbreviations
+
1
58
end
59
end
60
end
61 62
-- [#%-] comment
63
-- meaning = abbreviations [;.....]
64 65
local
whitespace
=
lpegpatterns
.
whitespace
^
0
66
local
assignment
=
whitespace
*
P
(
"
=
"
)
*
whitespace
67
local
separator
=
P
(
"
;
"
)
68
local
newline
=
lpegpatterns
.
newline
69
local
endofline
=
lpegpatterns
.
space
^
0
*
(
newline
+
P
(
-1
)
+
separator
)
70
local
restofline
=
(
1
-
newline
)
^
0
71
local
splitter
=
whitespace
*
C
(
(
1
-
assignment
)
^
1
)
*
assignment
*
C
(
(
1
-
endofline
)
^
1
)
*
restofline
72
local
comment
=
S
(
"
#-%
"
)
*
restofline
73
local
pattern
=
(
comment
+
splitter
/
add
)
^
0
74 75
function
journals
.
load
(
filename
)
76
if
not
filename
then
77
return
78
end
-- error
79
if
file
.
suffix
(
filename
,
"
txt
"
)
then
80
local
data
=
io
.
loaddata
(
filename
)
81
if
type
(
data
)
~
=
"
string
"
then
82
return
83
elseif
find
(
data
,
"
=
"
)
then
84
-- expansion = abbreviation
85
lpegmatch
(
pattern
,
data
)
86
end
87
elseif
file
.
suffix
(
filename
,
"
lua
"
)
then
88
local
data
=
table
.
load
(
filename
)
89
if
type
(
data
)
~
=
"
table
"
then
90
return
91
else
92
local
de
=
data
.
expansions
93
local
da
=
data
.
abbreviations
94
if
de
and
da
then
95
-- { expansions = { a = e }, abbreviations = { e = a } }
96
if
next
(
expansions
)
then
97
table
.
merge
(
expansions
,
de
)
98
else
99
expansions
=
de
100
end
101
if
next
(
abbreviations
)
then
102
table
.
merge
(
abbreviations
,
da
)
103
else
104
abbreviations
=
da
105
end
106
elseif
#
data
>
0
then
107
-- { expansion, abbreviation }, ... }
108
for
i
=
1
,
#
data
do
109
local
d
=
d
[
i
]
110
add
(
d
[
1
]
,
d
[
2
]
)
111
end
112
else
113
-- { expansion = abbreviation, ... }
114
for
expansion
,
abbreviation
in
data
do
115
add
(
expansion
,
abbreviation
)
116
end
117
end
118
end
119
end
120
report_journals
(
"
file %a loaded, %s expansions, %s abbreviations
"
,
filename
,
nofexpansions
,
nofabbreviations
)
121
end
122 123
function
journals
.
save
(
filename
)
124
table
.
save
(
filename
,
{
expansions
=
expansions
,
abbreviations
=
abbreviations
}
)
125
end
126 127
function
journals
.
add
(
expansion
,
abbreviation
)
128
add
(
expansion
,
abbreviation
)
129
end
130 131
function
journals
.
expanded
(
name
)
132
local
s
=
simplify
(
name
)
133
return
expansions
[
s
]
or
expansions
[
simplify
(
abbreviations
[
s
]
)
]
or
name
134
end
135 136
function
journals
.
abbreviated
(
name
)
137
local
s
=
simplify
(
name
)
138
return
abbreviations
[
s
]
or
abbreviations
[
simplify
(
expansions
[
s
]
)
]
or
name
139
end
140 141
local
implement
=
interfaces
and
interfaces
.
implement
142 143
if
implement
then
144 145
implement
{
146
name
=
"
btxloadjournallist
"
,
147
arguments
=
"
string
"
,
148
actions
=
journals
.
load
149
}
150 151
implement
{
152
name
=
"
btxsavejournallist
"
,
153
arguments
=
"
string
"
,
154
actions
=
journals
.
save
155
}
156 157
implement
{
158
name
=
"
btxaddjournal
"
,
159
arguments
=
"
2 strings
"
,
160
actions
=
{
journals
.
add
,
context
}
161
}
162 163
implement
{
164
name
=
"
btxexpandedjournal
"
,
165
arguments
=
"
string
"
,
166
actions
=
{
journals
.
expanded
,
context
}
,
167
}
168 169
implement
{
170
name
=
"
btxabbreviatedjournal
"
,
171
arguments
=
"
string
"
,
172
actions
=
{
journals
.
abbreviated
,
context
}
,
173
}
174 175
end
176 177
-- journals.load("e:/tmp/journals.txt")
178
-- journals.save("e:/tmp/journals.lua")
179 180
-- inspect(journals.expanded ("Z. Ökol. Nat.schutz"))
181
-- inspect(journals.abbreviated("Z. Ökol. Nat. schutz"))
182 183
if
typesetters
then
184
typesetters
.
manipulators
.
methods
.
expandedjournal
=
journals
.
expanded
185
typesetters
.
manipulators
.
methods
.
abbreviatedjournal
=
journals
.
abbreviated
186
end
187 188
-- journals.load("t:/manuals/publications-mkiv/journals.txt")
189
-- journals.save("t:/manuals/publications-mkiv/journals.lua")
190