Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Commit

Permalink
ResultIterator can't return choices with custom level (closes #119)
Browse files Browse the repository at this point in the history
ChoicesIterator always return only list of alternatives of symbol, it doesn't let us specify different PageIteratorLevel here. So this commit removes the method parameter and renames the whole method to make more sense.
  • Loading branch information
Robyer committed May 11, 2017
1 parent 3bda8b1 commit af9fc83
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void testChoiceIterator() {
List<Pair<String, Double>> choicesAndConfidences;
iterator.begin();
do {
choicesAndConfidences = iterator.getChoicesAndConfidence(PageIteratorLevel.RIL_SYMBOL);
choicesAndConfidences = iterator.getSymbolChoicesAndConfidence();
assertNotNull("Invalid result.", choicesAndConfidences);

for (Pair<String, Double> choiceAndConfidence : choicesAndConfidences) {
Expand Down
11 changes: 5 additions & 6 deletions tess-two/jni/com_googlecode_tesseract_android/resultiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,20 @@ jfloat Java_com_googlecode_tesseract_android_ResultIterator_nativeConfidence(JNI
return (jfloat) resultIterator->Confidence(enumLevel);
}

jobjectArray Java_com_googlecode_tesseract_android_ResultIterator_nativeGetChoices(JNIEnv *env,
jobject thiz, jlong nativeResultIterator, jint level) {
jobjectArray Java_com_googlecode_tesseract_android_ResultIterator_nativeGetSymbolChoices(JNIEnv *env,
jobject thiz, jlong nativeResultIterator) {

// Get the actual result iterator and level (as C objects)
PageIteratorLevel enumLevel = (PageIteratorLevel) level;
// Get the actual result iterator (as C object)
ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator;

// Create a choice iterator to determine to the number of alternatives
// Create a choice iterator to determine the number of alternatives
tesseract::ChoiceIterator ci(*resultIterator);
int numberOfAlternatives = 0;
do {
numberOfAlternatives++;
} while (ci.Next());

// Create a string array to hold the results
// Create a string array to hold the choices
jobjectArray ret = (jobjectArray) env->NewObjectArray(numberOfAlternatives, env->FindClass("java/lang/String"), env->NewStringUTF(""));

// Save each result to the output array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@ public float confidence(int level) {
* The default matching text is blank ("").
* The default confidence level is zero (0.0)
*
* @param level the page iterator level. See {@link PageIteratorLevel}.
* @return A list of pairs with the UTF string and the confidence
* @return A list of pairs with the UTF symbol and the confidence
*/
public List<Pair<String, Double>> getChoicesAndConfidence(int level) {
public List<Pair<String, Double>> getSymbolChoicesAndConfidence() {
// Get the native choices
String[] nativeChoices = nativeGetChoices(mNativeResultIterator, level);
String[] nativeChoices = nativeGetSymbolChoices(mNativeResultIterator);

// Create the output list
ArrayList<Pair<String, Double>> pairedResults = new ArrayList<Pair<String, Double>>();
Expand Down Expand Up @@ -121,7 +120,7 @@ public void delete() {
nativeDelete(mNativeResultIterator);
}

private static native String[] nativeGetChoices(long nativeResultIterator, int level);
private static native String[] nativeGetSymbolChoices(long nativeResultIterator);

private static native String nativeGetUTF8Text(long nativeResultIterator, int level);
private static native float nativeConfidence(long nativeResultIterator, int level);
Expand Down

0 comments on commit af9fc83

Please sign in to comment.