Esempio n. 1
0
  /**
   * For the given interval on the underlying data, get the corresponding interval on this level.
   *
   * <p>Example: 11 11 11 111 12 012 34567 8901 23 45 678 90 AD |111|22ZZ2|3333|44|55|YYY|55|
   *
   * <p>UL |111|XX|22|ZZ|2|XXXXX|3333|XX|44|XXXX|5555|XXXX| 012 34 56 78 9 11111 1111 12 22 2222
   * 2223 3333 01234 5678 90 12 3456 7890 1234
   *
   * <p>As you can see there is a YYY inserted in the AD. Otherwise some parts of the UL (marked
   * "X") have been removed in the AD. Also an ZZ part has been added to UL
   *
   * <p>Calling this method with getStart()=22 getEnd()=30 ("4XXXX555") should return [13, 20]
   * ("455YYY5").
   *
   * <p>Generally: - if the getStart() is within a deleted region, then find the next oblique
   * segment in AD to the right and return its getStart() position. - if the getEnd() is within a
   * deleted region, then find the next oblique segment in AD to the left and return its getEnd()
   * position.
   *
   * <p>Anchors are always in UL. They are referenced from the ObliqueSegments in AD.
   */
  @Test
  public void testInverseResolve() {
    bottom = new AlignedString("111XX222XXXXX3333XX44XXXX5555XXXX");
    bottom.insert(7, "ZZ");
    assertEquals("111XX22ZZ2XXXXX3333XX44XXXX5555XXXX", bottom.get());

    top = new AlignedString(bottom);
    top.delete(31, 35);
    assertEquals("111XX22ZZ2XXXXX3333XX44XXXX5555", top.get());
    top.delete(23, 27);
    assertEquals("111XX22ZZ2XXXXX3333XX445555", top.get());
    top.delete(19, 21);
    assertEquals("111XX22ZZ2XXXXX3333445555", top.get());
    top.delete(10, 15);
    assertEquals("111XX22ZZ23333445555", top.get());
    top.delete(3, 5);
    assertEquals("11122ZZ23333445555", top.get());
    top.insert(16, "YYY");
    assertEquals("11122ZZ233334455YYY55", top.get());

    final ImmutableInterval uli = new ImmutableInterval(22, 30);
    System.out.println("ULI    : " + bottom.get(uli.getStart(), uli.getEnd()));

    final ImmutableInterval adi = top.inverseResolve(uli);
    System.out.println("ADI   : " + top.get(adi.getStart(), adi.getEnd()));

    assertEquals(new ImmutableInterval(13, 20), adi);
    assertEquals("455YYY5", top.get(adi.getStart(), adi.getEnd()));
    assertEquals("4XXXX555", bottom.get(uli.getStart(), uli.getEnd()));
  }
Esempio n. 2
0
  /**
   * This is how you would expect to do hypenation removal, but it's wrong - use method used in
   * testInsert2. This here will not work, because AlignedString will try to interpolate the start
   * position of the uli interval (18) within the replaced interval (16-22).
   */
  @Test
  @Ignore("Wrong method to do hypenation removal")
  public void testInsert3() {
    //	          0123456789012345678901234567890
    baseString = "This is a hyphen- ated sentence";
    bottom = new AlignedString(baseString);
    top = new AlignedString(bottom);

    top.replace(16, 22, "ated");

    ImmutableInterval uli = new ImmutableInterval(18, 31);
    Interval adi = top.inverseResolve(uli);
    System.out.println("ADI    : " + top.get(adi.getStart(), adi.getEnd()));
    System.out.println("ULI    : " + bottom.get(uli.getStart(), uli.getEnd()));

    assertEquals(" sentence", top.get(adi.getStart(), adi.getEnd()));
  }
Esempio n. 3
0
  @Test
  public void testInsert2() {
    //            0123456789012345678901234567890
    baseString = "This is a hyphen- ated sentence";
    bottom = new AlignedString(baseString);
    top = new AlignedString(bottom);

    System.out.println("Delete word fragment");
    final String fragment = top.get(18, 22);
    top.delete(18, 22);
    System.out.println("Top    : " + top.get() + " - " + top.dataSegmentsToString());
    System.out.println("Bottom : " + bottom.get() + " - " + bottom.dataSegmentsToString());

    System.out.println("Insert word fragment to complete word");
    top.insert(16, fragment);
    System.out.println("Top    : " + top.get() + " - " + top.dataSegmentsToString());
    System.out.println("Bottom : " + bottom.get() + " - " + bottom.dataSegmentsToString());

    System.out.println("Delete hyphen");
    top.delete(16 + fragment.length(), 18 + fragment.length());
    System.out.println("Top    : " + top.get() + " - " + top.dataSegmentsToString());
    System.out.println("Bottom : " + bottom.get() + " - " + bottom.dataSegmentsToString());

    ImmutableInterval uli = new ImmutableInterval(0, 18);
    ImmutableInterval adi = top.inverseResolve(uli);
    System.out.println("ADI    : " + top.get(adi.getStart(), adi.getEnd()));
    System.out.println("ULI    : " + bottom.get(uli.getStart(), uli.getEnd()));

    assertEquals("This is a hyphenated", top.get(adi.getStart(), adi.getEnd()));

    uli = new ImmutableInterval(18, 31);
    adi = top.inverseResolve(uli);
    System.out.println("ADI    : " + top.get(adi.getStart(), adi.getEnd()));
    System.out.println("ULI    : " + bottom.get(uli.getStart(), uli.getEnd()));

    assertEquals(" sentence", top.get(adi.getStart(), adi.getEnd()));
  }