multichoice 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +140 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/multichoice.rb +86 -0
- data/lib/multichoice/version.rb +3 -0
- data/multichoice.gemspec +33 -0
- data/multichoice_array_test.rb +12 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5abd476d3dea81ee3313944da5f7d55fd26a772c
|
4
|
+
data.tar.gz: 543c9ba81467d4d4b72a75edc264e9d511b7800f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 78da0c0b618873fe8d8427cec59ee797bb95a0c50b88e697490781404dbbc2adb2a2f79e3f148160ae1fe98452c4e1d034662f3d4bb465d71f48fcdb9c40cbb8
|
7
|
+
data.tar.gz: 35f3ba9d23c6e5bf3b834d13c162e8e21cb2c83ce08bad5012f1d8ff83a6007761a2363adb02c5f82110b9380ec2380ddbb7806224ef170d960ef4965909ad4a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Floyd Wallace
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
# Multichoice
|
2
|
+
|
3
|
+
The gem takes Amazon MTurk's XML Spec file and adds the multiple choice elements with RADIO BUTTONS
|
4
|
+
please note that you can supply as many and as varied elements as you want
|
5
|
+
for each Human Intelligence Task or HIT.
|
6
|
+
|
7
|
+
The Gem was written to enable users to rapidly create a Human Intelligence Task that has RADIO BUTTONS.
|
8
|
+
|
9
|
+
#Arguments:
|
10
|
+
*over_view_text is the overview for the Question you are asking Mturkers
|
11
|
+
|
12
|
+
*identifier: format "Your_Name - HitNumber", example "John_Smith-1"
|
13
|
+
|
14
|
+
*question: format "something you want to ask", example "Which of these is a cat?"
|
15
|
+
|
16
|
+
*possibles: format ['A tabby cat', 'Leo Di Caprio since his name is Leo', 'Cat Stevens', 'The Year of the Cat by Al Stewart because Seventies Man!', 'None of the Above']
|
17
|
+
|
18
|
+
*possibles is the only argument that is NOT A STRING, but an array.
|
19
|
+
|
20
|
+
*possibles must have AT LEAST ONE ARRAY ELEMENT, which is at least one possible answer to the question. But to make sense to the Mturker workers you should have at least two, i.e
|
21
|
+
|
22
|
+
*possibles = ['The Band Stray Cats', 'None of the Above']
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'multichoice'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
|
34
|
+
$ bundle
|
35
|
+
|
36
|
+
Or install it yourself as:
|
37
|
+
|
38
|
+
$ gem install multichoice
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
Try this sample code out:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require "multichoice"
|
45
|
+
require 'mturk'
|
46
|
+
require 'yaml'
|
47
|
+
|
48
|
+
module TestCreateHit
|
49
|
+
class AmazonMturkHit
|
50
|
+
|
51
|
+
def initialize
|
52
|
+
read_config
|
53
|
+
@mturk = Amazon::WebServices::MechanicalTurkRequester.new :Host => @T_Host, :AWSAccessKeyId => @T_AWSAccessKeyId, :AWSAccessKey => @T_AWSAccessKey
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def read_config
|
59
|
+
config = YAML.load_file("mturk.yaml")
|
60
|
+
@T_Host = config["Host"]
|
61
|
+
@T_AWSAccessKeyId = config["AWSAccessKeyId"]
|
62
|
+
@T_AWSAccessKey = config["AWSAccessKey"]
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def create_hit
|
67
|
+
over_view_text = "This is a HIT to choose which of the following is a cat"
|
68
|
+
identifier = "John_Smith-3"
|
69
|
+
question = "Which of the following is a feline?"
|
70
|
+
possibles = ['Cat Stevens', 'The Year of the Cat by Al Stewart, The Seventies Man', 'Leo DiCaprio because his name is Leo', 'a tabby cat', 'None of the Above, they are all wrong']
|
71
|
+
my_xml = MultiChoice::RadioButton.new(over_view_text, identifier, question, possibles).execute
|
72
|
+
available = @mturk.availableFunds.to_f
|
73
|
+
puts "Available funds = #{available}"
|
74
|
+
title = "Question about CATS"
|
75
|
+
desc = "This is a HIT to answer questions about CATS"
|
76
|
+
keywords = "cats, match"
|
77
|
+
numAssignments = 1
|
78
|
+
my_LifetimeInSeconds = 604800
|
79
|
+
#one week lifetime
|
80
|
+
#autoapproval = 5 days
|
81
|
+
my_auto_approve = 60*60*24*5
|
82
|
+
rewardAmount = 0.09 # 9 cents
|
83
|
+
|
84
|
+
|
85
|
+
#create the HIT
|
86
|
+
result = @mturk.createHIT( :Title => title,
|
87
|
+
:Description => desc,
|
88
|
+
:MaxAssignments => numAssignments,
|
89
|
+
:LifetimeInSeconds => my_LifetimeInSeconds,
|
90
|
+
:AutoApprovalDelayInSeconds => my_auto_approve,
|
91
|
+
|
92
|
+
:Reward => { :Amount => rewardAmount, :CurrencyCode => 'USD' },
|
93
|
+
:Question => my_xml,
|
94
|
+
:Keywords => keywords )
|
95
|
+
#---------------------
|
96
|
+
#display Hit info
|
97
|
+
puts "Created HIT: #{result[:HITId]}"
|
98
|
+
myhit_id = result[:HITId]
|
99
|
+
myhit_type_id = result[:HITTypeId]
|
100
|
+
puts "HIT TYPE ID : #{myhit_type_id}"
|
101
|
+
my_hit_location = getHITUrl(result[:HITTypeId])
|
102
|
+
puts "HIT Location: #{getHITUrl( result[:HITTypeId])}"
|
103
|
+
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def getHITUrl( hitTypeId )
|
109
|
+
if @mturk.host =~ /sandbox/
|
110
|
+
"http://workersandbox.mturk.com/mturk/preview?groupId=#{hitTypeId}" # Sandbox Url
|
111
|
+
else
|
112
|
+
"http://mturk.com/mturk/preview?groupId=#{hitTypeId}" # Production Url
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
TestCreateHit::AmazonMturkHit.new.create_hit
|
121
|
+
```
|
122
|
+
|
123
|
+
## TODO
|
124
|
+
|
125
|
+
Still to come are checkboxes as well as radio buttons and retrieving the answer and parsing it for the good stuff.
|
126
|
+
|
127
|
+
## Development
|
128
|
+
|
129
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
130
|
+
|
131
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
132
|
+
|
133
|
+
## Contributing
|
134
|
+
|
135
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fwallace99/multichoice.
|
136
|
+
|
137
|
+
|
138
|
+
## License
|
139
|
+
|
140
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "multichoice"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/multichoice.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require "multichoice/version"
|
2
|
+
#require "mturk"
|
3
|
+
|
4
|
+
module MultiChoice
|
5
|
+
#takes Amazon MTurk's XML Spec file and adds the multiple choice elements with RADIO BUTTONS
|
6
|
+
#please note that you can supply as many and as varied elements as you want
|
7
|
+
#for each Human Intelligence Task or HIT.
|
8
|
+
|
9
|
+
#Arguments: over_view_text is the overview for the Question you are asking Mturkers
|
10
|
+
#identifier: format "Your_Name - HitNumber", example "John_Smith-1"
|
11
|
+
#question: format "something you want to ask", example "Which of these is a cat?"
|
12
|
+
#possibles: format ['A tabby cat', 'Leo Di Caprio since his name is Leo', 'Cat Stevens', 'The Year of the Cat by Al Stewart because Seventies Man!', 'None of the Above']
|
13
|
+
#possibles is the only argument that is NOT A STRING, but an array.
|
14
|
+
#possibles must have AT LEAST ONE ARRAY ELEMENT, which is at least one possible answer to the question. But to make sense to the Mturker workers you should have at least two, i.e
|
15
|
+
# possibles = ['The Band Stray Cats', 'None of the Above']
|
16
|
+
class RadioButton
|
17
|
+
|
18
|
+
def initialize(over_view_text, identifier, question, possibles)
|
19
|
+
@over_view_text = over_view_text
|
20
|
+
@identifier = identifier
|
21
|
+
@question = question
|
22
|
+
@possibles = possibles
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute
|
26
|
+
spitoutxml
|
27
|
+
end
|
28
|
+
|
29
|
+
def spitoutxml
|
30
|
+
base_xml = <<HERE
|
31
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
32
|
+
<QuestionForm xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd">
|
33
|
+
<Overview>
|
34
|
+
<Text>#{@over_view_text}</Text>
|
35
|
+
</Overview>
|
36
|
+
<Question>
|
37
|
+
HERE
|
38
|
+
|
39
|
+
mylocal_identifier = "<QuestionIdentifier>#{@identifier}</QuestionIdentifier>"
|
40
|
+
my_sku = "<QuestionContent>\n"
|
41
|
+
my_sku = my_sku + "<Text>#{@question}</Text>\n"
|
42
|
+
my_sku = my_sku + "</QuestionContent>\n"
|
43
|
+
base_xml = base_xml + mylocal_identifier + my_sku
|
44
|
+
|
45
|
+
top_answer_spec = <<ANS1
|
46
|
+
<AnswerSpecification>
|
47
|
+
<SelectionAnswer>
|
48
|
+
<StyleSuggestion>radiobutton</StyleSuggestion>
|
49
|
+
<Selections>
|
50
|
+
ANS1
|
51
|
+
|
52
|
+
base_xml = base_xml + top_answer_spec
|
53
|
+
my_answer = ''
|
54
|
+
|
55
|
+
|
56
|
+
@possibles.each do |myelement|
|
57
|
+
|
58
|
+
my_answer_spec = "<Selection>\n"
|
59
|
+
spec_ident = "<SelectionIdentifier>#{myelement}</SelectionIdentifier>\n"
|
60
|
+
sel_text = "<Text>#{myelement}</Text>\n"
|
61
|
+
close_spec = "</Selection>\n"
|
62
|
+
my_temp = my_answer_spec + spec_ident + sel_text + close_spec
|
63
|
+
my_answer = my_answer + my_temp
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
base_xml = base_xml + my_answer
|
69
|
+
|
70
|
+
bottom_answer = <<BOTTOM
|
71
|
+
|
72
|
+
|
73
|
+
</Selections>
|
74
|
+
</SelectionAnswer>
|
75
|
+
</AnswerSpecification>
|
76
|
+
</Question>
|
77
|
+
</QuestionForm>
|
78
|
+
BOTTOM
|
79
|
+
base_xml = base_xml + bottom_answer
|
80
|
+
|
81
|
+
return base_xml
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
data/multichoice.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'multichoice/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "multichoice"
|
8
|
+
spec.version = Multichoice::VERSION
|
9
|
+
spec.authors = ["Floyd Wallace"]
|
10
|
+
spec.email = ["fwallace99@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Creates a Multiple Choice Amazon Mechanical Turk Human Intellgince Task using radio buttons.}
|
13
|
+
spec.description = %q{Create Checkboxes and also parse the answer for a HIT.}
|
14
|
+
spec.homepage = "https://github.com/fwallace99/multichoice"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
f.match(%r{^(test|spec|features)/})
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
33
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class MultichoiceTest2 < Minitest::Test
|
4
|
+
|
5
|
+
def possibles_is_array
|
6
|
+
possibles = ['Cat Stevens', 'The Year of the Cat by Al Stevens, Seventies Man', 'Leo DiCaprio because his name is Leo', 'a tabby cat', 'None of the Above, they are all wrong']
|
7
|
+
assert_equal('Array', possibles.class)
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multichoice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Floyd Wallace
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: Create Checkboxes and also parse the answer for a HIT.
|
56
|
+
email:
|
57
|
+
- fwallace99@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/multichoice.rb
|
71
|
+
- lib/multichoice/version.rb
|
72
|
+
- multichoice.gemspec
|
73
|
+
- multichoice_array_test.rb
|
74
|
+
homepage: https://github.com/fwallace99/multichoice
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.6.8
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Creates a Multiple Choice Amazon Mechanical Turk Human Intellgince Task using
|
98
|
+
radio buttons.
|
99
|
+
test_files: []
|