Commits

David McClosky committed 752e1ec

second-stage/programs/features: Add test program for Java SWIG bindings
New Makefile target is "make swig-java-test".

  • Participants
  • Parent commits 2f9ac82

Comments (0)

Files changed (2)

File second-stage/programs/features/Makefile

 
 # Edit these variables as needed
 SWIG_RERANKER_MODULE_NAME ?= SWIGReranker
-SWIG_JAVA_PACKAGE ?= ${SWIG_RERANKER_MODULE_NAME}
+SWIG_JAVA_PACKAGE ?= ''
 
 SWIG_OBJS = simple-api.o heads.o read-tree.o sym.o
 
 		swig/java/lib/lib$(SWIG_RERANKER_MODULE_NAME).so \
 		$(SWIG_OBJS) swig/build/java_wrapper.o
 
+.PHONY: swig-java-test
+swig-java-test: swig-java
+	javac swig/java/lib/*.java
+	javac -cp swig/java/lib/ swig/java/test/*.java
+	java -cp swig/java/lib:swig/java/test -Djava.library.path=swig/java/lib test
+
 .PHONY: swig-python
 swig-python: swig/python/lib/_$(SWIG_RERANKER_MODULE_NAME).so
 
 	gcc $(SWIG_LINKER_FLAGS) -shared $(SWIG_OBJS) \
 		swig/build/python_wrapper.o -o swig/python/lib/_$(SWIG_RERANKER_MODULE_NAME).so
 
-.PHONY: swig-python
+.PHONY: swig-python-test
 swig-python-test: swig-python
 	PYTHONPATH=swig/python/lib/ python swig/python/test/test.py
 

File second-stage/programs/features/swig/java/test/test.java

+/*
+ * Licensed 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.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class test {
+    static {
+        System.loadLibrary("SWIGReranker");
+    }
+
+    public static void main(String argv[]) throws Exception {
+        System.out.println("top of main");
+        SWIGReranker.setOptions(0, true);
+        String modelDir = "../../models/ec50spfinal/";
+        String featuresFilename = modelDir + "features.gz";
+        String weightsFilename = modelDir + "cvlm-l1c10P1-weights.gz";
+        System.out.println("loading");
+        RerankerModel reranker = new RerankerModel(null, featuresFilename, weightsFilename);
+        System.out.println("number of features: " + reranker.getMaxid());
+        System.out.println("loaded");
+
+        String nbestListText = "2	1\n-58.4143\n(S1 (S (NP (DT This)) (VP (AUX is) (NP (DT an) (JJ n-best) (NN list))) (. .)))\n-61.6705\n(S1 (S (NP (DT This)) (VP (AUX is) (NP (DT an) (JJS n-best) (NN list))) (. .)))\n";
+
+        NBestList nbestList = SWIGReranker.readNBestList(nbestListText, false);
+        Weights scores = reranker.scoreNBestList(nbestList);
+        for (int i = 0; i < scores.size(); i++) {
+            System.out.format("score %d: %s\n", i, scores.get(i));
+        }
+    }
+}