Class: CooCoo::DataSources::Xournal::TrainingDocument
- Defined in:
- lib/coo-coo/data_sources/xournal/training_document.rb,
lib/coo-coo/data_sources/xournal/training_document/sets.rb,
lib/coo-coo/data_sources/xournal/training_document/example.rb,
lib/coo-coo/data_sources/xournal/training_document/constants.rb,
lib/coo-coo/data_sources/xournal/training_document/document_maker.rb,
lib/coo-coo/data_sources/xournal/training_document/document_reader.rb
Overview
The TrainingDocument is the source of strokes for the trainer of the Xournal recognizer. Each TrainingDocument has a set of labels and associated strokes. Examples are loaded and stored to Xournal documents formatted into a grid with a label and strokes in each cell.
Defined Under Namespace
Classes: DocumentMaker, DocumentReader, Example
Constant Summary collapse
- VERSION =
'1'
- GRID_COLOR =
FIXME Xournal places alpha up front
'#00E0FFFF'
- PARSED_GRID_COLOR =
ChunkyPNG::Color.parse(GRID_COLOR)
- META_LABEL =
"Training Document"
- META_LABEL_REGEX =
/^#{META_LABEL}( +\d+)?: *(\d+)( +\d+)( +\d+)?/
Instance Attribute Summary collapse
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
Class Method Summary collapse
-
.ascii_trainer(doc = self.new) ⇒ TrainingDocument
Create a TrainingDocument for ASCII characters.
-
.cjk_trainer(limit = 2000, doc = self.new) ⇒ TrainingDocument
Create a TrainingDocument for the CJK block.
-
.emoji_trainer(doc = self.new) ⇒ TrainingDocument
Create a TrainingDocument for emoji.
-
.from_document(doc) ⇒ TrainingDocument
Load a TrainingDocument from a Document.
-
.from_file(io_or_path) ⇒ TrainingDocument
Load TrainingDocument from a Xournal file.
-
.jp_trainer(doc = self.new) ⇒ TrainingDocument
Create a TrainingDocument for Japanese Hiragana, Katakana, and punctuation.
-
.math_trainer(doc = self.new) ⇒ TrainingDocument
Create a TrainingDocument for math symbols.
-
.unicode_trainer(starting_offset, number, doc = self.new) ⇒ TrainingDocument
Create a TrainingDocument for an arbitrary Unicode block.
Instance Method Summary collapse
-
#add_example(label, strokes = nil) ⇒ Object
Add an example to the set.
-
#each_example(&block) ⇒ Enumerator
Iterates each Example.
-
#initialize(examples = nil) ⇒ TrainingDocument
constructor
A new instance of TrainingDocument.
-
#labels ⇒ Array<String>
Of every example’s label.
-
#size ⇒ Integer
Number of examples.
- #to_document(columns, rows, cells_per_example = 4, page_width = 612, page_height = 792) ⇒ Document
Constructor Details
#initialize(examples = nil) ⇒ TrainingDocument
Returns a new instance of TrainingDocument.
18 19 20 |
# File 'lib/coo-coo/data_sources/xournal/training_document.rb', line 18 def initialize(examples = nil) @examples = examples || Hash.new { |h, k| h[k] = Example.new(k) } end |
Instance Attribute Details
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
15 16 17 |
# File 'lib/coo-coo/data_sources/xournal/training_document.rb', line 15 def examples @examples end |
Class Method Details
.ascii_trainer(doc = self.new) ⇒ TrainingDocument
Create a CooCoo::DataSources::Xournal::TrainingDocument for ASCII characters.
8 9 10 11 12 13 14 15 |
# File 'lib/coo-coo/data_sources/xournal/training_document/sets.rb', line 8 def self.ascii_trainer(doc = self.new) (32...127).each do |c| c = c.chr[0] doc.add_example(c, []) end doc end |
.cjk_trainer(limit = 2000, doc = self.new) ⇒ TrainingDocument
Create a CooCoo::DataSources::Xournal::TrainingDocument for the CJK block.
45 46 47 |
# File 'lib/coo-coo/data_sources/xournal/training_document/sets.rb', line 45 def self.cjk_trainer(limit = 2000, doc = self.new) unicode_trainer(0x4e00, limit) end |
.emoji_trainer(doc = self.new) ⇒ TrainingDocument
Create a CooCoo::DataSources::Xournal::TrainingDocument for emoji.
52 53 54 55 |
# File 'lib/coo-coo/data_sources/xournal/training_document/sets.rb', line 52 def self.emoji_trainer(doc = self.new) unicode_trainer(0x1F600, 16 * 5, doc) unicode_trainer(0x2700, 16 * 12, doc) end |
.from_document(doc) ⇒ TrainingDocument
Load a CooCoo::DataSources::Xournal::TrainingDocument from a Document.
72 73 74 |
# File 'lib/coo-coo/data_sources/xournal/training_document.rb', line 72 def self.from_document(doc) DocumentReader.new.load(doc) end |
.from_file(io_or_path) ⇒ TrainingDocument
Load CooCoo::DataSources::Xournal::TrainingDocument from a Xournal file.
65 66 67 |
# File 'lib/coo-coo/data_sources/xournal/training_document.rb', line 65 def self.from_file(io_or_path) DocumentReader.new.load(Xournal.from_file(io_or_path)) end |
.jp_trainer(doc = self.new) ⇒ TrainingDocument
Create a CooCoo::DataSources::Xournal::TrainingDocument for Japanese Hiragana, Katakana, and punctuation.
33 34 35 36 37 38 39 |
# File 'lib/coo-coo/data_sources/xournal/training_document/sets.rb', line 33 def self.jp_trainer(doc = self.new) unicode_trainer(0x3000, 64, doc) unicode_trainer(0x3040, 96, doc) unicode_trainer(0x30A0, 96, doc) unicode_trainer(0xff00, 16 * 15, doc) doc end |
.math_trainer(doc = self.new) ⇒ TrainingDocument
Create a CooCoo::DataSources::Xournal::TrainingDocument for math symbols.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/coo-coo/data_sources/xournal/training_document/sets.rb', line 60 def self.math_trainer(doc = self.new) unicode_trainer(0x2200, 16 * 16, doc) unicode_trainer(0x2A00, 16 * 16, doc) unicode_trainer(0x2100, 16 * 5, doc) unicode_trainer(0x27C0, 16 * 3, doc) unicode_trainer(0x2980, 16 * 8, doc) unicode_trainer(0x2300, 16 * 16, doc) unicode_trainer(0x25A0, 16 * 6, doc) unicode_trainer(0x2B00, 16 * 16, doc) unicode_trainer(0x2190, 16 * 7, doc) unicode_trainer(0x2900, 16 * 8, doc) unicode_trainer(0x1D400, 16 * 16 * 4, doc) end |
.unicode_trainer(starting_offset, number, doc = self.new) ⇒ TrainingDocument
Create a CooCoo::DataSources::Xournal::TrainingDocument for an arbitrary Unicode block.
22 23 24 25 26 27 28 |
# File 'lib/coo-coo/data_sources/xournal/training_document/sets.rb', line 22 def self.unicode_trainer(starting_offset, number, doc = self.new) number.times do |i| doc.add_example("" << (starting_offset + i), []) end doc end |
Instance Method Details
#add_example(label, strokes = nil) ⇒ Object
Add an example to the set.
36 37 38 39 40 |
# File 'lib/coo-coo/data_sources/xournal/training_document.rb', line 36 def add_example(label, strokes = nil) ex = @examples[label] ex.add_set(strokes) if strokes && !strokes.empty? self end |
#each_example(&block) ⇒ Enumerator
Iterates each Example.
44 45 46 47 48 49 50 |
# File 'lib/coo-coo/data_sources/xournal/training_document.rb', line 44 def each_example(&block) return to_enum(__method__) unless block_given? @examples.each do |label, ex| block.call(ex) end end |
#labels ⇒ Array<String>
Returns of every example’s label.
28 29 30 |
# File 'lib/coo-coo/data_sources/xournal/training_document.rb', line 28 def labels @examples.keys end |
#size ⇒ Integer
Returns Number of examples.
23 24 25 |
# File 'lib/coo-coo/data_sources/xournal/training_document.rb', line 23 def size @examples.size end |
#to_document(columns, rows, cells_per_example = 4, page_width = 612, page_height = 792) ⇒ Document
58 59 60 |
# File 'lib/coo-coo/data_sources/xournal/training_document.rb', line 58 def to_document(columns, rows, cells_per_example = 4, page_width = 612, page_height = 792) DocumentMaker.new(self, columns, rows, cells_per_example, page_width, page_height).make_document end |