[Groonga-commit] groonga/groonga at 4a257a5 [master] plugin functions/vector: add an experimental plugin

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Apr 9 19:36:12 JST 2015


Kouhei Sutou	2015-04-09 19:36:12 +0900 (Thu, 09 Apr 2015)

  New Revision: 4a257a58148e4f99aba24a8192d371115a5f79c0
  https://github.com/groonga/groonga/commit/4a257a58148e4f99aba24a8192d371115a5f79c0

  Message:
    plugin functions/vector: add an experimental plugin
    
    It includes the following functions:
    
      * vector_size()
    
    TODO:
    
      * Document me.
      * Improve function register API.

  Added files:
    plugins/functions/CMakeLists.txt
    plugins/functions/Makefile.am
    plugins/functions/vector.c
    plugins/functions/vector_sources.am
    test/command/suite/select/function/vector/vector_size/reference_vector.expected
    test/command/suite/select/function/vector/vector_size/reference_vector.test
    test/command/suite/select/function/vector/vector_size/vector.expected
    test/command/suite/select/function/vector/vector_size/vector.test
  Modified files:
    configure.ac
    plugins/Makefile.am

  Modified: configure.ac (+4 -0)
===================================================================
--- configure.ac    2015-04-09 14:30:30 +0900 (6b8f6da)
+++ configure.ac    2015-04-09 19:36:12 +0900 (fc6b211)
@@ -240,6 +240,7 @@ AC_CONFIG_FILES([
   plugins/ruby/Makefile
   plugins/token_filters/Makefile
   plugins/sharding/Makefile
+  plugins/functions/Makefile
   examples/Makefile
   examples/dictionary/Makefile
   examples/dictionary/edict/Makefile
@@ -1369,6 +1370,9 @@ AC_SUBST(token_filter_pluginsdir)
 sharding_pluginsdir="\${pluginsdir}/sharding"
 AC_SUBST(sharding_pluginsdir)
 
+function_pluginsdir="\${pluginsdir}/functions"
+AC_SUBST(function_pluginsdir)
+
 AC_MSG_CHECKING(for the suffix of plugin shared libraries)
 shrext_cmds=$(./libtool --config | grep '^shrext_cmds=')
 eval $shrext_cmds

  Modified: plugins/Makefile.am (+2 -1)
===================================================================
--- plugins/Makefile.am    2015-04-09 14:30:30 +0900 (92007ed)
+++ plugins/Makefile.am    2015-04-09 19:36:12 +0900 (dc39678)
@@ -5,7 +5,8 @@ SUBDIRS =					\
 	query_expanders				\
 	ruby					\
 	token_filters				\
-	sharding
+	sharding				\
+	functions
 
 EXTRA_DIST =					\
 	CMakeLists.txt

  Added: plugins/functions/CMakeLists.txt (+47 -0) 100644
===================================================================
--- /dev/null
+++ plugins/functions/CMakeLists.txt    2015-04-09 19:36:12 +0900 (c69a89a)
@@ -0,0 +1,47 @@
+# Copyright(C) 2015 Brazil
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+include_directories(
+  ${CMAKE_CURRENT_SOURCE_DIR}/../../lib
+  )
+
+set(GRN_FUNCTIONS_PLUGIN_DIR "${GRN_RELATIVE_PLUGINS_DIR}/functions")
+
+read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/stop_word_sources.am
+  STOP_WORD_SOURCES)
+add_library(stop_word_token_filter MODULE ${STOP_WORD_SOURCES})
+set_source_files_properties(${STOP_WORD_SOURCES}
+  PROPERTIES
+  COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}")
+set_target_properties(stop_word_token_filter PROPERTIES
+  PREFIX ""
+  OUTPUT_NAME "stop_word")
+target_link_libraries(stop_word_token_filter libgroonga)
+install(TARGETS stop_word_token_filter DESTINATION "${TOKEN_FILTERS_DIR}")
+
+if(GRN_WITH_LIBSTEMMER)
+  read_file_list(${CMAKE_CURRENT_SOURCE_DIR}/stem_sources.am STEM_SOURCES)
+  include_directories(${LIBSTEMMER_INCLUDE_DIRS})
+  link_directories(${LIBSTEMMER_LIBRARY_DIRS})
+  add_library(stem_token_filter MODULE ${STEM_SOURCES})
+  set_source_files_properties(${STEM_SOURCES}
+    PROPERTIES
+    COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}")
+  set_target_properties(stem_token_filter PROPERTIES
+    PREFIX ""
+    OUTPUT_NAME "stem")
+  target_link_libraries(stem_token_filter libgroonga ${LIBSTEMMER_LIBRARIES})
+  install(TARGETS stem_token_filter DESTINATION "${TOKEN_FILTERS_DIR}")
+endif()

  Added: plugins/functions/Makefile.am (+20 -0) 100644
===================================================================
--- /dev/null
+++ plugins/functions/Makefile.am    2015-04-09 19:36:12 +0900 (5d8d1d9)
@@ -0,0 +1,20 @@
+EXTRA_DIST =					\
+	CMakeLists.txt
+
+AM_CPPFLAGS =					\
+	-I$(top_builddir)			\
+	-I$(top_srcdir)/include			\
+	-I$(top_srcdir)/lib
+
+AM_LDFLAGS =					\
+	-avoid-version				\
+	-module					\
+	-no-undefined
+
+LIBS =						\
+	$(top_builddir)/lib/libgroonga.la
+
+function_plugins_LTLIBRARIES =
+function_plugins_LTLIBRARIES += vector.la
+
+include vector_sources.am

  Added: plugins/functions/vector.c (+90 -0) 100644
===================================================================
--- /dev/null
+++ plugins/functions/vector.c    2015-04-09 19:36:12 +0900 (34f7a98)
@@ -0,0 +1,90 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2015 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include <groonga/plugin.h>
+
+static grn_obj *
+func_vector_size(grn_ctx *ctx, int n_args, grn_obj **args,
+                 grn_user_data *user_data)
+{
+  grn_obj *target;
+  unsigned int size;
+  grn_obj *grn_size;
+
+  if (n_args != 1) {
+    GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
+                     "vector_size(): wrong number of arguments (%d for 1)",
+                     n_args);
+    return NULL;
+  }
+
+  target = args[0];
+  switch (target->header.type) {
+  case GRN_VECTOR :
+  case GRN_PVECTOR :
+  case GRN_UVECTOR :
+    size = grn_vector_size(ctx, target);
+    break;
+  default :
+    {
+      grn_obj inspected;
+
+      GRN_TEXT_INIT(&inspected, 0);
+      grn_inspect(ctx, target, &inspected);
+      GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT,
+                       "vector_size(): target object must be vector: <%.*s>",
+                       (int)GRN_TEXT_LEN(&inspected),
+                       GRN_TEXT_VALUE(&inspected));
+      GRN_OBJ_FIN(ctx, &inspected);
+      return NULL;
+    }
+    break;
+  }
+
+  grn_size = grn_plugin_proc_alloc(ctx, user_data, GRN_DB_UINT32, 0);
+  if (!grn_size) {
+    return NULL;
+  }
+
+  GRN_UINT32_SET(ctx, grn_size, size);
+
+  return grn_size;
+}
+
+grn_rc
+GRN_PLUGIN_INIT(grn_ctx *ctx)
+{
+  return ctx->rc;
+}
+
+grn_rc
+GRN_PLUGIN_REGISTER(grn_ctx *ctx)
+{
+  grn_rc rc = GRN_SUCCESS;
+
+  grn_proc_create(ctx, "vector_size", -1, GRN_PROC_FUNCTION, func_vector_size,
+                  NULL, NULL, 0, NULL);
+
+  return rc;
+}
+
+grn_rc
+GRN_PLUGIN_FIN(grn_ctx *ctx)
+{
+  return GRN_SUCCESS;
+}

  Added: plugins/functions/vector_sources.am (+2 -0) 100644
===================================================================
--- /dev/null
+++ plugins/functions/vector_sources.am    2015-04-09 19:36:12 +0900 (1d98e65)
@@ -0,0 +1,2 @@
+vector_la_SOURCES =				\
+	vector.c

  Added: test/command/suite/select/function/vector/vector_size/reference_vector.expected (+59 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/vector/vector_size/reference_vector.expected    2015-04-09 19:36:12 +0900 (d5324f8)
@@ -0,0 +1,59 @@
+plugin_register functions/vector
+[[0,0.0,0.0],true]
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos tags COLUMN_VECTOR Tags
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "Groonga", "tags": ["Groonga"]},
+{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]},
+{"_key": "Nothing"}
+]
+[[0,0.0,0.0],3]
+select Memos   --output_columns 'tags, vector_size(tags)'   --command_version 2
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "tags",
+          "Tags"
+        ],
+        [
+          "vector_size",
+          "Object"
+        ]
+      ],
+      [
+        [
+          "Groonga"
+        ],
+        1
+      ],
+      [
+        [
+          "Groonga",
+          "Ruby"
+        ],
+        2
+      ],
+      [
+        [
+
+        ],
+        0
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/function/vector/vector_size/reference_vector.test (+17 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/vector/vector_size/reference_vector.test    2015-04-09 19:36:12 +0900 (b7990dd)
@@ -0,0 +1,17 @@
+plugin_register functions/vector
+
+table_create Tags TABLE_PAT_KEY ShortText
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos tags COLUMN_VECTOR Tags
+
+load --table Memos
+[
+{"_key": "Groonga", "tags": ["Groonga"]},
+{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]},
+{"_key": "Nothing"}
+]
+
+select Memos \
+  --output_columns 'tags, vector_size(tags)' \
+  --command_version 2

  Added: test/command/suite/select/function/vector/vector_size/vector.expected (+57 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/vector/vector_size/vector.expected    2015-04-09 19:36:12 +0900 (f1633c4)
@@ -0,0 +1,57 @@
+plugin_register functions/vector
+[[0,0.0,0.0],true]
+table_create Memos TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos tags COLUMN_VECTOR ShortText
+[[0,0.0,0.0],true]
+load --table Memos
+[
+{"_key": "Groonga", "tags": ["Groonga"]},
+{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]},
+{"_key": "Nothing"}
+]
+[[0,0.0,0.0],3]
+select Memos   --output_columns 'tags, vector_size(tags)'   --command_version 2
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        3
+      ],
+      [
+        [
+          "tags",
+          "ShortText"
+        ],
+        [
+          "vector_size",
+          "Object"
+        ]
+      ],
+      [
+        [
+          "Groonga"
+        ],
+        1
+      ],
+      [
+        [
+          "Groonga",
+          "Ruby"
+        ],
+        2
+      ],
+      [
+        [
+
+        ],
+        0
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/function/vector/vector_size/vector.test (+15 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/vector/vector_size/vector.test    2015-04-09 19:36:12 +0900 (2b32b4f)
@@ -0,0 +1,15 @@
+plugin_register functions/vector
+
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos tags COLUMN_VECTOR ShortText
+
+load --table Memos
+[
+{"_key": "Groonga", "tags": ["Groonga"]},
+{"_key": "Rroonga", "tags": ["Groonga", "Ruby"]},
+{"_key": "Nothing"}
+]
+
+select Memos \
+  --output_columns 'tags, vector_size(tags)' \
+  --command_version 2
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index