A Ruby parser for the GIFT question format.
GIFT is the format used by Moodle Learning Management System for writing multiple-choice, true-false, short answer, match missing word and numerical questions.
For details on the GIFT file format see: http://docs.moodle.org/en/GIFT
The parser is generated by Treetop parser generator. http://treetop.rubyforge.org/
P.S. The parser is not yet complete. It generates the syntactic tree but does not have all the semantic features as yet. It will give marks for answers using pattern matching of strings to mark close answers.
See the tests to get an idea on how the parser is supposed to be used.
See the file LICENCE for copyright details. (MIT license.)
Original Author: https://github.com/stuart/gift-parser Stuart Coyle 2010
In this gem you can see two main classes:
- Gift - it's a main class, whitch take an argument with GIFT string or file
- GiftParse - it's automatic generated class from treetop
require 'gift'
parser = Gift::Gift.new(my_gift_file)
# all questions
parser.questions
# count of all questions
parser.questions.count # or length
# questions enumerators
parser.questions.each { |q| ... }
When you will iterate in questions list, you will see, that every question object is instance of special class. It can be TrueFalseQuestion, DescriptionQuestion, ShortAnswerQuestion, EssayQuestion, MultipleChoiceQuestion, NumericQuestion, MatchQuestion, FillInQuestion
Every instance has methods to get any info about question:
# get title ::this is title::
question.title
# get text of question
question.text
# get list of answers
question.answers
# get list of correct answers (where :correct => true)
question.correct_answers
# get comment //this is comment
question.comment
# get markup lang. info e.g. [html]
question.markup_language
# TrueFalseQuestion#answers
[{:value => true, :correct => true, :feedback => "Feedback string"}]
# DescriptionQuestion#answers
[]
# EssayQuestion#answers
[]
# MultipleChoiceQuestion#answers
[
{:value => "Grant", :correct=> true, :feedback=> nil},
{:value => "No one", :correct => false, :feedback => "Was true for 12 years, but Grant's remains were buried in the tomb in 1897"}
]
# ShortAnswerQuestion#answers
[
{:feedback => nil, :value => "Grant", :correct => true},
{:feedback => nil, :value => "Ulysses S. Grant", :correct => true},
{:feedback => nil, :value => "Ulysses Grant" , :correct => true}
]
# NumericQuestion#answers
[{:minimum => "1822", :maximum => "1822"}]
# MatchQuestion#answers
{'Canada' => 'Ottowa','Italy' => 'Rome'}
# FillInQuestion#answers
[
{:value => 'second', :correct => false},
{:value => 'third', :correct => false},
{:value => 'fourth', :correct => true}
]
- Fork it ( https://github.com/[my-github-username]/gift-parser/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request