public static void assertSemPred(String[] aExpected, Collection<SemPred> aActual) { List<String> expected = new ArrayList<String>(asList(aExpected)); List<String> actual = new ArrayList<String>(); for (SemPred p : aActual) { StringBuilder sb = new StringBuilder(); sb.append(p.getCoveredText()).append(" (").append(p.getCategory()).append("): ["); List<SemArgLink> args = new ArrayList<>(select(p.getArguments(), SemArgLink.class)); // Sort arguments by role to avoid sensitivity to unstable iteration orders in // annotation tools Comparator<SemArgLink> byRole = (a,b) -> ObjectUtils.compare(a.getRole(), b.getRole()); args.sort(byRole); for (SemArgLink a : args) { sb.append('(').append(a.getRole()).append(':') .append(a.getTarget().getCoveredText()).append(')'); } sb.append(']'); actual.add(sb.toString()); } Collections.sort(actual); Collections.sort(expected); System.out.printf("%-20s - Expected: %s%n", "Semantic predicates", asCopyableString(expected)); System.out .printf("%-20s - Actual : %s%n", "Semantic predicates", asCopyableString(actual)); assertEquals(asCopyableString(expected, true), asCopyableString(actual, true)); }
public static void assertSemPred(String[] aExpected, Collection<SemPred> aActual) { List<String> expected = new ArrayList<String>(asList(aExpected)); List<String> actual = new ArrayList<String>(); for (SemPred p : aActual) { StringBuilder sb = new StringBuilder(); sb.append(p.getCoveredText()).append(" (").append(p.getCategory()).append("): ["); List<SemArgLink> args = new ArrayList<>(select(p.getArguments(), SemArgLink.class)); // Sort arguments by role to avoid sensitivity to unstable iteration orders in // annotation tools Comparator<SemArgLink> byRole = (a,b) -> ObjectUtils.compare(a.getRole(), b.getRole()); args.sort(byRole); for (SemArgLink a : args) { sb.append('(').append(a.getRole()).append(':') .append(a.getTarget().getCoveredText()).append(')'); } sb.append(']'); actual.add(sb.toString()); } Collections.sort(actual); Collections.sort(expected); System.out.printf("%-20s - Expected: %s%n", "Semantic predicates", asCopyableString(expected)); System.out .printf("%-20s - Actual : %s%n", "Semantic predicates", asCopyableString(actual)); assertEquals(asCopyableString(expected, true), asCopyableString(actual, true)); }