mork 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -12
- data/lib/mork/sheet_pdf.rb +11 -2
- data/lib/mork/version.rb +1 -1
- data/spec/mork/sheet_pdf_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1468b498d3b8817fa1535d1764e026c5ecb4db7f
|
4
|
+
data.tar.gz: 3ef072301473be4f4101594a27c60485c6ca9fdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 736560a4ffa1e59db099382a99440f11eff492b56fc65f02431e9e4b69d45d2f25793389d748f2cc5609524b269ae0d666ac396756194b215424f64b581a37b3
|
7
|
+
data.tar.gz: 810723654fd44aa7eb1acfa57687fb04e2aa368f29933c03597328ca9e14cfd45eb433b1ecd07670fc7bdbed717754a3d0a498d5d95fd304e4554d3efde2c6b6
|
data/README.md
CHANGED
@@ -7,27 +7,34 @@ A ruby [optical mark recognition](http://en.wikipedia.org/wiki/Optical_mark_reco
|
|
7
7
|
|
8
8
|
## Assumptions and limitations
|
9
9
|
|
10
|
-
Mork is a low-level library, and very much work in progress. It is not, and will likely never be a complete OMR solution. While suggestions and contributions are more than welcome, for the time being several assumptions and restrictions
|
10
|
+
Mork is a low-level library, and very much work in progress. It is not, and will likely never be a complete OMR solution. While suggestions and contributions are more than welcome, for the time being several assumptions and restrictions apply.
|
11
11
|
|
12
12
|
- the PDF files generated by Mork are intended to be printed on regular printer paper
|
13
13
|
- the entire response sheet must fit into a single page
|
14
14
|
- after collecting the responses, a filled-out form should be acquired as a JPEG, PNG, or PDF image by a normal optical scanner or camera (i.e., no specialized equipment is necessary)
|
15
15
|
- independent of how the sheet is printed and the image is acquired, all internal processing is done on a grayscale version of the bitmap
|
16
|
-
- the response sheet contains the following items:
|
16
|
+
- the response sheet always contains the following items:
|
17
17
|
- registration marks at each page corner
|
18
|
-
- a bar code along the bottom margin to uniquely identify the sheet
|
19
|
-
- a header area to print arbitrary information
|
20
18
|
- a response area containing a list of numbered items (questions)
|
21
19
|
- each item contains an arbitrary number of choice “cells”, each marked with a capital letter (A, B, C, ...)
|
22
20
|
- the right edge of the response area is reserved for a column of calibration cells that must remain blank
|
21
|
+
- in addition, the sheet may contain:
|
22
|
+
- a bar code along the bottom margin to uniquely identify the sheet
|
23
|
+
- a header area to print arbitrary information
|
23
24
|
- it is entirely up to the user to provide parameters that produce the desired response sheet layout; in particular, making sure that the header elements and choice cells fit in the available space, as Mork does not provide any type of "sanity" check at this time
|
24
25
|
|
25
26
|
## Getting started
|
26
27
|
|
27
|
-
First, make sure that ImageMagick is installed in your system.
|
28
|
+
First, make sure that ImageMagick is installed in your system. Typing `convert in a terminal shell should print out a long help message. If instead you get an error, you will need to install ImageMagick.
|
29
|
+
|
30
|
+
In OS X, `brew` is an excellent package manager:
|
28
31
|
|
29
32
|
brew install imagemagick
|
30
33
|
|
34
|
+
In a Debian-based Linux distro (e.g., Ubuntu) you would do:
|
35
|
+
|
36
|
+
sudo apt-get install imagemagick
|
37
|
+
|
31
38
|
To create a small ruby project that uses Mork, `cd` into a directory of choice, then execute the following shell commands:
|
32
39
|
|
33
40
|
```
|
@@ -46,7 +53,7 @@ Edit the file `mork_test.rb` with the code snippets below, then execute the foll
|
|
46
53
|
|
47
54
|
## Generating response sheets with `SheetPDF`
|
48
55
|
|
49
|
-
Response sheets are created through the `Mork::SheetPDF` class. Two pieces of information must be provided to the class constructor to produce a meaningful
|
56
|
+
Response sheets are created through the `Mork::SheetPDF` class. Two pieces of information must be provided to the class constructor to produce a meaningful sheet:
|
50
57
|
|
51
58
|
- **content**: what to place on the sheet, such as how many response items and choices, what to write in the header, the number to print as a barcode
|
52
59
|
- **layout**: sizes, margins, spacing, fonts, etc., of each of the printed elements
|
@@ -75,11 +82,11 @@ content = {
|
|
75
82
|
}
|
76
83
|
```
|
77
84
|
|
78
|
-
These are the key-value pairs that the `content` hash
|
85
|
+
These are the key-value pairs that the `content` hash may contain:
|
79
86
|
|
80
|
-
- **
|
81
|
-
- **
|
82
|
-
- **
|
87
|
+
- **choices**: an array of integers, specifiying the number of items in the test (the length of the array) and the number of choices available for each item (the array values); if omitted, the maximum number of items and choices per item are printed
|
88
|
+
- **header**: optional; a (sub)hash of key-value pairs defining the content of named header elements; in each pair, the key is the name of one header element, while the value is the rendered content; the actually available elements are defined in the `layout` (see below)
|
89
|
+
- **barcode**: optional; an integer number, the sheet's unique identifier to be printed as a binary barcode along the bottom edge of the sheet
|
83
90
|
|
84
91
|
### layout
|
85
92
|
|
@@ -96,7 +103,7 @@ reg_marks:
|
|
96
103
|
offset: 2 # distance between the search area and each page border (*)
|
97
104
|
blur: 2 # size of a gaussian blur filter to smooth overly pixelated registration marks (0 to skip) (*)
|
98
105
|
dilate: 5 # size of a “dilate” filter to get rid of stray noise (0 to skip) (*)
|
99
|
-
contrast: 20 # minimum contrast between registration mark circles and the surrounding white paper
|
106
|
+
contrast: 20 # minimum contrast between registration mark circles and the surrounding white paper (*)
|
100
107
|
header:
|
101
108
|
name: # ‘name’ is just a label; you can add arbitrary header elements
|
102
109
|
top: 5 # margin relative to registration frame top side
|
@@ -124,7 +131,7 @@ header:
|
|
124
131
|
size: 7
|
125
132
|
box: true # header element will be enclosed in a box
|
126
133
|
items:
|
127
|
-
threshold: 0.75 # mark detection threshold
|
134
|
+
threshold: 0.75 # mark detection threshold (*)
|
128
135
|
top: 55 # response area margin, relative to reg frame
|
129
136
|
left: 11 # response area margin, relative to reg frame
|
130
137
|
rows: 30 # number of items per column
|
data/lib/mork/sheet_pdf.rb
CHANGED
@@ -47,13 +47,14 @@ module Mork
|
|
47
47
|
# for all sheets
|
48
48
|
line_width 0.3
|
49
49
|
font_size @grip.item_font_size
|
50
|
+
ensure_presence_of_choices
|
50
51
|
create_stamps
|
51
52
|
make_repeaters
|
52
53
|
# for each response sheet
|
53
54
|
@content.each_with_index do |content, i|
|
54
55
|
start_new_page if i>0
|
55
|
-
barcode
|
56
|
-
header
|
56
|
+
barcode(content[:barcode] || 0)
|
57
|
+
header(content[:header] || [])
|
57
58
|
unless equal_choice_number?
|
58
59
|
questions_and_choices ch_len[i]
|
59
60
|
end
|
@@ -165,6 +166,14 @@ module Mork
|
|
165
166
|
true
|
166
167
|
end
|
167
168
|
|
169
|
+
def ensure_presence_of_choices
|
170
|
+
@content.each do |c|
|
171
|
+
if c[:choices].nil?
|
172
|
+
c[:choices] = [@grip.max_choices_per_question] * @grip.max_questions
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
168
177
|
def ch_len
|
169
178
|
@all_choice_lengths ||= @content.collect { |c| c[:choices] }
|
170
179
|
end
|
data/lib/mork/version.rb
CHANGED
data/spec/mork/sheet_pdf_spec.rb
CHANGED
@@ -85,6 +85,17 @@ module Mork
|
|
85
85
|
s = SheetPDF.new([c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c])
|
86
86
|
s.save('spec/out/pdf/p20.pdf')
|
87
87
|
end
|
88
|
+
|
89
|
+
it 'creates a pdf with minimal content' do
|
90
|
+
s = SheetPDF.new({choices: [4] * 30})
|
91
|
+
s.save 'spec/out/pdf/mincont.pdf'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'creates a PDF with the maximum possible choice cells if none are specified' do
|
95
|
+
ct = [{}, {choices: [3]*20}]
|
96
|
+
s = SheetPDF.new ct
|
97
|
+
s.save 'spec/out/pdf/nocontent.pdf'
|
98
|
+
end
|
88
99
|
end
|
89
100
|
end
|
90
101
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giuseppe Bertini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: narray
|