Changeset: db631d067a69 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=db631d067a69
Modified Files:
        monetdb5/extras/rdf/rdfalgebra.c
        monetdb5/extras/rdf/rdfschema.c
        monetdb5/extras/rdf/rdfschema.h
        monetdb5/modules/mal/tokenizer.c
        monetdb5/modules/mal/tokenizer.h
Branch: rdf
Log Message:

Build BAT mapping original oid to converted oid.

BAT: original oid created from Tokenizer maps to converted oid.


diffs (238 lines):

diff --git a/monetdb5/extras/rdf/rdfalgebra.c b/monetdb5/extras/rdf/rdfalgebra.c
--- a/monetdb5/extras/rdf/rdfalgebra.c
+++ b/monetdb5/extras/rdf/rdfalgebra.c
@@ -137,6 +137,7 @@ RDFpartialjoin(bat *retid, bat *lid, bat
        
        result = BATproject(result2, right); 
        result->T->nil = 0; 
+       
 
        BBPreleaseref(left->batCacheid);
        BBPreleaseref(right->batCacheid);
diff --git a/monetdb5/extras/rdf/rdfschema.c b/monetdb5/extras/rdf/rdfschema.c
--- a/monetdb5/extras/rdf/rdfschema.c
+++ b/monetdb5/extras/rdf/rdfschema.c
@@ -37,6 +37,7 @@
 #include <mtime.h>
 #include <rdfgraph.h>
 #include <rdfparams.h>
+#include "bat5.h"
 
 #define SHOWPROPERTYNAME 1
 
@@ -11243,6 +11244,74 @@ str RDFdistTriplesToCSs(int *ret, bat *s
        return MAL_SUCCEED; 
 }
 
+#if BUILDTOKENZIER_TO_MAPID 
+/*
+ * Since the of s,p,o oids are converted to table-based oids,
+ * a bat that maps original tokenizer oids to the converted oid
+ * need to be built. Then, when it comes a string, it can first look
+ * at the tokenizer for its original oid. After that, it can
+ * use this TKNZRMappingBat for receiving the converted Id. 
+ * 
+ * Input String --> Original TKNZR oid --> New Oid (TKNRZ_to_new_MapBAT)
+ * New oid --> Original TKNZR oid --> Input String (New_to_TKNZR_MapBat)
+ * */
+static 
+str buildTKNZRMappingBat(BAT *lmap, BAT *rmap){
+
+       BAT     *tmpBat = NULL; 
+       char*   schema = "rdf";
+       int     ret; 
+       int     num = 0; 
+       bat     mapBatId; 
+       BAT     *mapBat;        
+       str     batname = NULL; 
+
+       if (TKNZRopen (NULL, &schema) != MAL_SUCCEED) {
+               throw(RDF, "rdf.rdfschema",
+                               "could not open the tokenizer\n");
+       }
+       
+       TKNZRgetTotalCount(&num);
+       //create a tmpBat from 0 to number of TKNZR items
+       tmpBat = BATnew(TYPE_void, TYPE_oid , num + 1, TRANSIENT);
+       BATsetcount(tmpBat,num);
+       BATseqbase(tmpBat, 0);
+       BATseqbase(BATmirror(tmpBat), 0);
+
+       tmpBat->T->nonil = 1;
+       tmpBat->tkey = 1;
+       tmpBat->tsorted = 1;
+       tmpBat->trevsorted = 0;
+       tmpBat->tdense = 1;
+
+
+       if (RDFpartialjoin(&mapBatId, &lmap->batCacheid, &rmap->batCacheid, 
&tmpBat->batCacheid) != MAL_SUCCEED){
+               throw(RDF, "rdf.RDFreorganize", "Problem in using 
RDFpartialjoin for tokenizer map bat");
+       }
+
+       if ((mapBat = BATdescriptor(mapBatId)) == NULL) {
+               throw(MAL, "rdf.RDFreorganize", RUNTIME_OBJECT_MISSING);
+       }
+       
+       batname = (str) GDKmalloc(50 * sizeof(char));
+       snprintf(batname, 50, "tknzr_to_map");
+
+       if (BKCsetName(&ret, (int *) &(mapBat->batCacheid), (str *) &batname) 
!= MAL_SUCCEED)
+               throw(MAL, "tokenizer.open", OPERATION_FAILED);
+       /*
+       if (BKCsetPersistent(&ret, (int *) &(mapBat->batCacheid) != MAL_SUCCEED)
+               throw(MAL, "tokenizer.open", OPERATION_FAILED);
+               */
+
+       GDKfree(batname);
+
+       TKNZRclose(&ret);
+       
+       return MAL_SUCCEED; 
+}
+
+#endif /* BUILDTOKENZIER_TO_MAPID*/
+
 str
 RDFreorganize(int *ret, CStableStat *cstablestat, CSPropTypes **csPropTypes, 
bat *sbatid, bat *pbatid, bat *obatid, bat *mapbatid, bat *ontbatid, int 
*freqThreshold, int *mode){
 
@@ -11561,6 +11630,10 @@ RDFreorganize(int *ret, CStableStat *cst
        #endif
        //BATprint(VIEWcreate(BATmirror(lmap),rmap)); 
        
+       #if BUILDTOKENZIER_TO_MAPID
+       buildTKNZRMappingBat(lmap, rmap); 
+       #endif
+       
        origobat = getOriginalUriOBat(obat);    //Return obat without 
type-specific information for URI & BLANKNODE
                                                //This is to get the same oid 
as the subject oid for a same URI, BLANKNODE
                                                //--> There will be no 
BLANKNODE indication in this obat object oid. 
@@ -11582,6 +11655,7 @@ RDFreorganize(int *ret, CStableStat *cst
        else
                throw(RDF, "rdf.RDFreorganize", "Problem in using 
RDFpartialjoin for obat");
 
+       
        printf("Done! \n");
        printf("Sort triple table according to P, S, O order ... ");
        if (triplesubsort(&pNewBat, &sNewBat, &oNewBat) != MAL_SUCCEED){
diff --git a/monetdb5/extras/rdf/rdfschema.h b/monetdb5/extras/rdf/rdfschema.h
--- a/monetdb5/extras/rdf/rdfschema.h
+++ b/monetdb5/extras/rdf/rdfschema.h
@@ -298,6 +298,9 @@ typedef struct SubCSSet{
                                        // However, for creating the foreign 
key relationship, we add this column and 
                                        // markt it as a primary key
 
+#define BUILDTOKENZIER_TO_MAPID        1       /* Build the BAT storing the 
mapping between the
+                                       original tokenizer oid of a URI and 
converted oid */
+
 
 typedef struct CSset{
        CS* items;
diff --git a/monetdb5/modules/mal/tokenizer.c b/monetdb5/modules/mal/tokenizer.c
--- a/monetdb5/modules/mal/tokenizer.c
+++ b/monetdb5/modules/mal/tokenizer.c
@@ -458,6 +458,26 @@ TKNZRdepositFile(int *r, str *fnme)
 
 str
 TKNZRlocate(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{      
+       str ret; 
+       oid id; 
+       (void) cntxt;
+       (void) mb;
+
+       if (TRANS == NULL)
+               throw(MAL, "tokenizer", "no tokenizer store open");
+
+       ret = TKNRstringToOid(&id, (str *) getArgReference(stk, pci, 1));
+       if (ret == MAL_SUCCEED) {
+               VALset(getArgReference(stk, pci, 0), TYPE_oid, &id);
+       }
+       return MAL_SUCCEED;
+}
+
+/*
+ * This is similar to the  TKNRlocate function */
+
+str TKNRstringToOid(oid *id, str *s)
 {
        oid pos;
        str url;
@@ -466,19 +486,11 @@ TKNZRlocate(Client cntxt, MalBlkPtr mb, 
        BUN p;
        oid prv = 0;
        oid comp;
-       (void) cntxt;
-       (void) mb;
 
-       if (TRANS == NULL)
-               throw(MAL, "tokenizer", "no tokenizer store open");
 
-       url = (str) GDKmalloc(sizeof(char) *
-                       (strlen(*(str *) getArgReference(stk, pci, 1)) + 1));
-       if (url == NULL) {
-               throw(MAL, "tokenizer.locate", MAL_MALLOC_FAIL);
+       if ((url = GDKstrdup(*s)) == NULL) {
+               throw(MAL, "tokenizer.append", OPERATION_FAILED 
MAL_MALLOC_FAIL);
        }
-       strcpy(url, *(str *) getArgReference(stk, pci, 1));
-
 
        depth = TKNZRtokenize(url, parts, '/');
 
@@ -509,11 +521,11 @@ TKNZRlocate(Client cntxt, MalBlkPtr mb, 
                }
        }
 
-       VALset(getArgReference(stk, pci, 0), TYPE_oid, &pos);
+       *id = pos;
+
        GDKfree(url);
        return MAL_SUCCEED;
 }
-
 str
 takeOid(oid id, str *val)
 {
@@ -651,6 +663,7 @@ TKNZRgetLevel(int *r, int *level)
        return MAL_SUCCEED;
 }
 
+
 str
 TKNZRgetCount(int *r)
 {
@@ -675,8 +688,21 @@ TKNZRgetCount(int *r)
        BBPkeepref(*r);
        return MAL_SUCCEED;
 }
+/*
+ * Get total number of the strings in the tokenizer
+ * */
 
 str
+TKNZRgetTotalCount(int *r){
+
+       if (TRANS == NULL)
+               throw(MAL, "tokenizer", "no tokenizer store open");
+
+       *r = BATcount(tokenBAT[INDEX].val); 
+
+       return MAL_SUCCEED; 
+}
+str
 TKNZRgetCardinality(int *r)
 {
        BAT *b, *en;
diff --git a/monetdb5/modules/mal/tokenizer.h b/monetdb5/modules/mal/tokenizer.h
--- a/monetdb5/modules/mal/tokenizer.h
+++ b/monetdb5/modules/mal/tokenizer.h
@@ -45,6 +45,8 @@ tokenizer_export str TKNZRgetCount      
 tokenizer_export str TKNZRgetCardinality   (int *r);
 tokenizer_export str takeOid              (oid id, str *val);                  
 tokenizer_export str takeOid2             (oid id, str *val);                  
        
-tokenizer_export int TKNZRtokenize     (str in, str *parts, char tkn);         
                        
+tokenizer_export int TKNZRtokenize        (str in, str *parts, char tkn);      
                
+tokenizer_export str TKNRstringToOid       (oid *id, str *s);                  
+tokenizer_export str TKNZRgetTotalCount           (int *r);
 
 #endif /* _TKNZR_H */
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to