]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/metadata/create_V7_mowgli/METADATA/meta_lex.l
* new version of metadata extraction
[helm.git] / helm / metadata / create_V7_mowgli / METADATA / meta_lex.l
index eca7c383d6a1a96568d20a31521b3ca7d82b75c5..2f8c4b039f06204e2b77fb5831e52e84bd5038a3 100644 (file)
@@ -39,6 +39,7 @@
 #include                <string.h>
 #include                <stdlib.h>
 #include                <sys/stat.h>
+#include                <postgresql/libpq-fe.h>
 #include                "sthandler.h"
 %}
 
@@ -70,7 +71,7 @@ int                     found = NOTFOUND;
 int                     position = INBODY;
 int                     first_child = HERE;
 int                    skip = 0;     // boolean to skip the insertion of a URI
-int                     no_open_source =0;
+int                     no_open_source = 0;
 int                     spine_depth = 0;
 int                     depth = 0;
 int                     tmp_n;
@@ -101,6 +102,10 @@ value                   [^"]+
 
 "</body>"(" "|\n)*"<type" {
                     position = INTYPE; // Variables have both a body and a type
+                    first_child = HERE;
+                    no_open_source = 0;
+                    spine_depth = 0;
+                    depth = 0;   
                    }
 
 "<decl"            |
@@ -113,7 +118,7 @@ value                   [^"]+
                    }
 
 "</decl>"          |
-"</def           {
+"</def>"           {
                     if (position == INHYP)
                      {
                       no_open_source--;
@@ -129,8 +134,9 @@ value                   [^"]+
                        position = INTYPE;
                        spine_depth++;
                        depth = 0;
+                       first_child = HERE;
                       }
-                    first_child = HERE;
+                    /* bug? first_child = HERE; */
                    }
 
 
@@ -264,54 +270,66 @@ value                   [^"]+
 
 main(int argc, char *argv[])
 {                  
-                   struct stat buf;
-                   FILE *outrel, *outsort;
-
-                   init_symbol_table();
-                   if (!(outrel = fopen("forward_rel.xml","a"))) 
-                     {
-                     fprintf(stderr, "error in openinf file forward_rel.xml\n");
-                      exit(-1);
-                     }
-                   if (!(outsort = fopen("forward_sort.xml","a"))) 
-                     {
-                     fprintf(stderr, "error in openinf file forward_rel.xml\n");
-                      exit(-1);
-                     }
-                   // We process the body
-                   if (!stat("tmp/body.xml",&buf)) {
-                      yyin = fopen("tmp/body.xml", "r");
-                      position = INBODY;
-                      yylex();
-                      fclose(yyin);
-                   }
+    struct stat buf;
+
+    char       *pghost,
+               *pgport,
+               *pgoptions,
+               *pgtty;
+    char       *dbName;
+
+    /* FILE *debug; */
+
+    PGconn     *conn;
+    PGresult   *res;
+
+    /*
+     * begin, by setting the parameters for a backend connection if the
+     * parameters are null, then the system will try to use reasonable
+     * defaults by looking up environment variables or, failing that,
+     * using hardwired constants
+     */
+
+    /* make a connection to the database */
+    conn = PQconnectdb("user=helm dbname=mowgli");
+
+    /*
+     * check to see that the backend connection was successfully made
+     */
+    if (PQstatus(conn) == CONNECTION_BAD)
+    {
+        fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
+        fprintf(stderr, "%s", PQerrorMessage(conn));
+        exit_nicely(conn);
+    }
+
+    /* debug = fopen("/tmp/trace.out","w"); */
+    /* PQtrace(conn, debug);  */
+
+    /* initialize the symbol table */
+    init_symbol_table();
+
+    // We process the body
+    if (!stat("tmp/body.xml",&buf)) 
+    {
+        yyin = fopen("tmp/body.xml", "r");
+        position = INBODY;
+        yylex();
+        fclose(yyin);
+     }
+
+    // We process the type
+    yyin = fopen("tmp/type.xml", "r");
+    position = INTYPE;
+    first_child = HERE;
+    no_open_source = 0;
+    spine_depth = 0;
+    depth = 0;
+    yylex(); 
+    fclose(yyin);
+    print_all(argv[1],conn);
+} 
 
-                   // We process the type
-                   yyin = fopen("tmp/type.xml", "r");
-                   position = INTYPE;
-                   first_child = HERE;
-                   no_open_source = 0;
-                   spine_depth = 0;
-                   depth = 0;
-                   yylex(); 
-
-                   printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n");
-printf("<!DOCTYPE rdf:RDF [
-        <!ENTITY rdfns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
-        <!ENTITY hthns 'http://www.cs.unibo.it/helm/schemas/schema-helmth#'>
-        <!ENTITY hns 'http://www.cs.unibo.it/helm/schemas/schema-helm#'>
-
-   ]>\n");
-
-                   printf("<rdf:RDF xml:lang=\"en\" xmlns:rdf=\"&rdfns;\" xmlns:h=\"&hns;\" xmlns:hth=\"&hthns;\">\n");
-                   printf("\t<h:Object rdf:about=\"");
-                   printf("%s",argv[1]);
-                   printf("\">\n");
-                   print_all(argv[1],outrel,outsort);
-                   printf("\t</h:Object>\n");
-                   printf("</rdf:RDF>\n");
-                   fclose(yyin);
-                   } 
 
 search(uri,first_child,position,depth)
 char               *uri;
@@ -335,8 +353,9 @@ int                position;
                         
                    else 
                       found = search_bucket(uri,position,depth);
-                   /* if (found == NOTFOUND)
-                         fprintf(stderr,"pos = %d, uri = %s\n", position, uri); */
+                   /*
+                   if (found == NOTFOUND)
+                         fprintf(stderr,"here = %d, pos = %d, uri = %s\n", first_child,position, uri); */
 } 
 /*                  
                       (first_child == HERE) 
@@ -361,3 +380,6 @@ int yywrap() {
                return 1;
              }
 
+
+
+