Changeset: 55b03c4a084c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=55b03c4a084c
Added Files:
monetdb5/extras/rdf/rdfontologyload.c
monetdb5/extras/rdf/rdfparser.c
monetdb5/extras/rdf/rdfparser.h
Modified Files:
monetdb5/extras/rdf/Makefile.ag
monetdb5/extras/rdf/rdf.h
monetdb5/extras/rdf/rdf_shredder.c
monetdb5/extras/rdf/rdfschema.mal
sql/scripts/30_rdf.sql
Branch: rdf
Log Message:
Create function and data structure for loading ontology into RDF store.
Move common data structure for rdf parser to rdfparser.h, .c
diffs (truncated from 560 to 300 lines):
diff --git a/monetdb5/extras/rdf/Makefile.ag b/monetdb5/extras/rdf/Makefile.ag
--- a/monetdb5/extras/rdf/Makefile.ag
+++ b/monetdb5/extras/rdf/Makefile.ag
@@ -31,7 +31,8 @@ lib__rdf = {
#MODULE
NOINST
#DIR = libdir/monetdb5
- SOURCES = rdf.h rdfschema.h rdf_shredder.c rdfalgebra.c rdfschema.c
+ SOURCES = rdf.h rdfschema.h rdfparser.h rdfparser.c rdfontologyload.c
rdf_shredder.c rdfalgebra.c rdfschema.c
+
#SEP = _
# LIBS = ./hashmap/librdfhash
# ../../tools/libmonetdb5 \
diff --git a/monetdb5/extras/rdf/rdf.h b/monetdb5/extras/rdf/rdf.h
--- a/monetdb5/extras/rdf/rdf.h
+++ b/monetdb5/extras/rdf/rdf.h
@@ -45,6 +45,9 @@
rdf_export str
RDFParser(BAT **graph, str *location, str *graphname, str *schemam);
+rdf_export str
+RDFOntologyParser(int *ret, str *location, str *schema);
+
rdf_export str
RDFleftfetchjoin_sortedestimate(int *result, int *lid, int *rid, lng
*estimate);
rdf_export str
diff --git a/monetdb5/extras/rdf/rdf_shredder.c
b/monetdb5/extras/rdf/rdf_shredder.c
--- a/monetdb5/extras/rdf/rdf_shredder.c
+++ b/monetdb5/extras/rdf/rdf_shredder.c
@@ -28,7 +28,7 @@
#include "tokenizer.h"
#include <gdk.h>
#include <rdf.h>
-#include <raptor2.h>
+#include <rdfparser.h>
typedef struct graphBATdef {
graphBATType batType; /* BAT type */
@@ -73,94 +73,8 @@ static graphBATdef graphdef[N_GRAPH_BAT]
};
#endif /* STORE */
-typedef struct parserData {
- /**PROPERTIES */
- str location; /* rdf data file location */
- oid tcount; /* triple count */
- raptor_parser *rparser; /* the parser object */
- /**ERROR HANDLING */
- int exception; /* raise an exception */
- int warning; /* number of warning msgs */
- int error; /* number of error msgs */
- int lasterror; /* # errors before next triple */
- int fatal; /* number of fatal msgs */
- const char *exceptionMsg; /* exception msgs */
- const char *warningMsg; /* warning msgs */
- const char *errorMsg; /* error msgs */
- const char *fatalMsg; /* fatal msgs */
- int line; /* locator for errors */
- int column; /* locator for errors */
- /**GRAPH DATA */
- BAT **graph; /* BATs for the result
- shredded RDF graph */
-} parserData;
/*
- * @-
- * The (fatal) errors and warnings produced by the raptor parser are handled
- * by the next three message handler functions.
- */
-
-static void
-fatalHandler (void *user_data, raptor_log_message* message)
-{
- parserData *pdata = ((parserData *) user_data);
- pdata->fatalMsg = GDKstrdup(message->text);
- mnstr_printf(GDKout, "rdflib: fatal:%s\n", pdata->fatalMsg);
- pdata->fatal++;
-
- /* check for a valid locator object and only then use it */
- if (message->locator != NULL) {
- pdata->line = message->locator->line;
- pdata->column = message->locator->column;
- mnstr_printf(GDKout, "rdflib: fatal: at line %d column %d\n",
pdata->line, pdata->column);
- }
-
-}
-
-
-static void
-errorHandler (void *user_data, raptor_log_message* message)
-{
- parserData *pdata = ((parserData *) user_data);
- pdata->errorMsg = GDKstrdup(message->text);
- mnstr_printf(GDKout, "rdflib: error:%s\n", pdata->errorMsg);
- pdata->error++;
-
- /* check for a valid locator object and only then use it */
- if (message->locator != NULL) {
- pdata->line = message->locator->line;
- pdata->column = message->locator->column;
- mnstr_printf(GDKout, "rdflib: error: at line %d column %d\n",
pdata->line, pdata->column);
- }
-
-}
-
-
-static void
-warningHandler (void *user_data, raptor_log_message* message)
-{
- parserData *pdata = ((parserData *) user_data);
- pdata->warningMsg = GDKstrdup(message->text);
- mnstr_printf(GDKout, "rdflib: warning:%s\n", pdata->warningMsg);
- pdata->warning++;
-
- /* check for a valid locator object and only then use it */
- if (message->locator != NULL) {
- pdata->line = message->locator->line;
- pdata->column = message->locator->column;
- mnstr_printf(GDKout, "rdflib: warning: at line %d column %d\n",
pdata->line, pdata->column);
- }
-
-}
-
-static void
-raptor_exception(parserData *pdata, const char* msg){
- pdata->exception++;
- pdata->exceptionMsg = GDKstrdup(msg);
- raptor_parser_parse_abort (pdata->rparser);
-}
-/*
static void
rdf_BUNappend_unq(parserData* pdata, BAT *b, void* value, BUN* bun){
@@ -309,6 +223,7 @@ tripleHandler(void* user_data, const rap
BUN bun = BUN_NONE;
BAT **graph = pdata->graph;
+ printf("%s %s
%s\n",raptor_term_to_string(triple->subject),raptor_term_to_string(triple->predicate),raptor_term_to_string(triple->object));
if (pdata->error > pdata->lasterror){
unsigned char* objStr;
int objLen;
@@ -806,3 +721,4 @@ RDFParser (BAT **graph, str *location, s
return MAL_SUCCEED;
}
+
diff --git a/monetdb5/extras/rdf/rdfontologyload.c
b/monetdb5/extras/rdf/rdfontologyload.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/extras/rdf/rdfontologyload.c
@@ -0,0 +1,224 @@
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2013 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+/* This contains algebra functions used for RDF store only */
+
+#include "monetdb_config.h"
+#include "mal_exception.h"
+#include "url.h"
+#include "tokenizer.h"
+#include <gdk.h>
+#include <rdf.h>
+#include <rdfparser.h>
+
+/**
+ * Ontology vocabulary is stored in two tables
+ * Table1: ontMetaTbl [uri, label, subclassof]
+ * Table2: ontAttTbl [uri, attribute]
+ */
+typedef enum{
+ OntURI,
+ OntLabel,
+ OntSubclassof,
+ OntAttURI,
+ OntAttAtt
+} OntTableCol;
+
+#define N_ONTOLOGY_BAT (OntAttAtt+1)
+
+typedef struct OntBATdef {
+ OntTableCol batType; /* BAT type */
+ str name; /* name of the BAT/column */
+ int headType; /* type of left column */
+ int tailType; /* type of right column */
+} OntBATdef;
+
+static OntBATdef ontBatdef[N_ONTOLOGY_BAT]= {
+ {OntURI, "uri", TYPE_void, TYPE_oid},
+ {OntLabel, "label", TYPE_void, TYPE_str},
+ {OntSubclassof, "subclassof", TYPE_void, TYPE_oid},
+ {OntAttURI, "uriatt", TYPE_void, TYPE_oid},
+ {OntAttAtt, "attribute", TYPE_void, TYPE_oid}
+};
+
+static BAT*
+create_OntologyBAT(int ht, int tt, int size)
+{
+ BAT *b = BATnew(ht, tt, size);
+ if (b == NULL) {
+ return b;
+ }
+ BATseqbase(b, 0);
+
+ /* disable all properties */
+ b->tsorted = FALSE;
+ b->tdense = FALSE;
+ b->tkey = FALSE;
+ b->hdense = TRUE;
+
+ return b;
+}
+
+static parserData*
+createOntoglogyParser (str location, BAT** graph){
+
+ int i;
+
+ parserData *pdata = (parserData *) GDKmalloc(sizeof(parserData));
+ if (pdata == NULL) return NULL;
+
+ pdata->tcount = 0;
+ pdata->exception = 0;
+ pdata->fatal = 0;
+ pdata->error = 0;
+ pdata->lasterror = 0;
+ pdata->warning = 0;
+ pdata->location = location;
+ pdata->graph = graph;
+
+ for (i = 0; i < N_ONTOLOGY_BAT; i++) {
+ pdata->graph[i] = NULL;
+ pdata->graph[i] = create_OntologyBAT (
+ ontBatdef[i].headType,
+ ontBatdef[i].tailType,
+ batsz); /* TODO: estimate
size */
+ if (pdata->graph[i] == NULL) {
+ return NULL;
+ }
+ }
+
+ return pdata;
+
+}
+
+static void
+clean(parserData *pdata){
+ int iret;
+ if (pdata != NULL) {
+ for (iret = 0; iret < N_ONTOLOGY_BAT; iret++) {
+ if (pdata->graph[iret] != NULL)
+ BBPreclaim(pdata->graph[iret]);
+ }
+
+ GDKfree(pdata);
+ }
+}
+
+static void
+tripleHandler(void* user_data, const raptor_statement* triple)
+{
+ parserData *pdata = ((parserData *) user_data);
+ //BUN bun = BUN_NONE;
+ //BAT **graph = pdata->graph;
+ printf("%s %s
%s\n",raptor_term_to_string(triple->subject),raptor_term_to_string(triple->predicate),raptor_term_to_string(triple->object));
+ pdata->tcount++;
+ return;
+}
+
+str
+RDFOntologyParser(int *xret, str *location, str *schema){
+
+ raptor_parser *ontparser;
+ parserData *pdata;
+ raptor_uri *uri;
+ bit isURI;
+ str ret;
+ int iret;
+ raptor_world *world;
+
+ BAT *graph[N_ONTOLOGY_BAT];
+
+ printf("Loading ontology from %s to %s schema \n", *location, *schema);
+
+ /* init tokenizer */
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list