Revision: 7475
Author: victormote
Date: 2006-06-08 18:10:55 -0700 (Thu, 08 Jun 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7475&view=rev
Log Message:
-----------
1. Return all values, including the negative values.
2. Return the weights.
Modified Paths:
--------------
trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java
Modified: trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java
===================================================================
--- trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-09 00:50:28 UTC (rev 7474)
+++ trunk/foray/foray-hyphen-r/src/java/org/foray/hyphenR/HyphenationTree.java 2006-06-09 01:10:55 UTC (rev 7475)
@@ -302,6 +302,7 @@
// use algorithm to get hyphenation points
int[] result = new int[len + 1];
+ byte[] values = new byte[result.length];
int k = 0;
word[0] = '.'; // word start marker
word[len + 1] = '.'; // word end marker
@@ -313,28 +314,58 @@
// hyphenation points are located where interletter value is odd
for (int i = 0; i < len; i++) {
- if (((il[i + 1] & 1) == 1) && i >= remainCharCount
+ int interletterValue = il[i + 1];
+ if (interletterValue != 0
+ && i >= remainCharCount
&& i <= (len - pushCharCount)) {
- result[k++] = i;
+ k++;
+ result[k] = i;
+ byte weight = convertLiangToWeight(interletterValue);
+ values[k] = weight;
}
}
- return createHyphenation(theWord, result, k);
+ return createHyphenation(theWord, result, values, k);
}
/**
+ * Converts the raw value from the Liang data to a weighted value.
+ * In the Liang system, 1) even values are negative, 2) odd values are
+ * positive, and the magnitude of the number conveys the magnitude of
+ * the direction.
+ * @param liangValue A value in the range 0-9 that contains the Liang
+ * algorithm weight.
+ * @return A value in the range -4 to +5 that reflects the numeric weight
+ * of the raw Liang value.
+ */
+ public static byte convertLiangToWeight(int liangValue) {
+ switch (liangValue) {
+ case 0: return 0;
+ case 1: return 1;
+ case 2: return -1;
+ case 3: return 2;
+ case 4: return -2;
+ case 5: return 3;
+ case 6: return -3;
+ case 7: return 4;
+ case 8: return -4;
+ case 9: return 5;
+ default: return 0;
+ }
+ }
+
+ /**
* @param result
* @param k
* @return The new Hyphenation instance.
*/
- private Hyphenation createHyphenation(String theWord,
- int[] result, int k) {
+ private Hyphenation createHyphenation(String theWord, int[] result,
+ byte[] values, int k) {
if (k > 0) {
// trim result array
int[] res = new int[k];
System.arraycopy(result, 0, res, 0, k);
/* TODO: values needs to be populated. Also both positive and
* negative values should be returned. */
- byte[] values = new byte[res.length];
return new Hyphenation(theWord, res, values);
}
return null;
@@ -377,7 +408,12 @@
}
}
}
- return createHyphenation(sw, result, k);
+ /* Assume that all found points have a value of 1. */
+ byte[] values = new byte[result.length];
+ for (int i = 0; i < values.length; i++) {
+ values[i] = 1;
+ }
+ return createHyphenation(sw, result, values, k);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|