Add reshaper test

This commit is contained in:
Victor Shcherb 2020-06-11 11:58:19 +02:00
parent b974c1123f
commit cdf795c6af
4 changed files with 85 additions and 23 deletions

View file

@ -354,6 +354,7 @@ public class NativeLibrary {
FileInputStream fis = new FileInputStream(f); FileInputStream fis = new FileInputStream(f);
Algorithms.streamCopy(fis, ous); Algorithms.streamCopy(fis, ous);
fis.close(); fis.close();
System.out.println("FONT " + name);
initFontType(ous.toByteArray(), name.substring(0, name.length() - 4), name.toLowerCase().contains("bold"), initFontType(ous.toByteArray(), name.substring(0, name.length() - 4), name.toLowerCase().contains("bold"),
name.toLowerCase().contains("italic")); name.toLowerCase().contains("italic"));
} catch (IOException e) { } catch (IOException e) {

View file

@ -20,14 +20,18 @@ public class Reshaper {
return ""; return "";
} }
} }
public static String reshape(String s) { public static String reshape(String s) {
try { try {
ArabicShaping as = new ArabicShaping(ArabicShaping.LETTERS_SHAPE |ArabicShaping.LENGTH_GROW_SHRINK); ArabicShaping as = new ArabicShaping(ArabicShaping.LETTERS_SHAPE |
ArabicShaping.LENGTH_GROW_SHRINK);
//printSplit("B", s);
try { try {
s = as.shape(s); s = as.shape(s);
} catch (ArabicShapingException e) { } catch (ArabicShapingException e) {
LOG.error(e.getMessage(), e); LOG.error(e.getMessage(), e);
} }
//printSplit("A", s);
Bidi line = new Bidi(s.length(), s.length()); Bidi line = new Bidi(s.length(), s.length());
line.setPara(s, Bidi.LEVEL_DEFAULT_LTR, null); line.setPara(s, Bidi.LEVEL_DEFAULT_LTR, null);
// line.setPara(s, Bidi.LEVEL_DEFAULT_LTR, null); // line.setPara(s, Bidi.LEVEL_DEFAULT_LTR, null);
@ -96,33 +100,27 @@ public class Reshaper {
return ch; return ch;
} }
public static void main(String[] args) { public static void main(String[] args) {
// char[] c = new char[] {'א', 'ד','ם', ' ', '1', '2'} ;
// String reshape = "אדם";
// char[] c = new char[] {'א', 'ד','ם'} ;
// String reshape = reshape(new String(c));
// for (int i = 0; i < reshape.length(); i++) {
// System.out.println(reshape.charAt(i));
// }
test2(); test2();
test3(); test3();
test4(); test4();
test5(); test5();
} }
private static void test3() { public static void test3() {
String s = "מרכז מסחרי/השלום (40050)"; String s = "מרכז מסחרי/השלום (40050)";
String reshape = reshape(s); String reshape = reshape(s);
String expected = "(40050) םולשה/ירחסמ זכרמ"; String expected = "(40050) םולשה/ירחסמ זכרמ";
check(s, reshape, expected); check(s, reshape, expected);
} }
private static void test5() { public static void test5() {
String s = "מרכז מסחרי/השלום (מרז)"; String s = "מרכז מסחרי/השלום (מרז)";
String reshape = reshape(s); String reshape = reshape(s);
String expected = "(זרמ) םולשה/ירחסמ זכרמ"; String expected = "(זרמ) םולשה/ירחסמ זכרמ";
check(s, reshape, expected); check(s, reshape, expected);
} }
private static void check(String source, String reshape, String expected) {
public static void check(String source, String reshape, String expected) {
printSplit("Source ", source); printSplit("Source ", source);
printSplit("Expected", expected); printSplit("Expected", expected);
printSplit("Reshaped", reshape); printSplit("Reshaped", reshape);
@ -131,19 +129,28 @@ public class Reshaper {
throw new IllegalArgumentException(String.format("Bug: expected '%s', reshaped '%s'", expected, reshape)); throw new IllegalArgumentException(String.format("Bug: expected '%s', reshaped '%s'", expected, reshape));
} }
} }
private static void printSplit(String p, String source) {
static void printSplit(String p, String source) {
printSplit(p, source, true);
printSplit(p, source, false);
}
static void printSplit(String p, String source, boolean f) {
System.out.print(p); System.out.print(p);
System.out.print(": \u2066"); System.out.print(": \u2066");
for(int i = 0; i < source.length(); i++) { for (int i = 0; i < source.length(); i++) {
System.out.print(source.charAt(i)); if (f) {
System.out.print(" \u200e"); System.out.print(source.charAt(i));
System.out.print(" \u200e");
} else {
System.out.print(String.format("%04x ", (int) source.charAt(i)));
}
} }
// System.out.println(Arrays.toString(source.toCharArray())); // System.out.println(Arrays.toString(source.toCharArray()));
System.out.println(); System.out.println();
System.out.flush(); System.out.flush();
} }
private static void test2() { public static void test2() {
String s = "گچ پژ نمکی باللغة العربي"; String s = "گچ پژ نمکی باللغة العربي";
String reshape = reshape(s); String reshape = reshape(s);
String expected1 = "ﻲﺑﺮﻌﻟﺍ ﺔﻐﻠﻟﺎﺑ ﯽﮑﻤﻧ ﮋﭘ ﭻﮔ"; String expected1 = "ﻲﺑﺮﻌﻟﺍ ﺔﻐﻠﻟﺎﺑ ﯽﮑﻤﻧ ﮋﭘ ﭻﮔ";
@ -151,7 +158,7 @@ public class Reshaper {
check(s, reshape, expected1); check(s, reshape, expected1);
} }
private static void test4() { public static void test4() {
String s = "Abc (123)"; String s = "Abc (123)";
check(s, reshape(s), s); check(s, reshape(s), s);
} }

View file

@ -810,14 +810,12 @@ public class BinaryRoutePlanner {
printRoad(">?", visitedSegments.get(calculateRoutePointId(next, next.isPositive())), printRoad(">?", visitedSegments.get(calculateRoutePointId(next, next.isPositive())),
next.isPositive()); next.isPositive());
} }
if (distFromStart < next.distanceFromStart) {
if (ctx.config.heuristicCoefficient <= 1) {
System.err.println("! Alert distance from start " + distFromStart + " < "
+ next.distanceFromStart + " id=" + next.road.id);
}
}
if (distFromStart < visIt.distanceFromStart && next.getParentRoute() == null) { if (distFromStart < visIt.distanceFromStart && next.getParentRoute() == null) {
toAdd = true; toAdd = true;
if (ctx.config.heuristicCoefficient <= 1) {
System.err.println("! Alert distance from start " + distFromStart + " < "
+ visIt.distanceFromStart + " id=" + next.road.id);
}
} else { } else {
toAdd = false; toAdd = false;
} }

View file

@ -0,0 +1,56 @@
package net.osmand;
import java.text.Normalizer;
import org.junit.Test;
import com.ibm.icu.text.ArabicShaping;
import com.ibm.icu.text.ArabicShapingException;
import com.ibm.icu.text.Bidi;
import net.osmand.Reshaper;
public class ReShaperTest {
//
// Source : ه ە ی ب ە
// Expected: ه ە ی ب ە
// Reshaped: ە ە
@Test
public void testArabName() throws ArabicShapingException {
// https://www.compart.com/en/unicode/U+FCD8
// String source = "\uFEEB\u06d5";
// System.out.println(new ArabicShaping(0).shape(s));
// System.out.println("\uFEEB\u06d5");
String source = "هەیبە";
String expected = "ەﺐﯾەﻩ";
String res = Reshaper.reshape(source);
Reshaper.check(source, res, expected);
}
@Test
public void test2() throws ArabicShapingException {
Reshaper.test2();
}
@Test
public void test3() throws ArabicShapingException {
Reshaper.test3();
}
@Test
public void test4() throws ArabicShapingException {
Reshaper.test4();
}
@Test
public void test5() throws ArabicShapingException {
Reshaper.test5();
}
}