Customize Analyzer#Split for Go.

Return a slice of strings rather than a slice of empty interface.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/094b76eb
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/094b76eb
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/094b76eb

Branch: refs/heads/master
Commit: 094b76ebfd217278c40873cf4505344dc4c09e12
Parents: 4f7227e
Author: Marvin Humphrey <[email protected]>
Authored: Tue Oct 6 18:41:58 2015 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Tue Oct 6 18:44:17 2015 -0700

----------------------------------------------------------------------
 go/build.go              |  4 ++++
 go/lucy/analysis.go      | 16 ++++++++++++++++
 go/lucy/analysis_test.go |  2 +-
 3 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/094b76eb/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index b265c2b..77263ee 100644
--- a/go/build.go
+++ b/go/build.go
@@ -141,6 +141,10 @@ func specClasses(parcel *cfc.Parcel) {
        tokenBinding.SpecMethod("", "GetText() string")
        tokenBinding.Register()
 
+       analyzerBinding := cfc.NewGoClass(parcel, "Lucy::Analysis::Analyzer")
+       analyzerBinding.SpecMethod("Split", "Split(string) []string")
+       analyzerBinding.Register()
+
        indexerBinding := cfc.NewGoClass(parcel, "Lucy::Index::Indexer")
        indexerBinding.SpecMethod("", "Close() error")
        indexerBinding.SpecMethod("Add_Doc", "AddDoc(doc interface{}) error")

http://git-wip-us.apache.org/repos/asf/lucy/blob/094b76eb/go/lucy/analysis.go
----------------------------------------------------------------------
diff --git a/go/lucy/analysis.go b/go/lucy/analysis.go
index 53cb3d9..134c081 100644
--- a/go/lucy/analysis.go
+++ b/go/lucy/analysis.go
@@ -19,7 +19,9 @@ package lucy
 /*
 #include <stdlib.h>
 
+#include "Lucy/Analysis/Analyzer.h"
 #include "Lucy/Analysis/Token.h"
+#include "Clownfish/Vector.h"
 */
 import "C"
 import "unsafe"
@@ -48,3 +50,17 @@ func (t *TokenIMP) GetText() string {
        size := C.LUCY_Token_Get_Len(self)
        return C.GoStringN(chars, C.int(size))
 }
+
+func (a *AnalyzerIMP) Split(text string) []string {
+       self := (*C.lucy_Analyzer)(clownfish.Unwrap(a, "a"))
+       input := (*C.cfish_String)(clownfish.GoToClownfish(text, 
unsafe.Pointer(C.CFISH_STRING), false))
+       defer C.cfish_decref(unsafe.Pointer(input))
+       retvalCF := C.LUCY_Analyzer_Split(self, input)
+       size := C.CFISH_Vec_Get_Size(retvalCF)
+       retvalGO := make([]string, int(size))
+       for i := 0; i < int(size); i++ {
+               elem := C.CFISH_Vec_Fetch(retvalCF, C.size_t(i))
+               retvalGO[i] = clownfish.CFStringToGo(unsafe.Pointer(elem))
+       }
+       return retvalGO
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/094b76eb/go/lucy/analysis_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/analysis_test.go b/go/lucy/analysis_test.go
index 300ae4c..65a8403 100644
--- a/go/lucy/analysis_test.go
+++ b/go/lucy/analysis_test.go
@@ -65,7 +65,7 @@ func TestInversionBasics(t *testing.T) {
 
 func TestRegexTokenizerSplit(t *testing.T) {
        tokenizer := NewRegexTokenizer("\\S+")
-       var expected []interface{} = []interface{}{"foo", "bar", "baz"}
+       expected := []string{"foo", "bar", "baz"}
        got := tokenizer.Split("foo bar baz")
        if !reflect.DeepEqual(got, expected) {
                t.Errorf("Expected %v, got %v", expected, got)

Reply via email to