-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from HighLiuk/main
Add Block, Paragraph, Word, Symbol models for Full Text Annotation
- Loading branch information
Showing
15 changed files
with
400 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// ignore_for_file: constant_identifier_names | ||
|
||
import 'dart:convert'; | ||
|
||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
import 'bounding_poly.dart'; | ||
import 'paragraph.dart'; | ||
import 'text_property.dart'; | ||
|
||
part 'block.g.dart'; | ||
|
||
/// Logical element on the page. | ||
@JsonSerializable(explicitToJson: true) | ||
class Block { | ||
/// Additional information detected for the block. | ||
final TextProperty? property; | ||
|
||
/// The bounding box for the block. The vertices are in the order of top-left, | ||
/// top-right, bottom-right, bottom-left. When a rotation of the bounding box | ||
/// is detected the rotation is represented as around the top-left corner as | ||
/// defined when the text is read in the 'natural' orientation. For example: | ||
/// | ||
/// - when the text is horizontal it might look like: | ||
/// | ||
/// ``` | ||
/// 0----1 | ||
/// | | | ||
/// 3----2 | ||
/// ``` | ||
/// | ||
/// - when it's rotated 180 degrees around the top-left corner it becomes: | ||
/// | ||
/// ``` | ||
/// 2----3 | ||
/// | | | ||
/// 1----0 | ||
/// ``` | ||
/// | ||
/// and the vertex order will still be (0, 1, 2, 3). | ||
final BoundingPoly? boundingBox; | ||
|
||
/// List of paragraphs in this block (if this blocks is of type text). | ||
final List<Paragraph>? paragraphs; | ||
|
||
/// Detected block type (text, image etc) for this block. | ||
@JsonKey(unknownEnumValue: BlockType.UNKNOWN) | ||
final BlockType blockType; | ||
|
||
/// Confidence of the OCR results on the block. Range [0, 1\]. | ||
final double? confidence; | ||
|
||
Block({ | ||
required this.property, | ||
required this.boundingBox, | ||
this.blockType = BlockType.UNKNOWN, | ||
required this.paragraphs, | ||
required this.confidence, | ||
}); | ||
|
||
factory Block.fromJson(Map<String, dynamic> json) => _$BlockFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$BlockToJson(this); | ||
|
||
@override | ||
String toString() => jsonEncode(toJson()); | ||
} | ||
|
||
/// Type of a block (text, image etc) as identified by OCR. | ||
@JsonEnum() | ||
enum BlockType { | ||
UNKNOWN, | ||
TEXT, | ||
TABLE, | ||
PICTURE, | ||
RULER, | ||
BARCODE, | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
import 'bounding_poly.dart'; | ||
import 'text_property.dart'; | ||
import 'word.dart'; | ||
|
||
part 'paragraph.g.dart'; | ||
|
||
/// Structural unit of text representing a number of words in certain order. | ||
@JsonSerializable(explicitToJson: true) | ||
class Paragraph { | ||
/// Additional information detected for the paragraph. | ||
final TextProperty? property; | ||
|
||
/// The bounding box for the paragraph. The vertices are in the order of | ||
/// top-left, top-right, bottom-right, bottom-left. When a rotation of the | ||
/// bounding box is detected the rotation is represented as around the | ||
/// top-left corner as defined when the text is read in the 'natural' | ||
/// orientation. For example: | ||
/// | ||
/// - when the text is horizontal it might look like: | ||
/// | ||
/// ``` | ||
/// 0----1 | ||
/// | | | ||
/// 3----2 | ||
/// ``` | ||
/// | ||
/// - when it's rotated 180 degrees around the top-left corner it becomes: | ||
/// | ||
/// ``` | ||
/// 2----3 | ||
/// | | | ||
/// 1----0 | ||
/// ``` | ||
/// | ||
/// and the vertex order will still be (0, 1, 2, 3). | ||
final BoundingPoly? boundingBox; | ||
|
||
/// List of all words in this paragraph. | ||
final List<Word>? words; | ||
|
||
/// Confidence of the OCR results for the paragraph. Range [0, 1\]. | ||
final double? confidence; | ||
|
||
Paragraph({ | ||
required this.property, | ||
required this.boundingBox, | ||
required this.words, | ||
required this.confidence, | ||
}); | ||
|
||
factory Paragraph.fromJson(Map<String, dynamic> json) => | ||
_$ParagraphFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$ParagraphToJson(this); | ||
|
||
@override | ||
String toString() => jsonEncode(toJson()); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
import 'bounding_poly.dart'; | ||
import 'text_property.dart'; | ||
|
||
part 'symbol.g.dart'; | ||
|
||
/// A single symbol representation. | ||
@JsonSerializable(explicitToJson: true) | ||
class Symbol { | ||
/// Additional information detected for the symbol. | ||
final TextProperty? property; | ||
|
||
/// The bounding box for the symbol. The vertices are in the order of | ||
/// top-left, top-right, bottom-right, bottom-left. When a rotation of the | ||
/// bounding box is detected the rotation is represented as around the | ||
/// top-left corner as defined when the text is read in the 'natural' | ||
/// orientation. For example: | ||
/// | ||
/// - when the text is horizontal it might look like: | ||
/// | ||
/// ``` | ||
/// 0----1 | ||
/// | | | ||
/// 3----2 | ||
/// ``` | ||
/// | ||
/// - when it's rotated 180 degrees around the top-left corner it becomes: | ||
/// | ||
/// ``` | ||
/// 2----3 | ||
/// | | | ||
/// 1----0 | ||
/// ``` | ||
/// | ||
/// and the vertex order will still be (0, 1, 2, 3). | ||
final BoundingPoly? boundingBox; | ||
|
||
/// The actual UTF-8 representation of the symbol. | ||
final String? text; | ||
|
||
/// Confidence of the OCR results for the symbol. Range [0, 1\]. | ||
final double? confidence; | ||
|
||
Symbol({ | ||
required this.property, | ||
required this.boundingBox, | ||
required this.text, | ||
required this.confidence, | ||
}); | ||
|
||
factory Symbol.fromJson(Map<String, dynamic> json) => _$SymbolFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$SymbolToJson(this); | ||
|
||
@override | ||
String toString() => jsonEncode(toJson()); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.