Skip to content

Commit 05eaec1

Browse files
committed
Paquete reference para funciones de marcado
1 parent 6748fdd commit 05eaec1

File tree

3 files changed

+228
-0
lines changed

3 files changed

+228
-0
lines changed

reference/__init__.py

Whitespace-only changes.

reference/config.py

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
MESSAGES = [
2+
{ 'role': 'system',
3+
'content': 'You are an assistant who distinguishes all the components of a citation in an article with output in JSON'
4+
},
5+
{ 'role': 'user',
6+
'content': 'Bachman, S., J. Moat, A. W. Hill, J. de la Torre and B. Scott. 2011. Supporting Red List threat assessments with GeoCAT: geospatial conservation assessment tool. ZooKeys 150: 117-126. DOI: https://doi.org/10.3897/zookeys.150.2109'
7+
},
8+
{ 'role': 'assistant',
9+
'content': {
10+
'reftype': 'journal',
11+
'authors': [
12+
{ 'surname': 'Bachman', 'fname': 'S.' },
13+
{ 'surname': 'Moat', 'fname': 'J.' },
14+
{ 'surname': 'Hill', 'fname': 'A. W.' },
15+
{ 'surname': 'de la Torre', 'fname': 'J.' },
16+
{ 'surname': 'Scott', 'fname': 'B.' },
17+
],
18+
'date': 2011,
19+
'title': 'Supporting Red List threat assessments with GeoCAT: geospatial conservation assessment tool',
20+
'source': 'ZooKeys',
21+
'vol': '150',
22+
'num': None,
23+
'pages': '117-126',
24+
'doi': '10.3897/zookeys.150.2109',
25+
}
26+
},
27+
{ 'role': 'user',
28+
'content': 'Brunel, J. F. 1987. Sur le genre Phyllanthus L. et quelques genres voisins de la Tribu des Phyllantheae Dumort. (Euphorbiaceae, Phyllantheae) en Afrique intertropicale et à Madagascar. Thèse de doctorat de l’Université L. Pasteur. Strasbourg, France. 760 pp.'
29+
},
30+
{ 'role': 'assistant',
31+
'content': {
32+
'reftype': 'Thesis',
33+
'authors': [
34+
{ 'surname': 'Brunel', 'fname': 'J. F.' },
35+
],
36+
'date': 1987,
37+
'title': 'Sur le genre Phyllanthus L. et quelques genres voisins de la Tribu des Phyllantheae Dumort. (Euphorbiaceae, Phyllantheae) en Afrique intertropicale et à Madagascar',
38+
'degree': 'doctorat',
39+
'organization': 'l’Université L. Pasteur',
40+
'city': 'Strasbourg',
41+
'country': 'France',
42+
'num_pages': 760
43+
},
44+
},
45+
{
46+
'role': 'user',
47+
'content': 'Hernández-López, L. 1995. The endemic flora of Jalisco, Mexico: Centers of endemism and implications for conservation. Tesis de maestría. Universidad de Wisconsin. Madison, USA. 74 pp.'
48+
},
49+
{ 'role': 'assistant',
50+
'content': {
51+
'reftype': 'Thesis',
52+
'authors': [
53+
{ 'surname': 'Hernández-López', 'fname': 'L.' },
54+
],
55+
'date': 1995,
56+
'title': 'The endemic flora of Jalisco, Mexico: Centers of endemism and implications for conservation',
57+
'degree': 'maestría',
58+
'organization': 'Universidad de Wisconsin',
59+
'city': 'Madison',
60+
'country': 'USA',
61+
'num_pages': 74
62+
},
63+
},
64+
{
65+
'role': 'user',
66+
'content': 'Schimper, A. F. W. 1903. Plant geography upon a physiological basis. Clarendon Press. Oxford, UK. 839 pp.'
67+
},
68+
{
69+
'role': 'assistant',
70+
'content': {
71+
'reftype': 'book',
72+
'authors':[
73+
{ 'surname': 'Schimper', 'fname': 'A. F. W.' },
74+
],
75+
'date': 1903,
76+
'title': 'Plant geography upon a physiological basis',
77+
'organization': 'Clarendon Press',
78+
'city': 'Oxford',
79+
'country': 'UK',
80+
'num_pages': 839
81+
}
82+
},
83+
{
84+
'role': 'user',
85+
'content': 'Correa, M. D., C. Galdames and M. Stapf. 2004. Catálogo de Plantas Vasculares de Panamá. Smithsonian Tropical Research Institute. Ciudad de Panamá, Panamá. 599 pp.'
86+
},
87+
{
88+
'role': 'assistant',
89+
'content': {
90+
'reftype': 'book',
91+
'authors':[
92+
{ 'surname': 'Correa', 'fname': 'M. D.' },
93+
{ 'surname': 'Galdames', 'fname': 'C.' },
94+
{ 'surname': 'Stapf', 'fname': 'M.' },
95+
],
96+
'date': 2004,
97+
'title': 'Catálogo de Plantas Vasculares de Panamá',
98+
'organization': 'Smithsonian Tropical Research Institute',
99+
'city': 'Ciudad de Panamá',
100+
'country': 'Panamá',
101+
'num_pages': 599
102+
}
103+
},
104+
{
105+
'role': 'user',
106+
'content': 'Hernández-López, L. 2019. Las especies endémicas de plantas en el estado de Jalisco: su distribución y conservación. Comisión Nacional para el Conocimiento y Uso de la Biodiversidad (CONABIO). Cd. Mx., México. https://doi.org/10.15468/ktvqds (consultado diciembre de 2019).'
107+
},
108+
{
109+
'role': 'assistant',
110+
'content': {
111+
'reftype': 'data',
112+
'authors':[
113+
{ 'surname': 'Hernández-López', 'fname': 'L.' },
114+
],
115+
'date': 2019,
116+
'title': 'Las especies endémicas de plantas en el estado de Jalisco: su distribución y conservación',
117+
'organization': 'Comisión Nacional para el Conocimiento y Uso de la Biodiversidad (CONABIO)',
118+
'city': 'Cd. Mx.',
119+
'country': 'México',
120+
'doi': '10.15468/ktvqds',
121+
'access_date': 'diciembre de 2019'
122+
}
123+
},
124+
{
125+
'role': 'user',
126+
'content': 'INAFED. 2010. Enciclopedia de los Municipios y Delegaciones de México: Jalisco. Instituto Nacional para el Federalismo y el Desarrollo Municipal. http://www.inafed.gob.mx/ work/enciclopedia/EMM21puebla/index.html (consultado diciembre de 2018).'
127+
},
128+
{
129+
'role': 'assistant',
130+
'content': {
131+
'reftype': 'webpage',
132+
'authors':[
133+
{ 'collab': 'INAFED' },
134+
],
135+
'date': 2010,
136+
'title': 'Enciclopedia de los Municipios y Delegaciones de México: Jalisco',
137+
'organization': 'Instituto Nacional para el Federalismo y el Desarrollo Municipal',
138+
'uri': 'http://www.inafed.gob.mx/ work/enciclopedia/EMM21puebla/index.html',
139+
'access_date': 'diciembre de 2018'
140+
}
141+
},
142+
{
143+
'role': 'user',
144+
'content': 'Nikon Corporation. 1991-2006. NIS- Elements, version 2.33. Tokio, Japón.'
145+
},
146+
{
147+
'role': 'assistant',
148+
'content': {
149+
'reftype': 'software',
150+
'authors':[
151+
{ 'collab': 'Nikon Corporation' },
152+
],
153+
'date': 2006,
154+
'source': 'NIS- Elements',
155+
'version': '2.33',
156+
'city': 'Tokio',
157+
'country': 'Japón',
158+
}
159+
},
160+
]
161+
162+
RESPONSE_FORMAT = {
163+
'type': 'json_object',
164+
'schema':{
165+
'type': 'object',
166+
'properties': {
167+
'reftype': {'type': 'string', 'enum': ['journal', 'thesis', 'book', 'data', 'webpage', 'software']},
168+
'authors': {'type': 'array',
169+
'items': {
170+
'type': 'object',
171+
'properties': {
172+
'surname': {'type': 'string'},
173+
'fname': {'type': 'string'},
174+
'collab': {'type': 'string'}
175+
}
176+
}
177+
},
178+
'date': {'type': 'integer'},
179+
'title': {'type': 'string'},
180+
'source': {'type': 'string'},
181+
'vol': {'type': 'integer'},
182+
'num': {'type': 'integer'},
183+
'pages': {'type': 'string'},
184+
'doi': {'type': 'string'},
185+
'degree': {'type': 'string'},
186+
'organization': {'type': 'string'},
187+
'city': {'type': 'string'},
188+
'country': {'type': 'string'},
189+
'num_pages': {'type': 'integer'},
190+
'uri': {'type': 'string'},
191+
'access_date': {'type': 'string'},
192+
'version': {'type': 'string'},
193+
},
194+
'required':{
195+
'journal': ['reftype', 'authors', 'date', 'title', 'source', 'vol', 'num', 'pages', 'doi'],
196+
'thesis': ['reftype', 'authors', 'date', 'title', 'degree', 'organization', 'city', 'country', 'num_pages'],
197+
'book': ['reftype', 'authors', 'date', 'title', 'organization', 'city', 'country', 'num_pages'],
198+
'data': ['reftype', 'authors', 'date', 'title', 'organization', 'city', 'country', 'num_pages', 'doi', 'access_date'],
199+
'webpage': ['reftype', 'authors', 'date', 'title', 'organization', 'uri', 'access_date'],
200+
'software': ['reftype', 'authors', 'date', 'source', 'version', 'city', 'country']
201+
}
202+
}
203+
}

reference/marker.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from llama3.generic_llama import GenericLlama
2+
3+
from reference.config import MESSAGE, RESPONSE_FORMAT
4+
5+
6+
reference_marker = GenericLlama(MESSAGES, RESPONSE_FORMAT)
7+
8+
9+
def mark_reference(reference_text):
10+
output = reference_marker.run(reference_text)
11+
# output['choices'][0]['message']['content']
12+
for item in output["choices"]:
13+
yield item["message"]["content"]
14+
15+
16+
def mark_references(reference_block):
17+
for ref_row in reference_block.split("\n"):
18+
ref_row = ref_row.strip()
19+
if ref_row:
20+
choices = mark_reference(ref_row)
21+
yield {
22+
"reference": ref_row,
23+
"choices": list(choices)
24+
}
25+

0 commit comments

Comments
 (0)