activities/text/Evaluator. Evaluator

This class and its derivatives BasicEvaluator and
ComplexEvaluator are used to evaluate the answers written by the final users
in text activities.

Constructor

new Evaluator(className)

Evaluator constructor

Parameters:
NameTypeDescription
classNamestring

The class name of this evaluator.

Members

checkcase :boolean

Whether uppercase and lowercase expressions must be considered equivalent or not.

Type:
  • boolean

className :string

The type of evaluator.

Type:
  • string

collator :external:Collator

The Intl.Collator object used to compare strings, when available.

initiated :boolean

Whether this evaluator has been initialized or not.

Type:
  • boolean

Methods

_checkText(_text, _match) → {boolean}

Abstract method to be implemented in subclasses.
Performs the validation of a string against a single match.

Parameters:
NameTypeDescription
_textstring

The text to be checked

_matchstring

A valid expression with which to compare.

Returns:
  • true when the two expressions can be considered equivalent.
Type: 
boolean

_evalText(_text, _match) → {Array.<number>}

Abstract method to be implemented in subclasses.
Performs the evaluation of a string against an array of valid matches, returning an array of
flags useful to indicate where the mistakes are located.

Parameters:
NameTypeDescription
_textstring

The text to be checked

_matchstring

A valid expression with which to compare.

Returns:
  • An array of flags (one number for character) indicating whether each
    position is erroneous or OK.
Type: 
Array.<number>

checkText(text, match) → {boolean}

Checks the given text against a set of valid matches

Parameters:
NameTypeDescription
textstring

The text to be checked

matchstring | Array.<string>

The valid expression or expressions with which to compare.

Returns:
  • true if the checked expression is valid, false otherwise.
Type: 
boolean

evalText(text, match) → {Array.<number>}

Evaluates the given text against a set of valid matches, returning an array of flags useful
to indicate where the mistakes are located.

Parameters:
NameTypeDescription
textstring

The text to be checked

matchstring | Array.<string>

The valid expression or expressions with which to compare.

Returns:
  • An array of flags (one number for character) indicating whether each
    position is erroneous or ok.
Type: 
Array.<number>

getAttributes() → {object}

Gets a object with the basic attributes needed to rebuild this instance excluding functions,
parent references, constants and also attributes retaining the default value.
The resulting object is commonly usued to serialize elements in JSON format.

Returns:
  • The resulting object, with minimal attrributes
Type: 
object

init(_locales)

Initializes this evaluator

Parameters:
NameTypeDescription
_localesArray.<string>

An array of valid locales, to be used by Intl.Collator

isOk(flags) → {boolean}

Checks if the given array of flags (usually returned by evalText) can be considered as a
valid or erroneous answer.

Parameters:
NameTypeDescription
flagsArray.<number>
Returns:
  • true when there is at least one flag and all flags are 0 (meaning no error).
Type: 
boolean

setProperties($xml)

Loads the object settings from a specific JQuery XML element

Parameters:
NameTypeDescription
$xmlexternal:jQuery

The jQuery XML element to parse

(static) factory(data) → {module:activities/text/Evaluator.Evaluator}

Builds a new Evaluator, based on the properties specified in a data object

Parameters:
NameTypeDescription
dataobject

The data object to be parsed

(static) getEvaluator($xml) → {module:activities/text/Evaluator.Evaluator}

Factory constructor that returns a specific type of Evaluator based on the class
attribute declared in the $xml element.

Parameters:
NameTypeDescription
$xmlexternal:jQuery

The XML element to be parsed.