Przeglądaj źródła

Add nsm_update to store.

scossu 5 dni temu
rodzic
commit
ab74430600
3 zmienionych plików z 35 dodań i 17 usunięć
  1. 1 0
      src/lua_graph.c
  2. 20 6
      src/lua_store.c
  3. 14 11
      test.lua

+ 1 - 0
src/lua_graph.c

@@ -27,6 +27,7 @@ static int l_graph_new (lua_State *L)
 
     // TODO Make store ID, nsm and initial size accessible.
     *gp = LSUP_graph_new (store, uri_str, NULL);
+    LOG_DEBUG ("New graph URI @%p: %s", *gp, LSUP_graph_uri (*gp)->data);
     LUA_NLCHECK (*gp, "Error creating graph.");
 
     return 1;

+ 20 - 6
src/lua_store.c

@@ -14,13 +14,10 @@ static int l_store_new (lua_State *L)
     const LSUP_StoreInt *sif = LSUP_store_int (store_type);
     LUA_NLCHECK (sif, "No interface defined for store type: %d.", store_type);
 
-    *store_p = LSUP_store_new (store_type, id, 0);
-    LUA_NLCHECK (*store_p, "Error creating back end store.");
-
     // Set up the store if a function for that is defined.
     if (clear) log_info ("Clearing old store.");
-    if (sif->setup_fn) LUA_PCHECK (
-            sif->setup_fn (id, clear), "Error initializing back end store.");
+    *store_p = LSUP_store_new (store_type, id, 0, clear);
+    LUA_NLCHECK (*store_p, "Error creating back end store.");
 
     return 1;
 }
@@ -38,6 +35,22 @@ static int store_gc (lua_State *L)
 }
 
 
+static int l_store_nsm_update (lua_State *L)
+{
+    const LSUP_Store *store = *(LSUP_Store **) luaL_checkudata (
+            L, 1, "LSUP.Store");
+    const char *pfx = luaL_checkstring (L, 2);
+    const char *ns = luaL_checkstring (L, 3);
+
+    if (store->sif->nsm_update_fn)
+        LUA_PCHECK (
+                store->sif->nsm_update_fn (store->data, pfx, ns, NULL),
+                "Error adding namespace to NS map");
+
+    return 0;
+}
+
+
 static int l_store_tostring (lua_State *L)
 {
     const LSUP_Store *store = *(LSUP_Store **) luaL_checkudata (
@@ -57,7 +70,6 @@ static int l_store_tostring (lua_State *L)
 
 static const luaL_Reg store_lib_fn [] = {
     {"new", l_store_new},
-    {"__gc", store_gc},
 
     {NULL}
 };
@@ -67,6 +79,8 @@ static const luaL_Reg store_lib_meth [] = {
     {"__gc", store_gc},
     {"__tostring", l_store_tostring},
 
+    {"nsm_update", l_store_nsm_update},
+
     {NULL}
 };
 

+ 14 - 11
test.lua

@@ -25,13 +25,13 @@ triples = {
 
 mdb_store = store.new(store.MDB, "file:///tmp/lsup_lua.db", true)
 print(("MDB store: %s"):format(mdb_store))
-gr1 = graph.new(mdb_store)
+local gr1 = graph.new(mdb_store)
 
 ct = gr1:add(triples)
 print("Triples added: " .. ct)
 ---[[
-gr2 = graph.new(mdb_store)  -- LMDB-backed
-gr3 = graph.new()  -- hashmap-backed
+local gr2 = graph.new(mdb_store)  -- LMDB-backed
+local gr3 = graph.new()  -- hashmap-backed
 gr1:copy(gr2)
 gr1:copy(gr3)
 assert(gr1 == gr2)
@@ -62,7 +62,7 @@ tset = gr1:term_set(t2, triple.POS_P, t1, triple.POS_S)
 for t in pairs(tset) do print(t) end
 --]]
 
-nsm = namespace.new()
+local nsm = namespace.new()
 nsm:add("ns1", "urn:ns:1#")
 nsm:add("ns2", "urn:ns:2#")
 nsm:add("ns3", "urn:ns:3#")
@@ -74,14 +74,17 @@ assert(nsm_map.ns2 == "urn:ns:2#")
 assert(nsm_map.ns3 == "urn:ns:3#")
 
 local mdb_store_ns = store.new(store.MDB, "file:///tmp/lsup_nsm.db", true)
+mdb_store_ns:nsm_update("ns1", "urn:ns:1#")
+mdb_store_ns:nsm_update("ns2", "urn:ns:2#")
+mdb_store_ns:nsm_update("ns3", "urn:ns:3#")
 
-local gr2 = graph.new(mdb_store_ns, "ns1:gr2")
-local gr3 = graph.new(mdb_store_ns, "ns1:gr3")
-local gr4 = graph.new(mdb_store_ns, "ns1:gr4")
-local gr5 = graph.new(mdb_store_ns, "ns1:gr5")
-gr2:add(triples)
-gr3:add(triples)
-gr4:add(triples)
+local mdb_gr2 = graph.new(mdb_store_ns, "ns1:gr2")
+local mdb_gr3 = graph.new(mdb_store_ns, "ns1:gr3")
+local mdb_gr4 = graph.new(mdb_store_ns, "ns1:gr4")
+local mdb_gr5 = graph.new(mdb_store_ns, "ns1:gr5")
+mdb_gr2:add(triples)
+mdb_gr3:add(triples)
+mdb_gr4:add(triples)
 
 local idx = graph.list(mdb_store_ns)
 assert(#idx == 3)