-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
compile_natnumurl.py
154 lines (140 loc) · 5.45 KB
/
compile_natnumurl.py
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
147
148
149
150
151
152
153
154
# Compila el archivo de estilo propio
import copy
import datetime
langs = {
'en': {
'[CHAPTER]': 'ch.~',
'[EDITOR]': ', ed.',
'[EDITORS]': ', eds.',
'[ERROR_BOOKLET]': 'empty title in ',
'[ERROR_EITHER_OR_CHECK_1]': 'can\'t use both ',
'[ERROR_EITHER_OR_CHECK_2]': ' fields in ',
'[ERROR_EMPTY_MISC]': 'all relevant fields are empty in ',
'[ERROR_FORMAT_ARTICLE_CROSSREF_1]': 'need key or journal for ',
'[ERROR_FORMAT_ARTICLE_CROSSREF_2]': ' to crossref ',
'[ERROR_FORMAT_BOOK_CROSSREF_1]': 'empty volume in ',
'[ERROR_FORMAT_BOOK_CROSSREF_2]': ' to crossref ',
'[ERROR_FORMAT_BOOK_CROSSREF_3]': 'need editor, key, or series for ',
'[ERROR_FORMAT_DATE]': 'there\'s a month but no year in ',
'[ERROR_FORMAT_INCOLL_INPROC_CROSSREF_1]': 'need editor, key, or booktitle for ',
'[ERROR_FORMAT_INCOLL_INPROC_CROSSREF_2]': ' to crossref ',
'[ERROR_FORMAT_NUMBER_SERIES]': 'there\'s a number but no series in ',
'[ERROR_OUTPUT_CHECK_1]': 'empty ',
'[ERROR_OUTPUT_CHECK_2]': ' in ',
'[FORMAT_NAMES_F]': '{vv~}{ll}{, jj}{, f.}',
'[FORMAT_NAMES_SEP]': '',
'[FORMAT_NAMES_SEP2]': ',',
'[IN_OBJECT_M]': 'In ',
'[IN_OBJECT]': 'in ',
'[IN]': ' in ',
'[LANG_AND]': ' and ',
'[LANG_ET_AL]': 'et~al.',
'[MSC_THESIS]': 'Master\'s thesis',
'[NO._IN]': 'No.~',
'[NO._MID]': 'no.~',
'[OF]': ' of ',
'[PAGE]': 'p.~',
'[PAGES]': 'pp.~',
'[PHD_THESIS]': 'PhD thesis',
'[TECH_REP]': 'Tech. Rep.',
'[TITLE_F_END_TITLE.P]': ".''",
'[TITLE_F_END_TITLE]': ",''",
'[TITLE_F_START]': '``',
'[VISITED_ON_LAST]': ')',
'[VISITED_ON]': ' (visited on ',
'[VOLUME_M]': 'Vol.~',
'[VOLUME]': 'vol.~'
},
'es': {
'[CHAPTER]': 'cap.~',
'[EDITOR]': ', ed.',
'[EDITORS]': ', eds.',
'[ERROR_BOOKLET]': 'titulo vacio en ',
'[ERROR_EITHER_OR_CHECK_1]': 'no se pueden usar ambos ',
'[ERROR_EITHER_OR_CHECK_2]': ' campos en ',
'[ERROR_EMPTY_MISC]': 'todos los campos relevantes estan vacios en ',
'[ERROR_FORMAT_ARTICLE_CROSSREF_1]': 'se necesita key o journal en ',
'[ERROR_FORMAT_ARTICLE_CROSSREF_2]': ' para validar crossref ',
'[ERROR_FORMAT_BOOK_CROSSREF_1]': 'volumen vacio en ',
'[ERROR_FORMAT_BOOK_CROSSREF_2]': 'para validar crossref ',
'[ERROR_FORMAT_BOOK_CROSSREF_3]': 'se necesita editor, key o series en ',
'[ERROR_FORMAT_DATE]': 'existe mes pero no año en ',
'[ERROR_FORMAT_INCOLL_INPROC_CROSSREF_1]': 'se necesita editor, key o booktitle en ',
'[ERROR_FORMAT_INCOLL_INPROC_CROSSREF_2]': ' para validar crossref ',
'[ERROR_FORMAT_NUMBER_SERIES]': 'existe numero pero no serie en ',
'[ERROR_OUTPUT_CHECK_1]': 'vacio ',
'[ERROR_OUTPUT_CHECK_2]': ' en ',
'[FORMAT_NAMES_F]': '{vv~}{ll}{, jj}{, f.}',
'[FORMAT_NAMES_SEP]': '',
'[FORMAT_NAMES_SEP2]': ',',
'[IN_OBJECT_M]': 'En ',
'[IN_OBJECT]': 'en ',
'[IN]': ' en ',
'[LANG_AND]': ' y ',
'[LANG_ET_AL]': 'et~al.',
'[MSC_THESIS]': 'Tesis M.Sc.',
'[NO._IN]': 'No.~',
'[NO._MID]': 'no.~',
'[OF]': ' de ',
'[PAGE]': 'p.~',
'[PAGES]': 'pp.~',
'[PHD_THESIS]': 'Tesis PhD',
'[TECH_REP]': 'Rep. Tec.',
'[TITLE_F_END_TITLE.P]': "''.",
'[TITLE_F_END_TITLE]': "'',",
'[TITLE_F_START]': '``',
'[VISITED_ON_LAST]': ')',
'[VISITED_ON]': ' (visitado el ',
'[VOLUME_M]': 'Vol.~',
'[VOLUME]': 'vol.~'
}
}
# Genera elsarticle
en_els = langs['en_elsarticle'] = copy.copy(langs['en'])
es_els = langs['es_elsarticle'] = copy.copy(langs['es'])
en_els['[FORMAT_NAMES_F]'] = es_els['[FORMAT_NAMES_F]'] = '{f.~}{vv~}{ll}{, jj}'
en_els['[FORMAT_NAMES_SEP]'] = es_els['[FORMAT_NAMES_SEP]'] = ','
en_els['[FORMAT_NAMES_SEP2]'] = es_els['[FORMAT_NAMES_SEP2]'] = ''
en_els['[LANG_AND]'] = es_els['[LANG_AND]'] = ' '
en_els['[TITLE_F_END_TITLE.P]'] = es_els['[TITLE_F_END_TITLE.P]'] = '.'
en_els['[TITLE_F_END_TITLE]'] = es_els['[TITLE_F_END_TITLE]'] = ','
en_els['[TITLE_F_START]'] = es_els['[TITLE_F_START]'] = ''
en_els['[VISITED_ON_LAST]'] = es_els['[VISITED_ON_LAST]'] = '.'
en_els['[VISITED_ON]'] = '. Accessed '
es_els['[VISITED_ON]'] = '. Visitado el '
# Define formato
def format(lang, outputfile, url, description):
f = open('.natnum_source.bst', 'r', encoding='utf8')
data = f.readlines()
# Chequea la versión
date = datetime.datetime.now()
for w in range(len(data)):
if 'Versión:' in data[w]:
data[w] = data[w].strip()
data[w] += f' ({date.day:02d}/{date.month:02d}/{date.year})\n'
break
# Transforma el texto
data = ''.join(data)
# Elimina urls
if not url:
data = data.replace(' output.links\n new.block\n', '')
# Reemplaza la descripción
data = data.replace('[NATNUM_DESCRIPTION]', description)
# Reemplaza tokens
for token in langs[lang].keys():
data = data.replace(token, langs[lang][token])
f.close()
# Escribe
f = open(outputfile, 'w', encoding='utf8')
for w in data:
f.write(w)
f.close()
# Guarda los formatos
format('es', 'natnumurl.bst', True, 'Archivo de estilos simple numerados + url (doi, arxivId) [es]')
format('es', 'natnum.bst', False, 'Archivo de estilos simple numerados [es]')
format('es_elsarticle', 'elsartnumurl.bst', True, 'Estilo elsarticle numerado + url (doi, arxivId) [es]')
format('es_elsarticle', 'elsartnum.bst', False, 'Estilo elsarticle numerado [es]')
format('en', 'natnumurl_en.bst', True, 'Archivo de estilos simple numerados + url (doi, arxivId) [en]')
format('en', 'natnum_en.bst', False, 'Archivo de estilos simple numerados [en]')
format('en_elsarticle', 'elsartnumurl_en.bst', True, 'Estilo elsarticle numerado + url (doi, arxivId) [en]')
format('en_elsarticle', 'elsartnum_en.bst', False, 'Estilo elsarticle numerado [en]')