Skip to content

Commit

Permalink
AutoML: Add support for documents (via synth). (#9039)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored and busunkim96 committed Aug 26, 2019
1 parent 05e7255 commit 86bb5cf
Show file tree
Hide file tree
Showing 10 changed files with 779 additions and 91 deletions.
59 changes: 59 additions & 0 deletions automl/google/cloud/automl_v1beta1/gapic/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,65 @@ class TypeCode(enum.IntEnum):
CATEGORY = 10


class Document(object):
class Layout(object):
class TextSegmentType(enum.IntEnum):
"""
The type of TextSegment in the context of the original document.
Attributes:
TEXT_SEGMENT_TYPE_UNSPECIFIED (int): Should not be used.
TOKEN (int): The text segment is a token. e.g. word.
PARAGRAPH (int): The text segment is a paragraph.
FORM_FIELD (int): The text segment is a form field.
FORM_FIELD_NAME (int): The text segment is the name part of a form field. It will be treated as
child of another FORM\_FIELD TextSegment if its span is subspan of
another TextSegment with type FORM\_FIELD.
FORM_FIELD_CONTENTS (int): The text segment is the text content part of a form field. It will be
treated as child of another FORM\_FIELD TextSegment if its span is
subspan of another TextSegment with type FORM\_FIELD.
TABLE (int): The text segment is a whole table, including headers, and all rows.
TABLE_HEADER (int): The text segment is a table's headers. It will be treated as child of
another TABLE TextSegment if its span is subspan of another TextSegment
with type TABLE.
TABLE_ROW (int): The text segment is a row in table. It will be treated as child of
another TABLE TextSegment if its span is subspan of another TextSegment
with type TABLE.
TABLE_CELL (int): The text segment is a cell in table. It will be treated as child of
another TABLE\_ROW TextSegment if its span is subspan of another
TextSegment with type TABLE\_ROW.
"""

TEXT_SEGMENT_TYPE_UNSPECIFIED = 0
TOKEN = 1
PARAGRAPH = 2
FORM_FIELD = 3
FORM_FIELD_NAME = 4
FORM_FIELD_CONTENTS = 5
TABLE = 6
TABLE_HEADER = 7
TABLE_ROW = 8
TABLE_CELL = 9


class DocumentDimensions(object):
class DocumentDimensionUnit(enum.IntEnum):
"""
Unit of the document dimension.
Attributes:
DOCUMENT_DIMENSION_UNIT_UNSPECIFIED (int): Should not be used.
INCH (int): Document dimension is measured in inches.
CENTIMETER (int): Document dimension is measured in centimeters.
POINT (int): Document dimension is measured in points. 72 points = 1 inch.
"""

DOCUMENT_DIMENSION_UNIT_UNSPECIFIED = 0
INCH = 1
CENTIMETER = 2
POINT = 3


class Model(object):
class DeploymentState(enum.IntEnum):
"""
Expand Down
126 changes: 122 additions & 4 deletions automl/google/cloud/automl_v1beta1/proto/data_items.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ syntax = "proto3";

package google.cloud.automl.v1beta1;

import "google/api/annotations.proto";
import "google/cloud/automl/v1beta1/geometry.proto";
import "google/cloud/automl/v1beta1/io.proto";
import "google/cloud/automl/v1beta1/text_segment.proto";
import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/struct.proto";
import "google/api/annotations.proto";

option go_package = "google.golang.org/genproto/googleapis/cloud/automl/v1beta1;automl";
option java_multiple_files = true;
Expand Down Expand Up @@ -56,19 +58,135 @@ message TextSnippet {
// characters long.
string content = 1;

// Optional. The format of [content][google.cloud.automl.v1beta1.TextSnippet.content]. Currently the only two allowed
// values are "text/html" and "text/plain". If left blank, the format is
// automatically determined from the type of the uploaded [content][google.cloud.automl.v1beta1.TextSnippet.content].
// Optional. The format of
// [content][google.cloud.automl.v1beta1.TextSnippet.content]. Currently the
// only two allowed values are "text/html" and "text/plain". If left blank,
// the format is automatically determined from the type of the uploaded
// [content][google.cloud.automl.v1beta1.TextSnippet.content].
string mime_type = 2;

// Output only. HTTP URI where you can download the content.
string content_uri = 4;
}

// Message that describes dimension of a document.
message DocumentDimensions {
// Unit of the document dimension.
enum DocumentDimensionUnit {
// Should not be used.
DOCUMENT_DIMENSION_UNIT_UNSPECIFIED = 0;

// Document dimension is measured in inches.
INCH = 1;

// Document dimension is measured in centimeters.
CENTIMETER = 2;

// Document dimension is measured in points. 72 points = 1 inch.
POINT = 3;
}

// Unit of the dimension.
DocumentDimensionUnit unit = 1;

// Width value of the document, works together with the unit.
float width = 2;

// Height value of the document, works together with the unit.
float height = 3;
}

// A structured text document e.g. a PDF.
message Document {
// Describes the layout information of a
// [text_segment][google.cloud.automl.v1beta1.Document.Layout.text_segment] in
// the document.
message Layout {
// The type of TextSegment in the context of the original document.
enum TextSegmentType {
// Should not be used.
TEXT_SEGMENT_TYPE_UNSPECIFIED = 0;

// The text segment is a token. e.g. word.
TOKEN = 1;

// The text segment is a paragraph.
PARAGRAPH = 2;

// The text segment is a form field.
FORM_FIELD = 3;

// The text segment is the name part of a form field. It will be treated
// as child of another FORM_FIELD TextSegment if its span is subspan of
// another TextSegment with type FORM_FIELD.
FORM_FIELD_NAME = 4;

// The text segment is the text content part of a form field. It will be
// treated as child of another FORM_FIELD TextSegment if its span is
// subspan of another TextSegment with type FORM_FIELD.
FORM_FIELD_CONTENTS = 5;

// The text segment is a whole table, including headers, and all rows.
TABLE = 6;

// The text segment is a table's headers. It will be treated as child of
// another TABLE TextSegment if its span is subspan of another TextSegment
// with type TABLE.
TABLE_HEADER = 7;

// The text segment is a row in table. It will be treated as child of
// another TABLE TextSegment if its span is subspan of another TextSegment
// with type TABLE.
TABLE_ROW = 8;

// The text segment is a cell in table. It will be treated as child of
// another TABLE_ROW TextSegment if its span is subspan of another
// TextSegment with type TABLE_ROW.
TABLE_CELL = 9;
}

// Text Segment that represents a segment in
// [document_text][google.cloud.automl.v1beta1.Document.document_text].
TextSegment text_segment = 1;

// Page number of the
// [text_segment][google.cloud.automl.v1beta1.Document.Layout.text_segment]
// in the original document, starts from 1.
int32 page_number = 2;

// The position of the
// [text_segment][google.cloud.automl.v1beta1.Document.Layout.text_segment]
// in the page. Contains exactly 4
//
// [normalized_vertices][google.cloud.automl.v1beta1.BoundingPoly.normalized_vertices]
// and they are connected by edges in the order provided, which will
// represent a rectangle parallel to the frame. The
// [NormalizedVertex-s][google.cloud.automl.v1beta1.NormalizedVertex] are
// relative to the page.
// Coordinates are based on top-left as point (0,0).
BoundingPoly bounding_poly = 3;

// The type of the
// [text_segment][google.cloud.automl.v1beta1.Document.Layout.text_segment]
// in document.
TextSegmentType text_segment_type = 4;
}

// An input config specifying the content of the document.
DocumentInputConfig input_config = 1;

// The plain text version of this document.
TextSnippet document_text = 2;

// Describes the layout of the document.
// Sorted by [page_number][].
repeated Layout layout = 3;

// The dimensions of the page in the document.
DocumentDimensions document_dimensions = 4;

// Number of pages in the document.
int32 page_count = 5;
}

// A representation of a row in a relational table.
Expand Down
Loading

0 comments on commit 86bb5cf

Please sign in to comment.