Repository: lucy
Updated Branches:
  refs/heads/master 245ed3b36 -> 61d45291a


Customize Go binding for Token.

Hand-roll bindings for constructor, SetText, and GetText.  Add basic
tests.


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

Branch: refs/heads/master
Commit: 7dd69a6bbb82216da5dfb243c67c532af8c1c8df
Parents: 64156f4
Author: Marvin Humphrey <mar...@rectangular.com>
Authored: Tue Oct 6 13:41:25 2015 -0700
Committer: Marvin Humphrey <mar...@rectangular.com>
Committed: Tue Oct 6 18:44:16 2015 -0700

----------------------------------------------------------------------
 go/lucy/analysis.go      | 50 +++++++++++++++++++++++++++++++++++++++++++
 go/lucy/analysis_test.go | 19 ++++++++++++++++
 2 files changed, 69 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/7dd69a6b/go/lucy/analysis.go
----------------------------------------------------------------------
diff --git a/go/lucy/analysis.go b/go/lucy/analysis.go
new file mode 100644
index 0000000..53cb3d9
--- /dev/null
+++ b/go/lucy/analysis.go
@@ -0,0 +1,50 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package lucy
+
+/*
+#include <stdlib.h>
+
+#include "Lucy/Analysis/Token.h"
+*/
+import "C"
+import "unsafe"
+
+import 
"git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
+
+func NewToken(text string) Token {
+       chars := C.CString(text)
+       defer C.free(unsafe.Pointer(chars))
+       size := C.size_t(len(text))
+       objC := C.lucy_Token_new(chars, size, 0, 0, 1.0, 1)
+       return WRAPToken(unsafe.Pointer(objC))
+}
+
+func (t *TokenIMP) SetText(text string) {
+       self := (*C.lucy_Token)(clownfish.Unwrap(t, "t"))
+       chars := C.CString(text)
+       defer C.free(unsafe.Pointer(chars))
+       size := C.size_t(len(text))
+       C.LUCY_Token_Set_Text(self, chars, size)
+}
+
+func (t *TokenIMP) GetText() string {
+       self := (*C.lucy_Token)(clownfish.Unwrap(t, "t"))
+       chars := C.LUCY_Token_Get_Text(self)
+       size := C.LUCY_Token_Get_Len(self)
+       return C.GoStringN(chars, C.int(size))
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/7dd69a6b/go/lucy/analysis_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/analysis_test.go b/go/lucy/analysis_test.go
index 26a30d5..2ae7a34 100644
--- a/go/lucy/analysis_test.go
+++ b/go/lucy/analysis_test.go
@@ -19,6 +19,25 @@ package lucy
 import "testing"
 import "reflect"
 
+func TestTokenBasics(t *testing.T) {
+       token := NewToken("foo")
+       if got := token.GetText(); got != "foo" {
+               t.Errorf("GetText: %v", got)
+       }
+       token.SetText("bar")
+       if got := token.GetText(); got != "bar" {
+               t.Errorf("SetText/GetText: %v", got)
+       }
+
+       // Verify that these were bound.
+       token.GetStartOffset()
+       token.GetEndOffset()
+       token.GetBoost()
+       token.GetPosInc()
+       token.GetPos()
+       token.GetLen()
+}
+
 func TestRegexTokenizerSplit(t *testing.T) {
        tokenizer := NewRegexTokenizer("\\S+")
        var expected []interface{} = []interface{}{"foo", "bar", "baz"}

Reply via email to