1 /******************************************************************/
2 /* Copyright (C) 2000, HELM Team */
4 /* This file is part of HELM, an Hypertextual, Electronic */
5 /* Library of Mathematics, developed at the Computer Science */
6 /* Department, University of Bologna, Italy. */
8 /* HELM is free software; you can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation; either version */
11 /* 2 of the License, or (at your option) any later version. */
13 /* HELM is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU General Public License for more details. */
18 /* You should have received a copy of the GNU General Public */
19 /* License along with HELM; if not, write to the Free Software */
20 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, */
21 /* MA 02111-1307, USA. */
23 /* For details, see the HELM World-Wide-Web page, */
24 /* http://cs.unibo.it/helm/. */
25 /******************************************************************/
27 /***************************************************************/
29 /* Automatic Metadata Extractor */
30 /* First draft 11/12/2001, by Andrea Asperti */
31 /* more bugs added by domenico lordi on mon 12/17/2001 */
32 /***************************************************************/
34 /***************************************************************/
35 /* 1. Inclusion of header files. */
36 /***************************************************************/
42 #include "sthandler.h"
45 /***************************************************************/
46 /* 2. Constants and Variables Definitions */
47 /***************************************************************/
53 #define MUTCONSTRUCT 3
70 int position = INBODY;
71 int first_child = HERE;
72 int skip = 0; // boolean to skip the insertion of a URI
73 int no_open_source =0;
78 char *xpointer = "#xpointer(1/";
83 /***************************************************************/
84 /* 3. Regular definitions. */
85 /***************************************************************/
91 /***************************************************************/
93 /***************************************************************/
98 "<Variable"[^>]*">"(" "|\n)*"<body" {
99 position = INBODY; // Variables have both a body and a type
102 "</body>"(" "|\n)*"<type" {
103 position = INTYPE; // Variables have both a body and a type
108 if (position == INTYPE)
110 else if (position == MAINHYP)
117 if (position == INHYP)
120 if (no_open_source == 0)
127 else if (position == MAINHYP)
148 if (((position == INTYPE) | (position == MAINHYP)) &&
149 (first_child == HERE))
151 if (position == INTYPE) /* REL on the spine */
154 search("Rel",first_child,position,spine_depth);
156 else search("Rel",first_child,position,depth);
161 "<SORT"(" "|\n)+"value=\""{value} {
162 if (((position == INTYPE) | (position == MAINHYP)) &&
163 (first_child == HERE))
165 tmp=(char *)malloc((sizeof('a')*200));
168 if (position == INTYPE) /* SORT on the spine */
171 search(tmp,first_child,position,spine_depth);
173 else search(tmp,first_child,position,depth);
184 if (position == INTYPE) /* CONST on the spine */
190 if (position == INTYPE) /* MUTIND on the spine */
196 if (position == INTYPE) /* MUTCONSTRUCT on the spine */
198 where = MUTCONSTRUCT;
203 uri=(char *)malloc((sizeof('a')*200));
208 if (position == INCONCL)
209 search(uri,first_child,position,spine_depth);
210 else search(uri,first_child,position,depth);
218 "noType=\""{digits} {
219 if ((where == MUTIND) || (where == MUTCONSTRUCT))
220 { strsep(&yytext,&sep);
221 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
224 sprintf(tmp,"%d",tmp_n);
225 strcat(uri,"#xpointer(1/");
231 if (position == INCONCL)
232 search(uri,first_child,position,spine_depth);
233 else search(uri,first_child,position,depth);
237 first_child = AFTER;};
240 "noConstr=\""{digits} {
241 if (where == MUTCONSTRUCT)
242 { strsep(&yytext,&sep);
243 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
248 if (position == INCONCL)
249 search(uri,first_child,position,spine_depth);
250 else search(uri,first_child,position,depth);
254 first_child = AFTER;};
261 /***************************************************************/
262 /* 6. Auxiliary functions. */
263 /***************************************************************/
265 main(int argc, char *argv[])
268 FILE *outrel, *outsort;
271 if (!(outrel = fopen("forward_rel.xml","a")))
273 fprintf(stderr, "error in openinf file forward_rel.xml\n");
276 if (!(outsort = fopen("forward_sort.xml","a")))
278 fprintf(stderr, "error in openinf file forward_rel.xml\n");
281 // We process the body
282 if (!stat("tmp/body.xml",&buf)) {
283 yyin = fopen("tmp/body.xml", "r");
289 // We process the type
290 yyin = fopen("tmp/type.xml", "r");
298 printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n");
299 printf("<!DOCTYPE rdf:RDF [
300 <!ENTITY rdfns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
301 <!ENTITY hthns 'http://www.cs.unibo.it/helm/schemas/schema-helmth#'>
302 <!ENTITY hns 'http://www.cs.unibo.it/helm/schemas/schema-helm#'>
306 printf("<rdf:RDF xml:lang=\"en\" xmlns:rdf=\"&rdfns;\" xmlns:h=\"&hns;\" xmlns:hth=\"&hthns;\">\n");
307 printf("\t<h:Object rdf:about=\"");
308 printf("%s",argv[1]);
310 print_all(argv[1],outrel,outsort);
311 printf("\t</h:Object>\n");
312 printf("</rdf:RDF>\n");
316 search(uri,first_child,position,depth)
321 if (position == MAINHYP)
323 if (first_child == HERE)
324 found = search_bucket(uri,MAINHYP,depth);
326 found = search_bucket(uri,INHYP,0);
328 else if (position == INCONCL)
330 if (first_child == HERE)
331 found = search_bucket(uri,MAINCONCL,depth);
333 found = search_bucket(uri,INCONCL,0);
337 found = search_bucket(uri,position,depth);
338 /* if (found == NOTFOUND)
339 fprintf(stderr,"pos = %d, uri = %s\n", position, uri); */
342 (first_child == HERE)
344 if (position == MAINHYP)
345 found = search_bucket(uri,MAINHYP,depth);
346 else if (position == INCONCL)
347 found = search_bucket(uri,MAINCONCL,0);
348 else if (position == INHYP)
349 found = search_bucket(uri,INHYP,0);
350 if (found == NOTFOUND)
351 printf( "pos = %d, uri = %s\n", MAINCONCL, uri);
353 else if ((position == MAINHYP) && (first_child == AFTER))
354 found = search_bucket(uri,INHYP,0);
355 else found = search_bucket(uri,position,0);
356 if (found == NOTFOUND)
357 printf( "pos = %d, uri = %s\n", position, uri);