Skip to content

Commit

Permalink
Remove TextContentType model (#12080)
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity authored Jun 12, 2020
1 parent eb3639c commit d70c567
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 89 deletions.
4 changes: 3 additions & 1 deletion sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Release History

## 1.0.0-beta.4 (Unreleased)

### Breaking Changes
- Rename `elements` property on model `FormTableCell` to `textContent`
- Remove `TextContentType` model and use `instanceOf` to detect the FormContent type

## 1.0.0-beta.3 (2020-06-10)
### New Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class FieldText extends FormContent {
*/
public FieldText(String text, BoundingBox boundingBox, Integer pageNumber,
final List<FormContent> textContent) {
super(text, boundingBox, pageNumber, null);
super(text, boundingBox, pageNumber);
this.textContent = textContent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,17 @@ public abstract class FormContent {
*/
private final BoundingBox boundingBox;

/*
* Form text content type.
*/
private final TextContentType textContentType;

/**
* Creates raw OCR item.
*
* @param text The text content of ExtractedField.
* @param boundingBox The BoundingBox of ExtractedField.
* @param text The text content of the field.
* @param boundingBox The BoundingBox specifying relative coordinates of the field.
* @param pageNumber the 1 based page number.
* @param textContentType The type of text content.
*/
FormContent(final String text, final BoundingBox boundingBox,
final Integer pageNumber, final TextContentType textContentType) {
this.boundingBox = boundingBox;
FormContent(final String text, final BoundingBox boundingBox, final Integer pageNumber) {
this.text = text;
this.boundingBox = boundingBox;
this.pageNumber = pageNumber;
this.textContentType = textContentType;
}

/**
Expand Down Expand Up @@ -73,13 +65,4 @@ public String getText() {
public Integer getPageNumber() {
return this.pageNumber;
}

/**
* Get the TextContent type of the FormContent.
*
* @return The TextContent type of the FormContent.
*/
public TextContentType getTextContentType() {
return this.textContentType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class FormLine extends FormContent {
*/
public FormLine(String text, BoundingBox boundingBox, Integer pageNumber,
final List<FormWord> formWords) {
super(text, boundingBox, pageNumber, TextContentType.LINE);
super(text, boundingBox, pageNumber);
this.formWords = formWords;
}

Expand All @@ -42,14 +42,6 @@ public List<FormWord> getFormWords() {
return this.formWords;
}

/**
* {@inheritDoc}
*/
@Override
public TextContentType getTextContentType() {
return super.getTextContentType();
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public final class FormTableCell extends FormContent {
private final float confidence;

/*
* When includeTextDetails is set to true, a list of references to the text
* When includeTextContent is set to true, a list of references to the text
* elements constituting this table cell.
*/
private final List<FormContent> elements;
private final List<FormContent> textContent;

/*
* Is the current cell a header cell?
Expand Down Expand Up @@ -73,15 +73,15 @@ public FormTableCell(final int rowIndex, final int columnIndex, final Integer ro
final Integer columnSpan, final String text, final BoundingBox boundingBox,
final float confidence, final boolean isHeader, final boolean isFooter, final int pageNumber,
final List<FormContent> textContent) {
super(text, boundingBox, pageNumber, null);
super(text, boundingBox, pageNumber);
this.rowIndex = rowIndex;
this.columnIndex = columnIndex;
this.rowSpan = rowSpan;
this.columnSpan = columnSpan;
this.confidence = confidence;
this.isHeader = isHeader;
this.isFooter = isFooter;
this.elements = textContent;
this.textContent = textContent;
}

/**
Expand Down Expand Up @@ -156,12 +156,12 @@ public Integer getColumnSpan() {

/**
* Get the list of references to the text elements constituting this table cell
* When includeTextDetails is set to true.
* When includeTextContent is set to true.
*
* @return the elements value.
* @return the {@code textContent} value.
*/
public List<FormContent> getElements() {
return this.elements;
public List<FormContent> getTextContent() {
return this.textContent;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class FormWord extends FormContent {
* @param confidence the confidence.
*/
public FormWord(String text, BoundingBox boundingBox, Integer pageNumber, final float confidence) {
super(text, boundingBox, pageNumber, TextContentType.WORD);
super(text, boundingBox, pageNumber);
this.confidence = confidence;
}

Expand All @@ -36,14 +36,6 @@ public float getConfidence() {
return this.confidence;
}

/**
* {@inheritDoc}
*/
@Override
public TextContentType getTextContentType() {
return super.getTextContentType();
}

/**
* {@inheritDoc}
*/
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.azure.ai.formrecognizer.models.FormWord;
import com.azure.ai.formrecognizer.models.OperationResult;
import com.azure.ai.formrecognizer.models.RecognizedForm;
import com.azure.ai.formrecognizer.models.TextContentType;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.util.polling.SyncPoller;

Expand Down Expand Up @@ -71,8 +70,8 @@ public static void main(String[] args) {
// call to beginRecognizeCustomFormsFromUrl
// It is also a list of FormWords and FormLines, but in this example, we only deal with
// FormWords
formTableCell.getElements().forEach(formContent -> {
if (formContent.getTextContentType().equals(TextContentType.WORD)) {
formTableCell.getTextContent().forEach(formContent -> {
if (formContent instanceof FormWord) {
FormWord formWordElement = (FormWord) (formContent);
StringBuilder boundingBoxStr = new StringBuilder();
if (formWordElement.getBoundingBox() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.azure.ai.formrecognizer.models.FormWord;
import com.azure.ai.formrecognizer.models.OperationResult;
import com.azure.ai.formrecognizer.models.RecognizedForm;
import com.azure.ai.formrecognizer.models.TextContentType;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.util.polling.PollerFlux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -85,8 +84,8 @@ public static void main(String[] args) {
// call to beginRecognizeCustomFormsFromUrl
// It is also a list of FormWords and FormLines, but in this example, we only deal with
// FormWords
formTableCell.getElements().forEach(formContent -> {
if (formContent.getTextContentType().equals(TextContentType.WORD)) {
formTableCell.getTextContent().forEach(formContent -> {
if (formContent instanceof FormWord) {
FormWord formWordElement = (FormWord) (formContent);
final StringBuilder boundingBoxStr = new StringBuilder();
if (formWordElement.getBoundingBox() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.azure.ai.formrecognizer.models.Point;
import com.azure.ai.formrecognizer.models.RecognizedForm;
import com.azure.ai.formrecognizer.models.RecognizedReceipt;
import com.azure.ai.formrecognizer.models.TextContentType;
import com.azure.ai.formrecognizer.training.FormTrainingClientBuilder;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.http.HttpClient;
Expand Down Expand Up @@ -131,7 +130,7 @@ private static void validateReferenceElementsData(List<String> expectedElements,
readResults.get(readResultIndex).getLines().get(lineIndex).getWords().get(wordIndex);
TextLine expectedTextLine = readResults.get(readResultIndex).getLines().get(lineIndex);

if (actualFormContentList.get(i).getTextContentType().equals(TextContentType.LINE)) {
if (actualFormContentList.get(i) instanceof FormLine) {
FormLine actualFormLine = (FormLine) actualFormContentList.get(i);
validateFormWordData(expectedTextLine.getWords(), actualFormLine.getFormWords());
}
Expand Down Expand Up @@ -173,7 +172,7 @@ private static void validateCellData(List<DataTableCell> expectedTableCells,
assertEquals(expectedTableCell.getRowSpan(), actualTableCell.getRowSpan());
validateBoundingBoxData(expectedTableCell.getBoundingBox(), actualTableCell.getBoundingBox());
if (includeTextDetails) {
validateReferenceElementsData(expectedTableCell.getElements(), actualTableCell.getElements(),
validateReferenceElementsData(expectedTableCell.getElements(), actualTableCell.getTextContent(),
readResults);
}
}
Expand Down

0 comments on commit d70c567

Please sign in to comment.