summaryrefslogtreecommitdiff
path: root/src/runtime/haskell-bind/SG.hsc
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2015-12-20 14:04:52 +0000
committerkrasimir <krasimir@chalmers.se>2015-12-20 14:04:52 +0000
commitbef9d8c5fce740fde65934b170cca33b121fde67 (patch)
tree8a8c86569cd4ea329f3c5a5a9caefdcdf36211c3 /src/runtime/haskell-bind/SG.hsc
parent0b9395fd7006592d0434503751a88ef95ab47603 (diff)
added a primitive full-text search index in libsg. This can be use for finding an abstract tree whose linearization matches given keywords
Diffstat (limited to 'src/runtime/haskell-bind/SG.hsc')
-rw-r--r--src/runtime/haskell-bind/SG.hsc32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/runtime/haskell-bind/SG.hsc b/src/runtime/haskell-bind/SG.hsc
index 3f7baa5fd..5ee02b8b2 100644
--- a/src/runtime/haskell-bind/SG.hsc
+++ b/src/runtime/haskell-bind/SG.hsc
@@ -8,6 +8,8 @@ module SG( SG, openSG, closeSG
, beginTrans, commit, rollback, inTransaction
, SgId
, insertExpr, getExpr
+ , updateFtsIndex
+ , queryLinearization
, readTriple, showTriple
, insertTriple, getTriple
, queryTriple
@@ -106,6 +108,36 @@ getExpr (SG sg) id = do
return Nothing
else do return $ Just (Expr c_expr exprFPl)
+updateFtsIndex :: SG -> PGF -> IO ()
+updateFtsIndex (SG sg) p = do
+ withGuPool $ \tmpPl -> do
+ exn <- gu_new_exn tmpPl
+ sg_update_fts_index sg (pgf p) exn
+ handle_sg_exn exn
+
+queryLinearization :: SG -> String -> IO [Expr]
+queryLinearization (SG sg) query = do
+ exprPl <- gu_new_pool
+ exprFPl <- newForeignPtr gu_pool_finalizer exprPl
+ (withCString query $ \c_query ->
+ withGuPool $ \tmpPl -> do
+ exn <- gu_new_exn tmpPl
+ seq <- sg_query_linearization sg c_query tmpPl exn
+ handle_sg_exn exn
+ len <- (#peek GuSeq, len) seq
+ ids <- peekArray (fromIntegral (len :: CInt)) (seq `plusPtr` (#offset GuSeq, data))
+ getExprs exprFPl exprPl exn ids)
+ where
+ getExprs exprFPl exprPl exn [] = return []
+ getExprs exprFPl exprPl exn (id:ids) = do
+ c_expr <- sg_get_expr sg id exprPl exn
+ handle_sg_exn exn
+ if c_expr == nullPtr
+ then getExprs exprFPl exprPl exn ids
+ else do let e = Expr c_expr exprFPl
+ es <- getExprs exprFPl exprPl exn ids
+ return (e:es)
+
-----------------------------------------------------------------------
-- Triples