lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [03/13] lucy git commit: Tune and test PolyAnalyzer Go bindings.
Date Tue, 24 Nov 2015 23:38:25 GMT
Tune and test PolyAnalyzer Go bindings.


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

Branch: refs/heads/master
Commit: cc7219e69aaab7aa215ed6c39106d89a7df7ee83
Parents: 19921d8
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Mon Nov 9 17:42:08 2015 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Fri Nov 20 16:43:37 2015 -0800

----------------------------------------------------------------------
 go/build.go              |  5 +++++
 go/lucy/analysis.go      | 22 ++++++++++++++++++++++
 go/lucy/analysis_test.go |  4 ++++
 3 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/cc7219e6/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 6060f5b..05231fc 100644
--- a/go/build.go
+++ b/go/build.go
@@ -145,6 +145,11 @@ func specClasses(parcel *cfc.Parcel) {
 	analyzerBinding.SpecMethod("Split", "Split(string) []string")
 	analyzerBinding.Register()
 
+	polyAnalyzerBinding := cfc.NewGoClass(parcel, "Lucy::Analysis::PolyAnalyzer")
+	polyAnalyzerBinding.SpecMethod("Get_Analyzers", "GetAnalyzers() []Analyzer")
+	polyAnalyzerBinding.SetSuppressCtor(true)
+	polyAnalyzerBinding.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/cc7219e6/go/lucy/analysis.go
----------------------------------------------------------------------
diff --git a/go/lucy/analysis.go b/go/lucy/analysis.go
index 61465b4..68a379c 100644
--- a/go/lucy/analysis.go
+++ b/go/lucy/analysis.go
@@ -20,6 +20,7 @@ package lucy
 #include <stdlib.h>
 
 #include "Lucy/Analysis/Analyzer.h"
+#include "Lucy/Analysis/PolyAnalyzer.h"
 #include "Lucy/Analysis/Token.h"
 #include "Clownfish/Vector.h"
 */
@@ -59,3 +60,24 @@ func (a *AnalyzerIMP) Split(text string) []string {
 	defer C.cfish_decref(unsafe.Pointer(retvalCF))
 	return vecToStringSlice(retvalCF)
 }
+
+func NewPolyAnalyzer(children []Analyzer) PolyAnalyzer {
+	vec := clownfish.NewVector(len(children))
+	for i := 0; i < len(children); i++ {
+		vec.Push(children[i])
+	}
+	retvalCF := C.lucy_PolyAnalyzer_new(nil, (*C.cfish_Vector)(clownfish.Unwrap(vec, "vec")))
+	return WRAPPolyAnalyzer(unsafe.Pointer(retvalCF))
+}
+
+func (p *PolyAnalyzerIMP) GetAnalyzers() []Analyzer {
+	self := (*C.lucy_PolyAnalyzer)(clownfish.Unwrap(p, "p"))
+	retvalCF := C.LUCY_PolyAnalyzer_Get_Analyzers(self)
+	size := C.CFISH_Vec_Get_Size(retvalCF)
+	retval := make([]Analyzer, int(size))
+	for i := 0; i < int(size); i++ {
+		child := unsafe.Pointer(C.CFISH_Vec_Fetch(retvalCF, C.size_t(i)))
+		retval[i] = clownfish.WRAPAny(unsafe.Pointer(C.cfish_incref(child))).(Analyzer)
+	}
+	return retval
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/cc7219e6/go/lucy/analysis_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/analysis_test.go b/go/lucy/analysis_test.go
index 9470fbb..d9d9f2f 100644
--- a/go/lucy/analysis_test.go
+++ b/go/lucy/analysis_test.go
@@ -105,6 +105,10 @@ func TestCoreAnalyzers(t *testing.T) {
 	runAnalyzerTests(t, NewSnowballStemmer("en"))
 	runAnalyzerTests(t, NewSnowballStopFilter("en", nil))
 	runAnalyzerTests(t, NewStandardTokenizer())
+
+	children := []Analyzer{NewStandardTokenizer(), NewNormalizer("NFKC", true, false)}
+	polyAnalyzer := NewPolyAnalyzer(children)
+	runAnalyzerTests(t, polyAnalyzer)
 }
 
 func TestRegexTokenizerSplit(t *testing.T) {


Mime
View raw message