From 7d26a502050836784010cabae6acedee8aa9a46c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kim=20Nguy=E1=BB=85n?= Date: Fri, 12 Oct 2012 16:04:45 +0200 Subject: [PATCH] Add a test program for experimenting with lexicographic indices. --- src/lexindex_stub.cpp | 76 ++++++++++++++++++++++++++++++++++++++++ src/lextest.ml | 35 ++++++++++++++++++ src/libcamlshredder.clib | 1 + 3 files changed, 112 insertions(+) create mode 100644 src/lexindex_stub.cpp create mode 100644 src/lextest.ml diff --git a/src/lexindex_stub.cpp b/src/lexindex_stub.cpp new file mode 100644 index 0000000..a09216e --- /dev/null +++ b/src/lexindex_stub.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include "xml-tree.hpp" +#include "utils_stub.hpp" + + +//define a type for the lexicographic index + +class lex_index { +public: + //The tag ID + xml_tree::tag_t tag; + //The text data + std::vector > data; +}; + + + +using namespace SXSI; + + +static xml_tree*& XMLTREE(value v) +{ + return Obj_val(v); +} + +static lex_index*& LEXINDEX(value v) +{ + return Obj_val(v); +} + +static xml_tree::node_t TREENODE(value i) +{ + return static_cast(Int_val(i)); +} + +static xml_tree::tag_t TAG(value i) +{ + return static_cast(Int_val(i)); +} + + + + +extern "C" value caml_build_lex_index(value vtree, value vtag) +{ + CAMLparam2(vtree, vtag); + CAMLlocal1(vindex); + vindex = sxsi_alloc_custom(); + xml_tree * tree = XMLTREE(vtree); + xml_tree::tag_t tag = TAG(vtag); + + //Uncomment the following and comment the failwith line + //LEXINDEX(vindex) = ... return a lex_index* .... + + + caml_failwith("build_lex_index not implemented"); + + + CAMLreturn (vindex); +} + +extern "C" value caml_print_lex_index(value vindex) +{ + CAMLparam1(vindex); + lex_index* index = LEXINDEX(vindex); + + //Print the index to the terminal + + caml_failwith("print_lex_index not implemented"); + + + CAMLreturn (Val_unit); +} diff --git a/src/lextest.ml b/src/lextest.ml new file mode 100644 index 0000000..0c297ca --- /dev/null +++ b/src/lextest.ml @@ -0,0 +1,35 @@ +(* Abstract type for the index, generated from C++ code *) + +type index + +external build_lex_index : Tree.t -> Tag.t -> index = "caml_build_lex_index" +external print_lex_index : index -> unit = "caml_print_lex_index" + + +let main () = + if Array.length Sys.argv != 3 then + let () = Printf.eprintf "Error: invalid argument" in exit 1 + else + let file = Sys.argv.(1) in + (* Load the index or the xml file *) + Printf.printf "Loading document\n%!"; + let document = + if Filename.check_suffix file ".srx" + then Tree.load file + else if Filename.check_suffix file ".xml" then Tree.parse_xml_uri file + else + let () = Printf.eprintf "Error: unrecognized extension" in exit 2 + in + Printf.printf "Building lex index\n%!"; + let index = build_lex_index document (Tag.tag Sys.argv.(2)) in + Printf.printf "Printing lex index\n%!"; + print_lex_index index; + exit 0 + + +let () = + try + main () + with + e -> Printf.eprintf "Fatal error: %s" (Printexc.to_string e); exit 3 + diff --git a/src/libcamlshredder.clib b/src/libcamlshredder.clib index 7dc17cf..001a22c 100644 --- a/src/libcamlshredder.clib +++ b/src/libcamlshredder.clib @@ -3,3 +3,4 @@ bp_stub.o xml-tree-builder_stub.o xml-tree_stub.o common_stub.o +lexindex_stub.o -- 2.17.1