document.proto 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.cloud.documentai.v1beta2;
  16. import "google/api/field_behavior.proto";
  17. import "google/cloud/documentai/v1beta2/geometry.proto";
  18. import "google/rpc/status.proto";
  19. import "google/type/color.proto";
  20. option csharp_namespace = "Google.Cloud.DocumentAI.V1Beta2";
  21. option go_package = "google.golang.org/genproto/googleapis/cloud/documentai/v1beta2;documentai";
  22. option java_multiple_files = true;
  23. option java_outer_classname = "DocumentProto";
  24. option java_package = "com.google.cloud.documentai.v1beta2";
  25. option php_namespace = "Google\\Cloud\\DocumentAI\\V1beta2";
  26. option ruby_package = "Google::Cloud::DocumentAI::V1beta2";
  27. // Document represents the canonical document resource in Document Understanding
  28. // AI.
  29. // It is an interchange format that provides insights into documents and allows
  30. // for collaboration between users and Document Understanding AI to iterate and
  31. // optimize for quality.
  32. message Document {
  33. // For a large document, sharding may be performed to produce several
  34. // document shards. Each document shard contains this field to detail which
  35. // shard it is.
  36. message ShardInfo {
  37. // The 0-based index of this shard.
  38. int64 shard_index = 1;
  39. // Total number of shards.
  40. int64 shard_count = 2;
  41. // The index of the first character in [Document.text][google.cloud.documentai.v1beta2.Document.text] in the overall
  42. // document global text.
  43. int64 text_offset = 3;
  44. }
  45. // Label attaches schema information and/or other metadata to segments within
  46. // a [Document][google.cloud.documentai.v1beta2.Document]. Multiple [Label][google.cloud.documentai.v1beta2.Document.Label]s on a single field can denote either
  47. // different labels, different instances of the same label created at
  48. // different times, or some combination of both.
  49. message Label {
  50. // Provenance of the label.
  51. oneof source {
  52. // Label is generated AutoML model. This field stores the full resource
  53. // name of the AutoML model.
  54. //
  55. // Format:
  56. // `projects/{project-id}/locations/{location-id}/models/{model-id}`
  57. string automl_model = 2;
  58. }
  59. // Name of the label.
  60. //
  61. // When the label is generated from AutoML Text Classification model, this
  62. // field represents the name of the category.
  63. string name = 1;
  64. // Confidence score between 0 and 1 for label assignment.
  65. float confidence = 3;
  66. }
  67. // Annotation for common text style attributes. This adheres to CSS
  68. // conventions as much as possible.
  69. message Style {
  70. // Font size with unit.
  71. message FontSize {
  72. // Font size for the text.
  73. float size = 1;
  74. // Unit for the font size. Follows CSS naming (in, px, pt, etc.).
  75. string unit = 2;
  76. }
  77. // Text anchor indexing into the [Document.text][google.cloud.documentai.v1beta2.Document.text].
  78. TextAnchor text_anchor = 1;
  79. // Text color.
  80. google.type.Color color = 2;
  81. // Text background color.
  82. google.type.Color background_color = 3;
  83. // Font weight. Possible values are normal, bold, bolder, and lighter.
  84. // https://www.w3schools.com/cssref/pr_font_weight.asp
  85. string font_weight = 4;
  86. // Text style. Possible values are normal, italic, and oblique.
  87. // https://www.w3schools.com/cssref/pr_font_font-style.asp
  88. string text_style = 5;
  89. // Text decoration. Follows CSS standard.
  90. // <text-decoration-line> <text-decoration-color> <text-decoration-style>
  91. // https://www.w3schools.com/cssref/pr_text_text-decoration.asp
  92. string text_decoration = 6;
  93. // Font size.
  94. FontSize font_size = 7;
  95. }
  96. // A page in a [Document][google.cloud.documentai.v1beta2.Document].
  97. message Page {
  98. // Dimension for the page.
  99. message Dimension {
  100. // Page width.
  101. float width = 1;
  102. // Page height.
  103. float height = 2;
  104. // Dimension unit.
  105. string unit = 3;
  106. }
  107. // Visual element describing a layout unit on a page.
  108. message Layout {
  109. // Detected human reading orientation.
  110. enum Orientation {
  111. // Unspecified orientation.
  112. ORIENTATION_UNSPECIFIED = 0;
  113. // Orientation is aligned with page up.
  114. PAGE_UP = 1;
  115. // Orientation is aligned with page right.
  116. // Turn the head 90 degrees clockwise from upright to read.
  117. PAGE_RIGHT = 2;
  118. // Orientation is aligned with page down.
  119. // Turn the head 180 degrees from upright to read.
  120. PAGE_DOWN = 3;
  121. // Orientation is aligned with page left.
  122. // Turn the head 90 degrees counterclockwise from upright to read.
  123. PAGE_LEFT = 4;
  124. }
  125. // Text anchor indexing into the [Document.text][google.cloud.documentai.v1beta2.Document.text].
  126. TextAnchor text_anchor = 1;
  127. // Confidence of the current [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] within context of the object this
  128. // layout is for. e.g. confidence can be for a single token, a table,
  129. // a visual element, etc. depending on context. Range [0, 1].
  130. float confidence = 2;
  131. // The bounding polygon for the [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout].
  132. BoundingPoly bounding_poly = 3;
  133. // Detected orientation for the [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout].
  134. Orientation orientation = 4;
  135. // Optional. This is the identifier used by referencing [PageAnchor][google.cloud.documentai.v1beta2.Document.PageAnchor]s.
  136. string id = 5 [(google.api.field_behavior) = OPTIONAL];
  137. }
  138. // A block has a set of lines (collected into paragraphs) that have a
  139. // common line-spacing and orientation.
  140. message Block {
  141. // [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] for [Block][google.cloud.documentai.v1beta2.Document.Page.Block].
  142. Layout layout = 1;
  143. // A list of detected languages together with confidence.
  144. repeated DetectedLanguage detected_languages = 2;
  145. }
  146. // A collection of lines that a human would perceive as a paragraph.
  147. message Paragraph {
  148. // [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] for [Paragraph][google.cloud.documentai.v1beta2.Document.Page.Paragraph].
  149. Layout layout = 1;
  150. // A list of detected languages together with confidence.
  151. repeated DetectedLanguage detected_languages = 2;
  152. }
  153. // A collection of tokens that a human would perceive as a line.
  154. // Does not cross column boundaries, can be horizontal, vertical, etc.
  155. message Line {
  156. // [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] for [Line][google.cloud.documentai.v1beta2.Document.Page.Line].
  157. Layout layout = 1;
  158. // A list of detected languages together with confidence.
  159. repeated DetectedLanguage detected_languages = 2;
  160. }
  161. // A detected token.
  162. message Token {
  163. // Detected break at the end of a [Token][google.cloud.documentai.v1beta2.Document.Page.Token].
  164. message DetectedBreak {
  165. // Enum to denote the type of break found.
  166. enum Type {
  167. // Unspecified break type.
  168. TYPE_UNSPECIFIED = 0;
  169. // A single whitespace.
  170. SPACE = 1;
  171. // A wider whitespace.
  172. WIDE_SPACE = 2;
  173. // A hyphen that indicates that a token has been split across lines.
  174. HYPHEN = 3;
  175. }
  176. // Detected break type.
  177. Type type = 1;
  178. }
  179. // [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] for [Token][google.cloud.documentai.v1beta2.Document.Page.Token].
  180. Layout layout = 1;
  181. // Detected break at the end of a [Token][google.cloud.documentai.v1beta2.Document.Page.Token].
  182. DetectedBreak detected_break = 2;
  183. // A list of detected languages together with confidence.
  184. repeated DetectedLanguage detected_languages = 3;
  185. }
  186. // Detected non-text visual elements e.g. checkbox, signature etc. on the
  187. // page.
  188. message VisualElement {
  189. // [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] for [VisualElement][google.cloud.documentai.v1beta2.Document.Page.VisualElement].
  190. Layout layout = 1;
  191. // Type of the [VisualElement][google.cloud.documentai.v1beta2.Document.Page.VisualElement].
  192. string type = 2;
  193. // A list of detected languages together with confidence.
  194. repeated DetectedLanguage detected_languages = 3;
  195. }
  196. // A table representation similar to HTML table structure.
  197. message Table {
  198. // A row of table cells.
  199. message TableRow {
  200. // Cells that make up this row.
  201. repeated TableCell cells = 1;
  202. }
  203. // A cell representation inside the table.
  204. message TableCell {
  205. // [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] for [TableCell][google.cloud.documentai.v1beta2.Document.Page.Table.TableCell].
  206. Layout layout = 1;
  207. // How many rows this cell spans.
  208. int32 row_span = 2;
  209. // How many columns this cell spans.
  210. int32 col_span = 3;
  211. // A list of detected languages together with confidence.
  212. repeated DetectedLanguage detected_languages = 4;
  213. }
  214. // [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] for [Table][google.cloud.documentai.v1beta2.Document.Page.Table].
  215. Layout layout = 1;
  216. // Header rows of the table.
  217. repeated TableRow header_rows = 2;
  218. // Body rows of the table.
  219. repeated TableRow body_rows = 3;
  220. // A list of detected languages together with confidence.
  221. repeated DetectedLanguage detected_languages = 4;
  222. }
  223. // A form field detected on the page.
  224. message FormField {
  225. // [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] for the [FormField][google.cloud.documentai.v1beta2.Document.Page.FormField] name. e.g. `Address`, `Email`,
  226. // `Grand total`, `Phone number`, etc.
  227. Layout field_name = 1;
  228. // [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] for the [FormField][google.cloud.documentai.v1beta2.Document.Page.FormField] value.
  229. Layout field_value = 2;
  230. // A list of detected languages for name together with confidence.
  231. repeated DetectedLanguage name_detected_languages = 3;
  232. // A list of detected languages for value together with confidence.
  233. repeated DetectedLanguage value_detected_languages = 4;
  234. // If the value is non-textual, this field represents the type. Current
  235. // valid values are:
  236. // - blank (this indicates the field_value is normal text)
  237. // - "unfilled_checkbox"
  238. // - "filled_checkbox"
  239. string value_type = 5;
  240. // An internal field, created for Labeling UI to export key text.
  241. string corrected_key_text = 6;
  242. // An internal field, created for Labeling UI to export value text.
  243. string corrected_value_text = 7;
  244. }
  245. // Detected language for a structural component.
  246. message DetectedLanguage {
  247. // The BCP-47 language code, such as "en-US" or "sr-Latn". For more
  248. // information, see
  249. // http://www.unicode.org/reports/tr35/#Unicode_locale_identifier.
  250. string language_code = 1;
  251. // Confidence of detected language. Range [0, 1].
  252. float confidence = 2;
  253. }
  254. // 1-based index for current [Page][google.cloud.documentai.v1beta2.Document.Page] in a parent [Document][google.cloud.documentai.v1beta2.Document].
  255. // Useful when a page is taken out of a [Document][google.cloud.documentai.v1beta2.Document] for individual
  256. // processing.
  257. int32 page_number = 1;
  258. // Physical dimension of the page.
  259. Dimension dimension = 2;
  260. // [Layout][google.cloud.documentai.v1beta2.Document.Page.Layout] for the page.
  261. Layout layout = 3;
  262. // A list of detected languages together with confidence.
  263. repeated DetectedLanguage detected_languages = 4;
  264. // A list of visually detected text blocks on the page.
  265. // A block has a set of lines (collected into paragraphs) that have a common
  266. // line-spacing and orientation.
  267. repeated Block blocks = 5;
  268. // A list of visually detected text paragraphs on the page.
  269. // A collection of lines that a human would perceive as a paragraph.
  270. repeated Paragraph paragraphs = 6;
  271. // A list of visually detected text lines on the page.
  272. // A collection of tokens that a human would perceive as a line.
  273. repeated Line lines = 7;
  274. // A list of visually detected tokens on the page.
  275. repeated Token tokens = 8;
  276. // A list of detected non-text visual elements e.g. checkbox,
  277. // signature etc. on the page.
  278. repeated VisualElement visual_elements = 9;
  279. // A list of visually detected tables on the page.
  280. repeated Table tables = 10;
  281. // A list of visually detected form fields on the page.
  282. repeated FormField form_fields = 11;
  283. }
  284. // A phrase in the text that is a known entity type, such as a person, an
  285. // organization, or location.
  286. message Entity {
  287. // Provenance of the entity.
  288. // Text anchor indexing into the [Document.text][google.cloud.documentai.v1beta2.Document.text].
  289. TextAnchor text_anchor = 1;
  290. // Required. Entity type from a schema e.g. `Address`.
  291. string type = 2 [(google.api.field_behavior) = REQUIRED];
  292. // Text value in the document e.g. `1600 Amphitheatre Pkwy`.
  293. string mention_text = 3;
  294. // Deprecated. Use `id` field instead.
  295. string mention_id = 4;
  296. // Optional. Confidence of detected Schema entity. Range [0, 1].
  297. float confidence = 5 [(google.api.field_behavior) = OPTIONAL];
  298. // Optional. Represents the provenance of this entity wrt. the location on the
  299. // page where it was found.
  300. PageAnchor page_anchor = 6 [(google.api.field_behavior) = OPTIONAL];
  301. // Optional. Canonical id. This will be a unique value in the entity list
  302. // for this document.
  303. string id = 7 [(google.api.field_behavior) = OPTIONAL];
  304. }
  305. // Relationship between [Entities][google.cloud.documentai.v1beta2.Document.Entity].
  306. message EntityRelation {
  307. // Subject entity id.
  308. string subject_id = 1;
  309. // Object entity id.
  310. string object_id = 2;
  311. // Relationship description.
  312. string relation = 3;
  313. }
  314. // Text reference indexing into the [Document.text][google.cloud.documentai.v1beta2.Document.text].
  315. message TextAnchor {
  316. // A text segment in the [Document.text][google.cloud.documentai.v1beta2.Document.text]. The indices may be out of bounds
  317. // which indicate that the text extends into another document shard for
  318. // large sharded documents. See [ShardInfo.text_offset][google.cloud.documentai.v1beta2.Document.ShardInfo.text_offset]
  319. message TextSegment {
  320. // [TextSegment][google.cloud.documentai.v1beta2.Document.TextAnchor.TextSegment] start UTF-8 char index in the [Document.text][google.cloud.documentai.v1beta2.Document.text].
  321. int64 start_index = 1;
  322. // [TextSegment][google.cloud.documentai.v1beta2.Document.TextAnchor.TextSegment] half open end UTF-8 char index in the
  323. // [Document.text][google.cloud.documentai.v1beta2.Document.text].
  324. int64 end_index = 2;
  325. }
  326. // The text segments from the [Document.text][google.cloud.documentai.v1beta2.Document.text].
  327. repeated TextSegment text_segments = 1;
  328. // Contains the content of the text span so that users do
  329. // not have to look it up in the text_segments.
  330. string content = 2;
  331. }
  332. // Referencing elements in [Document.pages][google.cloud.documentai.v1beta2.Document.pages].
  333. message PageAnchor {
  334. // Represents a weak reference to a page element within a document.
  335. message PageRef {
  336. // The type of layout that is being referenced.
  337. enum LayoutType {
  338. // Layout Unspecified.
  339. LAYOUT_TYPE_UNSPECIFIED = 0;
  340. // References a [Page.blocks][google.cloud.documentai.v1beta2.Document.Page.blocks] element.
  341. BLOCK = 1;
  342. // References a [Page.paragraphs][google.cloud.documentai.v1beta2.Document.Page.paragraphs] element.
  343. PARAGRAPH = 2;
  344. // References a [Page.lines][google.cloud.documentai.v1beta2.Document.Page.lines] element.
  345. LINE = 3;
  346. // References a [Page.tokens][google.cloud.documentai.v1beta2.Document.Page.tokens] element.
  347. TOKEN = 4;
  348. // References a [Page.visual_elements][google.cloud.documentai.v1beta2.Document.Page.visual_elements] element.
  349. VISUAL_ELEMENT = 5;
  350. // Refrrences a [Page.tables][google.cloud.documentai.v1beta2.Document.Page.tables] element.
  351. TABLE = 6;
  352. // References a [Page.form_fields][google.cloud.documentai.v1beta2.Document.Page.form_fields] element.
  353. FORM_FIELD = 7;
  354. }
  355. // Required. Index into the [Document.pages][google.cloud.documentai.v1beta2.Document.pages] element
  356. int64 page = 1 [(google.api.field_behavior) = REQUIRED];
  357. // Optional. The type of the layout element that is being referenced. If not
  358. // specified the whole page is assumed to be referenced.
  359. LayoutType layout_type = 2 [(google.api.field_behavior) = OPTIONAL];
  360. // Optional. The [Page.Layout.id][google.cloud.documentai.v1beta2.Document.Page.Layout.id] on the page that this element
  361. // references. If [LayoutRef.type][] is specified this id must also be
  362. // specified.
  363. string layout_id = 3 [(google.api.field_behavior) = OPTIONAL];
  364. }
  365. // One or more references to visual page elements
  366. repeated PageRef page_refs = 1;
  367. }
  368. // Original source document from the user.
  369. oneof source {
  370. // Currently supports Google Cloud Storage URI of the form
  371. // `gs://bucket_name/object_name`. Object versioning is not supported.
  372. // See [Google Cloud Storage Request
  373. // URIs](https://cloud.google.com/storage/docs/reference-uris) for more
  374. // info.
  375. string uri = 1;
  376. // Inline document content, represented as a stream of bytes.
  377. // Note: As with all `bytes` fields, protobuffers use a pure binary
  378. // representation, whereas JSON representations use base64.
  379. bytes content = 2;
  380. }
  381. // An IANA published MIME type (also referred to as media type). For more
  382. // information, see
  383. // https://www.iana.org/assignments/media-types/media-types.xhtml.
  384. string mime_type = 3;
  385. // UTF-8 encoded text in reading order from the document.
  386. string text = 4;
  387. // Styles for the [Document.text][google.cloud.documentai.v1beta2.Document.text].
  388. repeated Style text_styles = 5;
  389. // Visual page layout for the [Document][google.cloud.documentai.v1beta2.Document].
  390. repeated Page pages = 6;
  391. // A list of entities detected on [Document.text][google.cloud.documentai.v1beta2.Document.text]. For document shards,
  392. // entities in this list may cross shard boundaries.
  393. repeated Entity entities = 7;
  394. // Relationship among [Document.entities][google.cloud.documentai.v1beta2.Document.entities].
  395. repeated EntityRelation entity_relations = 8;
  396. // Information about the sharding if this document is sharded part of a larger
  397. // document. If the document is not sharded, this message is not specified.
  398. ShardInfo shard_info = 9;
  399. // [Label][google.cloud.documentai.v1beta2.Document.Label]s for this document.
  400. repeated Label labels = 11;
  401. // Any error that occurred while processing this document.
  402. google.rpc.Status error = 10;
  403. }