Re: [Monetdb-developers] [Monetdb-checkins] MonetDB5/src/modules/mal rdf.mx, , 1.1, 1.2
Marco Antonelli wrote:
Update of /cvsroot/monetdb/MonetDB5/src/modules/mal In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv9457/src/modules/mal
Modified Files: rdf.mx Log Message: The log message is missing...
It is always nice to have a summary of what you are check in... It also helps the developers in future debugging tasks.... Romulo
U rdf.mx Index: rdf.mx =================================================================== RCS file: /cvsroot/monetdb/MonetDB5/src/modules/mal/rdf.mx,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- rdf.mx 26 Mar 2008 12:51:06 -0000 1.1 +++ rdf.mx 1 Apr 2008 14:48:08 -0000 1.2 @@ -41,7 +41,7 @@ address RDFimportGraph comment "import a graph in a named rdf db";
-command exportGraph( url:str, db:str, graph:str) : void +command exportGraph( url:str, db:str, graph:str, order:str, syntax:str) : void address RDFexportGraph comment "export a graph in a named rdf db";
@@ -62,6 +62,7 @@ #include
#define rdf_export extern +#define RET_MAXLEN 2048
typedef struct { lng *cur; @@ -73,7 +74,7 @@ oid *o; oid *p; oid *s; - str ret; + str *ret; } triple_handler_vars; //TODO //static lng RDFestimate(str url) { @@ -91,34 +92,31 @@
void message_handler(void *user_data, raptor_locator *locator, const char *message) { - unsigned int maxlength = 2048; - char finalmessage[maxlength]; size_t length = 0; - char *msg = finalmessage; str *ret = (str *)user_data; + str msg = *ret; if (locator->uri) { - snprintf(msg, maxlength, "In URI location \"%s\": ", raptor_uri_as_string(locator->uri)); - length = strlen(finalmessage); - msg = finalmessage + length*(sizeof(char)); + snprintf(msg, RET_MAXLEN, "In URI location \"%s\": ", raptor_uri_as_string(locator->uri)); + length = strlen(*ret); + msg = *ret + length * (sizeof(char)); } - if (locator->line >=0 && length < maxlength-1) + if (locator->line >=0 && length < RET_MAXLEN-1) { - snprintf(msg, maxlength-length, "at line %d: ", locator->line); - length = strlen(finalmessage); - msg = finalmessage + length*(sizeof(char)); + snprintf(msg, RET_MAXLEN-length, "at line %d: ", locator->line); + length = strlen(*ret); + msg = *ret + length * (sizeof(char)); } - if (locator->column >=0 && length < maxlength-1) + if (locator->column >=0 && length < RET_MAXLEN-1) { - snprintf(msg, maxlength-length, "at column %d: ", locator->column); - length = strlen(finalmessage); - msg = finalmessage + length*(sizeof(char)); + snprintf(msg, RET_MAXLEN-length, "at column %d: ", locator->column); + length = strlen(*ret); + msg = *ret + length * (sizeof(char)); } - if (message && length < maxlength-1) + if (message && length < RET_MAXLEN-1) { - snprintf(msg, maxlength-length, "%s\n", message); + snprintf(msg, RET_MAXLEN-length, "%s\n", message); } - *ret=finalmessage; }
@= RDFins @@ -133,7 +131,7 @@ bun = (BUN) map->batCount; if (!BUNappend(map,(ptr)@1v, TRUE)) { GDKerror("RDFimport: @1[" LLFMT "] = %s, BUNappend fails\n", cur, @1v); - data->ret = RDFimport_fail(map,ob,pb,sb); + *(data->ret) = RDFimport_fail(map,ob,pb,sb); } } /* s,p,o[cur] are set to the virtual oid which is bun s p and o are arrays of oid */ @@ -153,9 +151,10 @@ oid *o = data->o; oid *p = data->p; oid *s = data->s; + str *ret = data->ret; BATiter mi = bat_iterator(BATmirror(map)); BUN bun; - if (data->ret!=MAL_SUCCEED) + if (strlen(*ret)!=0) return; /* get the subject */ if (triple->subject_type == RAPTOR_IDENTIFIER_TYPE_RESOURCE) @@ -164,7 +163,7 @@ sv = (str)triple->subject; else { - data->ret="Unexpected subject type"; + *ret="Unexpected subject type"; return; }
@@ -173,7 +172,7 @@ pv = (str)raptor_uri_as_string((raptor_uri *)triple->predicate); else { - data->ret="Unexpected predicate type"; + *ret="Unexpected predicate type"; return; }
@@ -190,18 +189,18 @@ ov = (str)raptor_uri_as_string((raptor_uri*)triple->object); else { - data->ret="Unexpected object type"; + *ret="Unexpected object type"; return; }
@:RDFins(o)@ - if (data->ret == MAL_SUCCEED) + if (strlen(*ret)==0) { @:RDFins(p)@ - if (data->ret == MAL_SUCCEED) + if (strlen(*ret)==0) { @:RDFins(s)@ - if (data->ret == MAL_SUCCEED) + if (strlen(*ret)==0) { if (++(*cur) > *lim) { *lim *= 2; @@ -209,7 +208,7 @@ pb = BATextend(pb, *lim); sb = BATextend(sb, *lim); if (ob == NULL || pb == NULL || sb == NULL) - data->ret = RDFimport_fail(map,ob,pb,sb); + *ret = RDFimport_fail(map,ob,pb,sb); o = (oid *) Tloc(ob, BUNfirst(ob)); p = (oid *) Tloc(pb, BUNfirst(pb)); s = (oid *) Tloc(sb, BUNfirst(sb)); @@ -223,6 +222,7 @@ RDFimport_(BAT** S, BAT** P, BAT **O, str url, BAT *map) { raptor_parser *parser; raptor_uri *rdf_file; + str ret; raptor_init(); parser = raptor_new_parser("rdfxml"); if (parser) @@ -244,41 +244,15 @@ p = (oid *) Tloc(pb, BUNfirst(pb)); s = (oid *) Tloc(sb, BUNfirst(sb));
- //char obuf[20],*op, pbuf[20],*pp, sbuf[20],*sp; - //str ov, pv, sv; - if (map == NULL || ob == NULL || pb == NULL || sb == NULL) return RDFimport_fail(map,ob,pb,sb); - - - -// strcpy(obuf, "object"); for(ov=op=obuf; *op; op++); op[1]=0; -// strcpy(pbuf, "predicate"); for(pv=pp=pbuf; *pp; pp++); pp[1]=0; -// strcpy(sbuf, "subject"); for(sv=sp=sbuf; *sp; sp++); sp[1]=0; -// while (cur < 8 /*redland gives me (ov,pv,sv)*/ ) { -// *op = (cur & 4)?'1':'0'; -// *pp = (cur & 2)?'1':'0'; -// *sp = (cur & 1)?'1':'0'; -// RDFins(o) /* mx macros*/ -// RDFins(p) -// RDFins(s) -// -// if (++cur > lim) { -// lim *= 2; -// ob = BATextend(ob, lim); -// pb = BATextend(pb, lim); -// sb = BATextend(sb, lim); -// if (ob == NULL || pb == NULL || sb == NULL) -// return RDFimport_fail(map,ob,pb,sb); -// o = (oid *) Tloc(ob, BUNfirst(ob)); -// p = (oid *) Tloc(pb, BUNfirst(pb)); -// s = (oid *) Tloc(sb, BUNfirst(sb)); -// } -// }
- data = malloc(sizeof(triple_handler_vars)); + data = GDKmalloc(sizeof(triple_handler_vars)); if (data) { + char ret_array[RET_MAXLEN]; + str ret_ptr = ret_array; + ret_array[0] = '\0'; data->cur = cur; data->lim = lim; data->map =map; @@ -288,18 +262,18 @@ data->s = s; data->p = p; data->o = o; - data->ret = MAL_SUCCEED; + data->ret = &ret_ptr; raptor_set_statement_handler(parser, data, triples_handler); - raptor_set_fatal_error_handler(parser, &data->ret, message_handler); - raptor_set_error_handler(parser, &data->ret, message_handler); - raptor_set_warning_handler(parser, &data->ret, message_handler); - //raptor_set_parser_strict(parser, TRUE); + raptor_set_fatal_error_handler(parser, &ret_ptr, message_handler); + raptor_set_error_handler(parser, &ret_ptr, message_handler); + raptor_set_warning_handler(parser, &ret_ptr, message_handler); + raptor_set_parser_strict(parser, TRUE);
if (raptor_parse_file(parser, rdf_file, NULL) == 0) { - /* do something with redland */ - if (data->ret == MAL_SUCCEED) + if(strlen(ret_ptr)==0) { + ret = MAL_SUCCEED; BATseqbase(ob, 0); BATseqbase(pb, 0); BATseqbase(sb, 0); @@ -312,30 +286,31 @@ BATkey(BATmirror(ob), FALSE); BATkey(BATmirror(sb), FALSE); BATkey(BATmirror(pb), FALSE); - - free(data); - raptor_free_parser(parser); - raptor_free_uri(rdf_file); - raptor_finish(); - return MAL_SUCCEED; } - else - throw(MAL, "rdf.import", data->ret); } else - throw(MAL, "rdf.import", "RDF parsing error"); + ret = "RDF parsing error"; + GDKfree(data); } else - throw(MAL, "rdf.import", "triple_handler_vars malloc failed"); + ret = "triple_handler_vars malloc failed"; + raptor_free_uri(rdf_file); } else - throw(MAL, "rdf.import", "Unexistent file: \"%s\"", url); + ret = "Unexistent url"; + raptor_free_parser(parser); } else - throw(MAL, "rdf.import", "Could not create a Redland parser"); + ret = "Could not create a Redland parser"; + raptor_finish(); + if (ret != MAL_SUCCEED) + throw(MAL, "rdf.import", ret); + + return MAL_SUCCEED; }
-rdf_export str RDFimport(int* S, int* P, int* O, str *url, bat m) +rdf_export +str RDFimport(int* S, int* P, int* O, str *url, bat m) { BAT *sb = NULL, *ob=NULL, *pb = NULL, *map = BATdescriptor(m); str ret; @@ -352,45 +327,109 @@ }
static str -RDFexport_(str url, bat M, bat S, bat P, bat O) { - str ret = "RDFexport failed to obtain bats"; +RDFexport_(str url, bat M, bat S, bat P, bat O, str syntax) +{ + str ret = MAL_SUCCEED; BAT *map = BATdescriptor(M); - if (map) { + (void)url; + if (map) + { BAT *sb = BATdescriptor(S); - if (sb) { + if (sb) + { BAT *pb = BATdescriptor(P); - if (pb) { + if (pb) + { BAT *ob = BATdescriptor(O); - if (ob) { - lng i, cnt = BATcount(ob); + if (ob) + { + raptor_serializer* rdf_serializer; + const char *filename="/ufs/antonell/Desktop/output.rdf"; + lng i, cnt = BATcount(ob); oid *o = (oid *) Tloc(ob, BUNfirst(ob)); oid *p = (oid *) Tloc(pb, BUNfirst(pb)); oid *s = (oid *) Tloc(sb, BUNfirst(sb)); //var_t position in heap var_t *off = (var_t *) Tloc(map, BUNfirst(map)); str base = (str) map->T->vheap->base;//heap first position - - for(i=0; i
subject=(void*)raptor_new_uri((const unsigned char*)sv); + triple->subject_type=RAPTOR_IDENTIFIER_TYPE_RESOURCE; + + triple->predicate=(void*)raptor_new_uri((const unsigned char*)pv); + triple->predicate_type=RAPTOR_IDENTIFIER_TYPE_RESOURCE; + + triple->object=ov; + triple->object_type=RAPTOR_IDENTIFIER_TYPE_LITERAL; + //triple->object_literal_language=(const unsigned char*)"en"; + triple->object_literal_language=NULL; + triple->object_literal_datatype = NULL; + /* Write the triple */ + if (raptor_serialize_statement(rdf_serializer, triple)!=0) + ret="failed to serialize a statement"; + + /* Delete the triple */ + raptor_free_uri((raptor_uri*)triple->subject); + raptor_free_uri((raptor_uri*)triple->predicate); + GDKfree(triple); + } + } + ret = MAL_SUCCEED; + raptor_serialize_end(rdf_serializer); + } + else + ret = "raptor_serialize_start failed"; + raptor_free_serializer(rdf_serializer); } - ret = MAL_SUCCEED; + else + ret = "raptor_new_serializer failed"; + raptor_finish(); BBPreleaseref(ob->batCacheid); - } + } + else + ret = "Failed to obtain O bat"; BBPreleaseref(pb->batCacheid); - } + } + else + ret = "Failed to obtain P bat"; BBPreleaseref(sb->batCacheid); - } + } + else + ret = "Failed to obtain S bat"; BBPreleaseref(map->batCacheid); - } + } + else + ret = "Failed to obtain MAP bat"; return ret; } str RDFexport(str *url, bat M, bat S, bat P, bat O) { - str ret = RDFexport_(*url, M, S, P, O); + str ret = RDFexport_(*url, M, S, P, O, "dummy syntax"); if (ret != MAL_SUCCEED) throw(MAL, "RDFexport", ret); return MAL_SUCCEED; @@ -513,23 +552,23 @@
ret = "RDFimportGraph: sorting failed"; if (sorted) { - ret = @:sort(sb, pb, ob, Spo, sPo, spO)@ + ret = @:sort(sb,pb,ob,Spo,sPo,spO)@ if (ret == MAL_SUCCEED) { - ret = @:sort(sb, ob, pb, Sop, sOp, soP)@ + ret = @:sort(sb,ob,pb,Sop,sOp,soP)@ if (ret == MAL_SUCCEED) { BBPreclaim(sorted); sorted = BATmirror(BATsort(BATmirror(pb))); if (sorted) { - ret = @:sort(pb, ob,sb,Pos,pOs,poS)@ + ret = @:sort(pb,ob,sb,Pos,pOs,poS)@ if (ret == MAL_SUCCEED) { - ret = @:sort(pb, sb,ob,Pso,pSo,psO)@ + ret = @:sort(pb,sb,ob,Pso,pSo,psO)@ if (ret == MAL_SUCCEED) { BBPreclaim(sorted); sorted = BATmirror(BATsort(BATmirror(ob))); if (sorted) { - ret = @:sort(ob, pb, sb, Ops, oPs, opS)@ + ret = @:sort(ob,pb,sb,Ops,oPs,opS)@ if (ret == MAL_SUCCEED) { - ret = @:sort(ob, sb, pb,Osp,oSp,osP)@ + ret = @:sort(ob,sb,pb,Osp,oSp,osP)@ if (ret == MAL_SUCCEED) { ret = MAL_SUCCEED; goto succeed; @@ -572,15 +611,84 @@ throw(MAL, "RDFimportGraph", ret); return MAL_SUCCEED; } -str RDFexportGraph(str *url, str *db, str *graph) { + +static str getBatNames(str db, str graph, char *s_buf,char *p_buf,char *o_buf, str order) +{ + str err = "order may be only one among \"spo\",\"sop\",\"pso\",\"pos\",\"osp\",\"ops\""; + if (strlen(order)>3) + return err; + if (strcmp(order, "spo")==0) + { + snprintf(s_buf, 1024, "%s_%s_Spo", db, graph); + snprintf(p_buf, 1024, "%s_%s_sPo", db, graph); + snprintf(o_buf, 1024, "%s_%s_spO", db, graph); + } + else if (strcmp(order, "sop")==0) + { + snprintf(s_buf, 1024, "%s_%s_Sop", db, graph); + snprintf(o_buf, 1024, "%s_%s_sOp", db, graph); + snprintf(p_buf, 1024, "%s_%s_soP", db, graph); + } + else if (strcmp(order, "pos")==0) + { + snprintf(p_buf, 1024, "%s_%s_Pos", db, graph); + snprintf(o_buf, 1024, "%s_%s_pOs", db, graph); + snprintf(s_buf, 1024, "%s_%s_poS", db, graph); + } + else if (strcmp(order, "pso")==0) + { + snprintf(p_buf, 1024, "%s_%s_Pso", db, graph); + snprintf(s_buf, 1024, "%s_%s_pSo", db, graph); + snprintf(o_buf, 1024, "%s_%s_psO", db, graph); + } + else if (strcmp(order, "osp")==0) + { + snprintf(o_buf, 1024, "%s_%s_Osp", db, graph); + snprintf(s_buf, 1024, "%s_%s_oSp", db, graph); + snprintf(p_buf, 1024, "%s_%s_osP", db, graph); + } + else if (strcmp(order, "ops")==0) + { + snprintf(o_buf, 1024, "%s_%s_Ops", db, graph); + snprintf(p_buf, 1024, "%s_%s_oPs", db, graph); + snprintf(s_buf, 1024, "%s_%s_opS", db, graph); + } + else + return err; + return MAL_SUCCEED; +} + +static str checkSyntax(str syntax) +{ + if ( //!strcmp(syntax, "atom") || + !strcmp(syntax, "ntriples") || + !strcmp(syntax, "rdfxml") || + !strcmp(syntax, "rdfxml-abbrev") || + !strcmp(syntax, "rdfxml-xmp") || + !strcmp(syntax, "turtle") || + //!strcmp(syntax, "rdfxml-xmp") || + !strcmp(syntax, "rss-1.0") || + !strcmp(syntax, "dot")) + { + return MAL_SUCCEED; + } + else + return "syntax may be only one among \"atom\",\"ntriples\",\"rdfxml\",\"rdfxml-abbrev\",\"rdfxml-xmp\",\"turtle\",\"rdfxml-xmp\",\"rss-1.0\",\"dot\""; +} + +str RDFexportGraph(int *d, str *url, str *db, str *graph, str *order, str *syntax) +{ char m_buf[1024], o_buf[1024], p_buf[1024], s_buf[1024]; bat map, ob, pb, sb; - str ret = "RDFexportGraph failed to obtain bats"; - + str ret; + (void)d; + ret = checkSyntax(*syntax); + if (ret!= MAL_SUCCEED) + throw(MAL, "RDFexportGraph", ret); + ret = getBatNames(*db, *graph, s_buf, p_buf, o_buf, *order); + if (ret!= MAL_SUCCEED) + throw(MAL, "RDFexportGraph", ret); snprintf(m_buf, 1024, "%s_%s_map", *db, *graph); - snprintf(p_buf, 1024, "%s_%s_Ops", *db, *graph); - snprintf(o_buf, 1024, "%s_%s_oPs", *db, *graph); - snprintf(s_buf, 1024, "%s_%s_opS", *db, *graph); map = BBPindex(m_buf); if (map) { sb = BBPindex(s_buf); @@ -589,11 +697,19 @@ if (pb) { ob = BBPindex(o_buf); if (ob) { - ret = RDFexport_(*url, map, sb, pb, ob); + ret = RDFexport_(*url, map, sb, pb, ob, *syntax); } + else + ret = "Failed to obtain O bat"; } + else + ret = "Failed to obtain P bat"; } + else + ret = "Failed to obtain S bat"; } + else + ret = "Failed to obtain map bat"; if (ret != MAL_SUCCEED) throw(MAL, "RDFexportGraph", ret); return MAL_SUCCEED;
------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ Monetdb-checkins mailing list Monetdb-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-checkins
On Tue, Apr 01, 2008 at 04:52:03PM +0200, Romulo Goncalves wrote:
Marco Antonelli wrote:
Update of /cvsroot/monetdb/MonetDB5/src/modules/mal In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv9457/src/modules/mal
Modified Files: rdf.mx Log Message: The log message is missing...
It is always nice to have a summary of what you are check in... It also helps the developers in future debugging tasks....
see also pages 8-16 (in particular pages 11 & 12) of http://homepages.cwi.nl/~manegold/Presentations/MonetDBdevTTT.pdf ;-) Stefan
Romulo
-- | Dr. Stefan Manegold | mailto:Stefan.Manegold@cwi.nl | | CWI, P.O.Box 94079 | http://www.cwi.nl/~manegold/ | | 1090 GB Amsterdam | Tel.: +31 (20) 592-4212 | | The Netherlands | Fax : +31 (20) 592-4312 |
participants (2)
-
Romulo Goncalves
-
Stefan Manegold