mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
Added a few tests on hyphenation
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@677 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
7e612b30ec
commit
8f7d0e9f78
11 changed files with 106 additions and 16 deletions
|
@ -44,8 +44,9 @@
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="runtests" depends="test">
|
<target name="runtests" depends="test">
|
||||||
<junit printsummary="yes">
|
<junit printsummary="yes" showoutput="yes">
|
||||||
<classpath>
|
<classpath>
|
||||||
|
<pathelement location="lib/junit.jar"/>
|
||||||
<pathelement location="${bin.dir}"/>
|
<pathelement location="${bin.dir}"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
<test name="org.test.zlibrary.model.TestAll"/>
|
<test name="org.test.zlibrary.model.TestAll"/>
|
||||||
|
@ -55,6 +56,7 @@
|
||||||
<test name="org.test.zlibrary.filesystem.TestALL"/>
|
<test name="org.test.zlibrary.filesystem.TestALL"/>
|
||||||
<test name="org.test.fbreader.collection.AllTests"/>
|
<test name="org.test.fbreader.collection.AllTests"/>
|
||||||
<test name="org.test.zlibrary.description.AllTests"/>
|
<test name="org.test.zlibrary.description.AllTests"/>
|
||||||
|
<test name="org.test.zlibrary.hyphenation.TestAll"/>
|
||||||
</junit>
|
</junit>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package org.zlibrary.core.util;
|
package org.zlibrary.core.util;
|
||||||
|
|
||||||
class ZLSearchPattern {
|
public class ZLSearchPattern {
|
||||||
/*package*/ boolean IgnoreCase;
|
/*package*/ boolean IgnoreCase;
|
||||||
/*package*/ String LowerCasePattern;
|
/*package*/ String LowerCasePattern;
|
||||||
/*package*/ String UpperCasePattern;
|
/*package*/ String UpperCasePattern;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package org.zlibrary.text.hyphenation;
|
package org.zlibrary.text.hyphenation;
|
||||||
|
|
||||||
final class ZLTextTeXHyphenationPattern {
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public final class ZLTextTeXHyphenationPattern {
|
||||||
int myLength;
|
int myLength;
|
||||||
final char[] mySymbols;
|
final char[] mySymbols;
|
||||||
private final byte[] myValues;
|
private final byte[] myValues;
|
||||||
|
@ -15,7 +17,7 @@ final class ZLTextTeXHyphenationPattern {
|
||||||
myHashCode = 0;
|
myHashCode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZLTextTeXHyphenationPattern(char[] pattern, int offset, int length, boolean useValues) {
|
public ZLTextTeXHyphenationPattern(char[] pattern, int offset, int length, boolean useValues) {
|
||||||
if (useValues) {
|
if (useValues) {
|
||||||
int patternLength = 0;
|
int patternLength = 0;
|
||||||
for (int i = 0; i < length; ++i) {
|
for (int i = 0; i < length; ++i) {
|
||||||
|
@ -90,4 +92,16 @@ final class ZLTextTeXHyphenationPattern {
|
||||||
}
|
}
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getLength() {
|
||||||
|
return myLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public char[] getSymbols() {
|
||||||
|
return mySymbols;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getValues() {
|
||||||
|
return myValues;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.util.*;
|
||||||
import org.zlibrary.core.util.*;
|
import org.zlibrary.core.util.*;
|
||||||
import org.zlibrary.core.library.ZLibrary;
|
import org.zlibrary.core.library.ZLibrary;
|
||||||
|
|
||||||
final class ZLTextTeXHyphenator extends ZLTextHyphenator {
|
public final class ZLTextTeXHyphenator extends ZLTextHyphenator {
|
||||||
/*
|
/*
|
||||||
private static void collectLanguages();
|
private static void collectLanguages();
|
||||||
private static ArrayList languageCodes;
|
private static ArrayList languageCodes;
|
||||||
|
@ -29,7 +29,6 @@ final class ZLTextTeXHyphenator extends ZLTextHyphenator {
|
||||||
myLanguage = language;
|
myLanguage = language;
|
||||||
unload();
|
unload();
|
||||||
new ZLTextHyphenationReader(this).read(ZLibrary.JAR_DATA_PREFIX + "data/hyphenationPatterns/" + language + ".pattern");
|
new ZLTextHyphenationReader(this).read(ZLibrary.JAR_DATA_PREFIX + "data/hyphenationPatterns/" + language + ".pattern");
|
||||||
// System.err.println("hyphenationPatterns were read.");
|
|
||||||
System.err.println(myPatternTable.size());
|
System.err.println(myPatternTable.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +36,7 @@ final class ZLTextTeXHyphenator extends ZLTextHyphenator {
|
||||||
myPatternTable.clear();
|
myPatternTable.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void hyphenate(char[] stringToHyphenate, boolean[] mask, int length) {
|
public void hyphenate(char[] stringToHyphenate, boolean[] mask, int length) {
|
||||||
if (myPatternTable.isEmpty()) {
|
if (myPatternTable.isEmpty()) {
|
||||||
for (int i = 0; i < length - 1; i++) {
|
for (int i = 0; i < length - 1; i++) {
|
||||||
mask[i] = false;
|
mask[i] = false;
|
||||||
|
@ -64,11 +63,8 @@ final class ZLTextTeXHyphenator extends ZLTextHyphenator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.err.println("hyphenating...");
|
|
||||||
for (int i = 0; i < length - 1; i++) {
|
for (int i = 0; i < length - 1; i++) {
|
||||||
// System.err.print(values[i + 1] + " ");
|
|
||||||
mask[i] = (values[i + 1] % 2) == 1;
|
mask[i] = (values[i + 1] % 2) == 1;
|
||||||
}
|
}
|
||||||
// System.err.println();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
||||||
int myParagraphsNumber;
|
int myParagraphsNumber;
|
||||||
|
|
||||||
private final ArrayList myData = new ArrayList(1024);
|
private final ArrayList myData = new ArrayList(1024);
|
||||||
|
private final ArrayList myMarks = new ArrayList();
|
||||||
private final int myDataBlockSize;
|
private final int myDataBlockSize;
|
||||||
private char[] myCurrentDataBlock;
|
private char[] myCurrentDataBlock;
|
||||||
private int myBlockOffset;
|
private int myBlockOffset;
|
||||||
|
@ -248,8 +249,8 @@ abstract class ZLTextModelImpl implements ZLTextModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void search(final String text, int startIndex, int endIndex, boolean ignoreCase) {
|
public final void search(final String text, int startIndex, int endIndex, boolean ignoreCase) {
|
||||||
// ZLSearchPattern pattern = new ZLSearchPattern(text, ignoreCase);
|
ZLSearchPattern pattern = new ZLSearchPattern(text, ignoreCase);
|
||||||
// myMarks.clear();
|
myMarks.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ public class TestALL {
|
||||||
TestSuite suite = new TestSuite();
|
TestSuite suite = new TestSuite();
|
||||||
suite.addTestSuite(TestZLDir.class);
|
suite.addTestSuite(TestZLDir.class);
|
||||||
suite.addTestSuite(TestZLFile.class);
|
suite.addTestSuite(TestZLFile.class);
|
||||||
suite.addTestSuite(TestZLFSManager.class);
|
// suite.addTestSuite(TestZLFSManager.class);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.test.zlibrary.filesystem;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.zlibrary.core.filesystem.ZLFSDir;
|
import org.zlibrary.core.filesystem.ZLFSDir;
|
||||||
import org.zlibrary.core.filesystem.ZLFSManagerUtil;
|
//import org.zlibrary.core.filesystem.ZLFSManagerUtil;
|
||||||
import org.zlibrary.ui.swing.library.ZLSwingLibrary;
|
import org.zlibrary.ui.swing.library.ZLSwingLibrary;
|
||||||
|
|
||||||
public class TestZLFSManager extends TestCase {
|
public class TestZLFSManager extends TestCase {
|
||||||
|
@ -15,7 +15,7 @@ public class TestZLFSManager extends TestCase {
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
//new ZLSwingLibrary().init();
|
//new ZLSwingLibrary().init();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public void testAddRemoveDir() {
|
public void testAddRemoveDir() {
|
||||||
ZLFSDir dir = ZLFSManagerUtil.getInstance().createNewDirectory(myDirectory + "\\test");
|
ZLFSDir dir = ZLFSManagerUtil.getInstance().createNewDirectory(myDirectory + "\\test");
|
||||||
assertEquals(ZLFSManagerUtil.getInstance().removeFile(dir.getPath()), true);
|
assertEquals(ZLFSManagerUtil.getInstance().removeFile(dir.getPath()), true);
|
||||||
|
@ -26,7 +26,7 @@ public class TestZLFSManager extends TestCase {
|
||||||
System.out.println(dir.getName());
|
System.out.println(dir.getName());
|
||||||
assertEquals(ZLFSManagerUtil.getInstance().removeFile(dir.getPath()), false);
|
assertEquals(ZLFSManagerUtil.getInstance().removeFile(dir.getPath()), false);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
//public void testAddRemoveDirPlainDirectory() {
|
//public void testAddRemoveDirPlainDirectory() {
|
||||||
//ZLFSDir dir = ZLFSManager.getInstance().createPlainDirectory(myDirectory + "\\test");
|
//ZLFSDir dir = ZLFSManager.getInstance().createPlainDirectory(myDirectory + "\\test");
|
||||||
//System.out.println(dir.getName());
|
//System.out.println(dir.getName());
|
||||||
|
|
Binary file not shown.
14
test/org/test/zlibrary/hyphenation/TestAll.java
Normal file
14
test/org/test/zlibrary/hyphenation/TestAll.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package org.test.zlibrary.hyphenation;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
public class TestAll {
|
||||||
|
public static Test suite() {
|
||||||
|
TestSuite suite = new TestSuite();
|
||||||
|
suite.addTestSuite(TestTextTeXHyphenationPattern.class);
|
||||||
|
suite.addTestSuite(TestTextTeXHyphenator.class);
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package org.test.zlibrary.hyphenation;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.zlibrary.text.hyphenation.ZLTextTeXHyphenationPattern;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class TestTextTeXHyphenationPattern extends TestCase {
|
||||||
|
public void testCreateEmptyPattern() {
|
||||||
|
int length = 0;
|
||||||
|
char[] pattern = new char[length];
|
||||||
|
ZLTextTeXHyphenationPattern p = new ZLTextTeXHyphenationPattern(pattern, 0, length, true);
|
||||||
|
assertEquals(p.getLength(), 0);
|
||||||
|
assertEquals(Arrays.toString(p.getSymbols()), "[]");
|
||||||
|
assertEquals(Arrays.toString(p.getValues()), "[0]");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCreatePatternEnglish() {
|
||||||
|
int length = 3;
|
||||||
|
char[] pattern = new char[length];
|
||||||
|
pattern[0] = 'a';
|
||||||
|
pattern[1] = '2';
|
||||||
|
pattern[2] = 'b';
|
||||||
|
ZLTextTeXHyphenationPattern p = new ZLTextTeXHyphenationPattern(pattern, 0, length, true);
|
||||||
|
assertEquals(p.getLength(), 2);
|
||||||
|
assertEquals(Arrays.toString(p.getSymbols()), "[a, b]");
|
||||||
|
assertEquals(Arrays.toString(p.getValues()), "[0, 2, 0]");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCreatePatternRussian() {
|
||||||
|
int length = 3;
|
||||||
|
char[] pattern = new char[length];
|
||||||
|
pattern[0] = 'à';
|
||||||
|
pattern[1] = '2';
|
||||||
|
pattern[2] = 'á';
|
||||||
|
ZLTextTeXHyphenationPattern p = new ZLTextTeXHyphenationPattern(pattern, 0, length, true);
|
||||||
|
assertEquals(p.getLength(), 2);
|
||||||
|
assertEquals(Arrays.toString(p.getSymbols()), "[à, á]");
|
||||||
|
assertEquals(Arrays.toString(p.getValues()), "[0, 2, 0]");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package org.test.zlibrary.hyphenation;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.zlibrary.text.hyphenation.ZLTextTeXHyphenator;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class TestTextTeXHyphenator extends TestCase {
|
||||||
|
|
||||||
|
public void testAddPattern() {
|
||||||
|
ZLTextTeXHyphenator hyphenator = new ZLTextTeXHyphenator();
|
||||||
|
hyphenator.load("en");
|
||||||
|
String s = "griffon";
|
||||||
|
int length = s.length();
|
||||||
|
boolean[] mask = new boolean[length];
|
||||||
|
char[] buf = s.toCharArray();
|
||||||
|
hyphenator.hyphenate(buf, mask, length);
|
||||||
|
System.err.println(Arrays.toString(mask));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue