Java Code Examples for org.apache.uima.cas.text.AnnotationFS#trim()

The following examples show how to use org.apache.uima.cas.text.AnnotationFS#trim() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Test
public void thatEmptySpanIsTrimmedToEmptySpan() throws Exception {
  cas.setDocumentText("    ");
  
  AnnotationFS ann = cas.createAnnotation(cas.getAnnotationType(), 2, 2);
  ann.trim();
  
  assertThat(ann)
      .extracting(AnnotationFS::getBegin, AnnotationFS::getEnd, AnnotationFS::getCoveredText)
      .containsExactly(2, 2, "");
}
 
Example 2
Source File: AnnotationTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Test
public void thatSpanIsTrimmedToEmptySpanStartingAtOriginalStart() {
  cas.setDocumentText("    ");
    
  AnnotationFS ann = cas.createAnnotation(cas.getAnnotationType(), 2, 3);
  ann.trim();
    
  assertThat(ann)
      .extracting(AnnotationFS::getBegin, AnnotationFS::getEnd, AnnotationFS::getCoveredText)
      .containsExactly(2, 2, "");
}
 
Example 3
Source File: AnnotationTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Test
public void thatLeadingAndTrailingWhitespaceIsRemoved() {
  cas.setDocumentText(" ab ");

  AnnotationFS ann = cas.createAnnotation(cas.getAnnotationType(), 0, 4);
  ann.trim();

  assertThat(ann)
      .extracting(AnnotationFS::getBegin, AnnotationFS::getEnd, AnnotationFS::getCoveredText)
      .containsExactly(1, 3, "ab");
}
 
Example 4
Source File: AnnotationTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Test
public void thatInnerWhitespaceIsRemoved1()
{
  cas.setDocumentText(" a b ");

  AnnotationFS ann = cas.createAnnotation(cas.getAnnotationType(), 0, 2);
  ann.trim();

  assertThat(ann)
      .extracting(AnnotationFS::getBegin, AnnotationFS::getEnd, AnnotationFS::getCoveredText)
      .containsExactly(1, 2, "a");
}
 
Example 5
Source File: AnnotationTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Test
public void thatInnerWhitespaceIsRemoved2()
{
  cas.setDocumentText(" a b ");

  AnnotationFS ann = cas.createAnnotation(cas.getAnnotationType(), 2, 5);
  ann.trim();

  assertThat(ann)
      .extracting(AnnotationFS::getBegin, AnnotationFS::getEnd, AnnotationFS::getCoveredText)
      .containsExactly(3, 4, "b");
}
 
Example 6
Source File: AnnotationTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleCharacter()
{
  cas.setDocumentText(".");

  AnnotationFS ann = cas.createAnnotation(cas.getAnnotationType(), 0, 1);
  ann.trim();

  assertThat(ann)
      .extracting(AnnotationFS::getBegin, AnnotationFS::getEnd, AnnotationFS::getCoveredText)
      .containsExactly(0, 1, ".");
}
 
Example 7
Source File: AnnotationTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Test
public void testLeadingWhitespace()
{
  cas.setDocumentText(" \t\n\r.");

  AnnotationFS ann = cas.createAnnotation(cas.getAnnotationType(), 0, 5);
  ann.trim();

  assertThat(ann)
      .extracting(AnnotationFS::getBegin, AnnotationFS::getEnd, AnnotationFS::getCoveredText)
      .containsExactly(4, 5, ".");
}
 
Example 8
Source File: AnnotationTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Test
public void testTrailingWhitespace()
{
  cas.setDocumentText(". \n\r\t");

  AnnotationFS ann = cas.createAnnotation(cas.getAnnotationType(), 0, 5);
  ann.trim();

  assertThat(ann)
      .extracting(AnnotationFS::getBegin, AnnotationFS::getEnd, AnnotationFS::getCoveredText)
      .containsExactly(0, 1, ".");
}
 
Example 9
Source File: AnnotationTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Test
public void testLeadingTrailingWhitespace()
{
  cas.setDocumentText(" \t\n\r. \n\r\t");

  AnnotationFS ann = cas.createAnnotation(cas.getAnnotationType(), 0, 9);
  ann.trim();

  assertThat(ann)
      .extracting(AnnotationFS::getBegin, AnnotationFS::getEnd)
      .containsExactly(4, 5);
}
 
Example 10
Source File: AnnotationTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Test
public void testBlankString()
{
  cas.setDocumentText("   ");

  AnnotationFS ann = cas.createAnnotation(cas.getAnnotationType(), 1, 2);
  ann.trim();

  assertThat(ann)
      .extracting(AnnotationFS::getBegin, AnnotationFS::getEnd, AnnotationFS::getCoveredText)
      .containsExactly(1, 1, "");
}