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))
164 tmp=(char *)malloc((sizeof('a')*200));
167 if (position == INTYPE) /* SORT on the spine */
170 search(tmp,first_child,position,spine_depth);
172 else search(tmp,first_child,position,depth);
183 if (position == INTYPE) /* CONST on the spine */
189 if (position == INTYPE) /* MUTIND on the spine */
195 if (position == INTYPE) /* MUTCONSTRUCT on the spine */
197 where = MUTCONSTRUCT;
202 uri=(char *)malloc((sizeof('a')*200));
207 if (position == INCONCL)
208 search(uri,first_child,position,spine_depth);
209 else search(uri,first_child,position,depth);
217 "noType=\""{digits} {
218 if ((where == MUTIND) || (where == MUTCONSTRUCT))
219 { strsep(&yytext,&sep);
220 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
223 sprintf(tmp,"%d",tmp_n);
224 strcat(uri,"#xpointer(1/");
230 if (position == INCONCL)
231 search(uri,first_child,position,spine_depth);
232 else search(uri,first_child,position,depth);
236 first_child = AFTER;};
239 "noConstr=\""{digits} {
240 if (where == MUTCONSTRUCT)
241 { strsep(&yytext,&sep);
242 tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
247 if (position == INCONCL)
248 search(uri,first_child,position,spine_depth);
249 else search(uri,first_child,position,depth);
253 first_child = AFTER;};
260 /***************************************************************/
261 /* 6. Auxiliary functions. */
262 /***************************************************************/
264 main(int argc, char *argv[])
267 FILE *outrel, *outsort;
270 if (!(outrel = fopen("forward_rel.rdf","a")))
272 fprintf(stderr, "error in openinf file forward_rel.rdf\n");
275 if (!(outsort = fopen("forward_sort.rdf","a")))
277 fprintf(stderr, "error in openinf file forward_rel.rdf\n");
280 // We process the body
281 if (!stat("tmp/body.xml",&buf)) {
282 yyin = fopen("tmp/body.xml", "r");
288 // We process the type
289 yyin = fopen("tmp/type.xml", "r");
297 printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n");
298 printf("<!DOCTYPE rdf:RDF [
299 <!ENTITY rdfns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
300 <!ENTITY hthns 'http://www.cs.unibo.it/helm/schemas/schema-helmth#'>
301 <!ENTITY hns 'http://www.cs.unibo.it/helm/schemas/schema-helm#'>
305 printf("<rdf:RDF xml:lang=\"en\" xmlns:rdf=\"&rdfns;\" xmlns:h=\"&hns;\" xmlns:hth=\"&hthns;\">\n");
306 printf("\t<h:Object rdf:about=\"");
307 printf("%s",argv[1]);
309 print_all(argv[1],outrel,outsort);
310 printf("\t</h:Object>\n");
311 printf("</rdf:RDF>\n");
315 search(uri,first_child,position,depth)
320 if (position == MAINHYP)
322 if (first_child == HERE)
323 found = search_bucket(uri,MAINHYP,depth);
325 found = search_bucket(uri,INHYP,0);
327 else if (position == INCONCL)
329 if (first_child == HERE)
330 found = search_bucket(uri,MAINCONCL,depth);
332 found = search_bucket(uri,INCONCL,0);
336 found = search_bucket(uri,position,depth);
337 /* if (found == NOTFOUND)
338 fprintf(stderr,"pos = %d, uri = %s\n", position, uri); */
341 (first_child == HERE)
343 if (position == MAINHYP)
344 found = search_bucket(uri,MAINHYP,depth);
345 else if (position == INCONCL)
346 found = search_bucket(uri,MAINCONCL,0);
347 else if (position == INHYP)
348 found = search_bucket(uri,INHYP,0);
349 if (found == NOTFOUND)
350 printf( "pos = %d, uri = %s\n", MAINCONCL, uri);
352 else if ((position == MAINHYP) && (first_child == AFTER))
353 found = search_bucket(uri,INHYP,0);
354 else found = search_bucket(uri,position,0);
355 if (found == NOTFOUND)
356 printf( "pos = %d, uri = %s\n", position, uri);