Class Index | File Index

Classes


Built-In Namespace _global_

Field Summary
Field Attributes Field Name and Description
 
This is the directory that the currently running TurKit JavaScript file is in.
 
This is a reference to the Database associated with this TurKit file.
 
This is a reference to the TurKit object in Java running this JavaScript file.
 
A reference to an MTurk object.
 
s3
A reference to an S3 object.
 
This is a pointer to the TraceManager.
Method Summary
Method Attributes Method Name and Description
 
attempt(func, frameName)
This is a wrapper around TraceManager#attempt.
 
Bag(a)
Returns a new Bag data structure, which is an unordered collection of objects, where objects can appear multiple times.
 
Returns a JavaScript array given a Java array.
 
createWebpageFromTemplate(html, blockWorkers, bucketName)

Creates a webpage, puts it on S3, and returns the URL.

 
ensure(obj, path, defaultValue)
Ensures that a JavaScript path exists, assigns a default value to the path if it doesn't exist yet, and returns the value in either case.
 
Escape the string for use inside XML, e.g.
 
filter(a, test)
Filters values of an array or object using the test function; the original object is not affected.
 
fold(a, func, def)

Here is an example of fold:
fold([1, 1, 1, 1], function (x, y) { return x + y }, 0)
returns 4.

 
foreach(a, test)
Processes values of an array or object using the test function; the original object is not affected.
 
getFile(relPath)
Get a Java File object given a path relative to the baseDir.
 
getMax(a, test)
Passes each value of an array or object through the test function, and returns the maximum value found, along with the index it was found at, in an array.
 
group(a, func)
Groups the values in the object or array a by the key defined for each value by running func on that value.
 

Takes two strings a and b, and calculates their differences.

 
json(o)
Returns a JSON-like representation of the JavaScript data value.
 
jsonPath(obj, expr, arg)
see documentation here: http://goessner.net/articles/JsonPath/ from: http://code.google.com/p/jsonpath/ JSONPath 0.8.0 - XPath for JSON Copyright (c) 2007 Stefan Goessner (goessner.net) Licensed under the MIT (MIT-LICENSE.txt) licence.
 
keys(obj)
Returns the keys of an object as an array.
 
last(a)
Returns the last element of this array.
 
map(a, test)
Maps values of an array or object using the test function; the original object is not affected.
 
mapToSelf(a, test)
Maps values of an array or object using the test function, overriding the values in the original object.
 
md5(s)
Return the md5 hash of the given string.
 
merge(objA, objB)
Adds the key/value pairs found in objB to objA.
 
once(func, frameName)
This is a wrapper around TraceManager#once.
 
 
print(s)
A thin wrapper around Java's System.out.println(s).
 
prune(o, depth)
Returns a deep clone of o up to the specified depth.
 
Use this instead of Math.random().
 
read(src)
Reads the contents of the file or url indicated by src into a string.
 
resetTrace(traceName)
Wrapper around TraceManager#resetTrace.
 
Re-throws the given exception, with an attempt to preserve the original stack trace.
 
Returns true if it is safe to call eval on s, i.e.
 
Set(a)
Returns a new Set.
 
setMode(mode)
Changes the mode.
 
setTrace(traceName)
Wrapper around TraceManager#setTrace
 
Randomizes the order of the elements in a.
 
sleep(seconds)
Sleep for the specified number of seconds using Java's Thread.sleep
 
slurp(src)
Reads the contents of the file or url indicated by src into a string, same as read.
 
Utility methods for doing statistics.
 
stop()
Wrapper around TraceManager#stop.
 
test(v, k)
 
time()
Wraps Java's System.currentTimeMillis().
 
trim(s)
Removes whitespace from the front and back of the string.
 
Unescape a string with XML escape codes, e.g.
 
values(obj)
Returns an array of the values in an object.
 
This function prints s if and only if TurKit is in "verbose" mode.
 
write(dest, s)
Writes the contents of the string s to the file indicated by dest.
Field Detail
baseDir
This is the directory that the currently running TurKit JavaScript file is in.
Defined in: turkit_base.js.

database
This is a reference to the Database associated with this TurKit file.
Defined in: Database.js.

javaTurKit
This is a reference to the TurKit object in Java running this JavaScript file.
Defined in: turkit_base.js.

{MTurk} mturk
A reference to an MTurk object.
Defined in: MTurk.js.

{S3} s3
A reference to an S3 object.
Defined in: S3.js.

traceManager
This is a pointer to the TraceManager. You probably want to use this, and not create another TraceManager.
Defined in: TraceManager.js.
Method Detail
attempt(func, frameName)
This is a wrapper around TraceManager#attempt.
Defined in: TraceManager.js.
Parameters:
func
frameName

Bag(a)
Returns a new Bag data structure, which is an unordered collection of objects, where objects can appear multiple times. The bag is really a map of keys, where the value associated with each key represents the number of times that key appears in the bag. If a is a bag, add it's elements to this bag. If a is an object, add it's values to this bag. If a is an element, add it to this bag.
Defined in: util.js.
Parameters:
a

convertJavaArray(ja)
Returns a JavaScript array given a Java array.
Defined in: util.js.
Parameters:
ja

createWebpageFromTemplate(html, blockWorkers, bucketName)

Creates a webpage, puts it on S3, and returns the URL. The webpage represents a HIT. The webpage is created by starting with a template HTML page. The html supplied to this function in injected into the template. The S3 webpage is made publicly accessible. The URL to the S3 webpage is returned. You can pass the URL to s3.deleteObject to remove it.

If you supply an array or comma-delimited-string for blockWorkers, then the html page will use JavaScript to prevent those workers from completing the HIT.

If you give any elements the class "random", then those elements will be randomly permuted each time a user views the page. This is good for randomizing the choices in voting tasks.

bucketName is optional. If you do not provide it, the name S3#defaultBucketName will be used.


Defined in: highlevel_utils.js.
Parameters:
html
blockWorkers
bucketName

ensure(obj, path, defaultValue)
Ensures that a JavaScript path exists, assigns a default value to the path if it doesn't exist yet, and returns the value in either case. There are multiple ways to call this function. All of the following are equivalent:
ensure("a.b[2].c", 5)
ensure(null, "a.b[2].c", 5)
ensure(a, "b[2].c", 5)
ensure(a, ".b[2].c", 5)
ensure(a, ["b", 2, "c"], 5)

print(a.b[2].c)

The last line prints "5". Note that the last 3 versions only work if a is already an object.
Defined in: util.js.
Parameters:
obj
path
defaultValue

escapeXml(s)
Escape the string for use inside XML, e.g., convert characters like & into &.
Defined in: util.js.
Parameters:
s

filter(a, test)
Filters values of an array or object using the test function; the original object is not affected.
For example:
filter({a:5,b:7,c:3}, function (e) {return e >= 5})
returns {a:5,b:7}.
You may also use a string for test like so:
filter({a:5,b:7,c:3}, "e >= 5").
Note that e is a special value in the string.
Defined in: util.js.
Parameters:
a
test

fold(a, func, def)

Here is an example of fold:
fold([1, 1, 1, 1], function (x, y) { return x + y }, 0)
returns 4.

The value of x in the function will always come from an element of a.

If the parameter def is used, then the value of y in the function will always come from def, or from a return value of func. If a has no elements, then def will be returned.

If def is not supplied, then both x and y will come from a. If a has only 1 element, then func will not be called, and that one element will be returned. If a has no elements, then null will be returned.


Defined in: util.js.
Parameters:
a
func
def

foreach(a, test)
Processes values of an array or object using the test function; the original object is not affected.
For example:
foreach({a:5,b:7,c:3}, function (e) {print(e)})
prints 5, 7, 3
You may also use a string for test like so:
foreach({a:5,b:7,c:3}, "print(e)").
Note that e is a special value in the string. Another special value is i, which is the index or key of the current element.
Defined in: util.js.
Parameters:
a
test

getFile(relPath)
Get a Java File object given a path relative to the baseDir.
Defined in: turkit_base.js.
Parameters:
relPath

getMax(a, test)
Passes each value of an array or object through the test function, and returns the maximum value found, along with the index it was found at, in an array.
For example:
getMax({a:5,b:7,c:3}, function (e) {return e})
returns [7, "b"]
You may also use a string for test like so:
getMax({a:5,b:7,c:3}, "e").
Note that e is a special value in the string. Another special value is i, which is the index or key of the current element. If you omit a value for test, the default is "e".
Defined in: util.js.
Parameters:
a
An array or object.
test
Each element in a is passed through this. The default is the identity function.

group(a, func)
Groups the values in the object or array a by the key defined for each value by running func on that value. The result is a map of keys to arrays, where each array holds all the values associated with that key.
Defined in: util.js.
Parameters:
a
func

highlightDiff(a, b)

Takes two strings a and b, and calculates their differences. The differences are highlighted in each result using HTML span tags with yellow backgrounds. There are two resulting strings of HTML, returned in an object with two properties, a and b.


Defined in: util.js.
Parameters:
a
b

{String} json(o)
Returns a JSON-like representation of the JavaScript data value. You may call "eval" on the result and get back the original data structure. This works even if the structure contains nested or even circular references. It does not handle functions.
Defined in: util.js.
Parameters:
o
The data value to convert. May be a number, string, array or object.
Returns:
A JSON-like representation of o.

jsonPath(obj, expr, arg)
see documentation here: http://goessner.net/articles/JsonPath/ from: http://code.google.com/p/jsonpath/ JSONPath 0.8.0 - XPath for JSON Copyright (c) 2007 Stefan Goessner (goessner.net) Licensed under the MIT (MIT-LICENSE.txt) licence.
Defined in: util.js.
Parameters:
obj
expr
arg

{Array} keys(obj)
Returns the keys of an object as an array.
Defined in: util.js.
Parameters:
obj

last(a)
Returns the last element of this array.
Defined in: util.js.
Parameters:
a

map(a, test)
Maps values of an array or object using the test function; the original object is not affected.
For example:
map({a:5,b:7,c:3}, function (e) {return e + 1})
returns {a:6,b:8,c:4}.
You may also use a string for test like so:
map({a:5,b:7,c:3}, "e + 1").
Note that e is a special value in the string. Another special value is i, which is the index or key of the current element.
Defined in: util.js.
Parameters:
a
test

mapToSelf(a, test)
Maps values of an array or object using the test function, overriding the values in the original object.
For example:
mapToSelf({a:5,b:7,c:3}, function (e) {return e + 1})
returns {a:6,b:8,c:4}.
You may also use a string for test like so:
mapToSelf({a:5,b:7,c:3}, "e + 1").
Note that e is a special value in the string. Another special value is i, which is the index or key of the current element.
Defined in: util.js.
Parameters:
a
test

md5(s)
Return the md5 hash of the given string.
Defined in: util.js.
Parameters:
s

merge(objA, objB)
Adds the key/value pairs found in objB to objA.
For example:
merge({a:1, b:2}, {c:3, d:4})
returns {a:1, b:2, c:3, d:4}
Defined in: util.js.
Parameters:
objA
objB

once(func, frameName)
This is a wrapper around TraceManager#once.
Defined in: TraceManager.js.
Parameters:
func
frameName

parseMTurkTime(s)

Defined in: MTurk.js.
Parameters:
s

print(s)
A thin wrapper around Java's System.out.println(s). If s is an object, then it is converted into a string using json.
Defined in: util.js.
Parameters:
s

prune(o, depth)
Returns a deep clone of o up to the specified depth.
For example:
prune({a:{b:5},c:[1,2,3]}, 1)
Returns {a:{},c:[]}
Defined in: util.js.
Parameters:
o
depth

random()
Use this instead of Math.random(). This is not just a shorthand. It is important that TurKit programs run the same way each time they are executed. This function wraps Math.random() inside a call to TraceManager#once.
Defined in: highlevel_utils.js.

read(src)
Reads the contents of the file or url indicated by src into a string.
Defined in: turkit_base.js.
Parameters:
src

resetTrace(traceName)
Wrapper around TraceManager#resetTrace.
Defined in: TraceManager.js.
Parameters:
traceName

rethrow(e)
Re-throws the given exception, with an attempt to preserve the original stack trace.
Defined in: util.js.
Parameters:
e

safeJson(s)
Returns true if it is safe to call eval on s, i.e., calling eval on s will not have any side effects aside from creating a data structure.
Defined in: util.js.
Parameters:
s

Set(a)
Returns a new Set. A set is represented as an object where the values are true for keys in the set. If a is a set, add it's elements to this set. If a is an object, add it's values to this set. If a is an element, add it to this set.
Defined in: util.js.
Parameters:
a

setMode(mode)
Changes the mode. Possible values include "offline", "sandbox" and "real".
Defined in: highlevel_utils.js.
Parameters:
mode

setTrace(traceName)
Wrapper around TraceManager#setTrace
Defined in: TraceManager.js.
Parameters:
traceName

shuffle(a)
Randomizes the order of the elements in a.
Defined in: highlevel_utils.js.
Parameters:
a

sleep(seconds)
Sleep for the specified number of seconds using Java's Thread.sleep
Defined in: util.js.
Parameters:
seconds

slurp(src)
Reads the contents of the file or url indicated by src into a string, same as read.
Defined in: turkit_base.js.
Parameters:
src

Stats()
Utility methods for doing statistics. More to come here in the future.
Defined in: Stats.js.

stop()
Wrapper around TraceManager#stop.
Defined in: TraceManager.js.

test(v, k)

Defined in: util.js.
Parameters:
v
k

time()
Wraps Java's System.currentTimeMillis(). Returns the current time in milliseconds.
Defined in: util.js.

trim(s)
Removes whitespace from the front and back of the string.
Defined in: util.js.
Parameters:
s

unescapeXml(s)
Unescape a string with XML escape codes, e.g., convert sequences like & into &.
Defined in: util.js.
Parameters:
s

{Array} values(obj)
Returns an array of the values in an object.
Defined in: util.js.
Parameters:
obj

verbosePrint(s)
This function prints s if and only if TurKit is in "verbose" mode.
Defined in: turkit_base.js.
Parameters:
s

write(dest, s)
Writes the contents of the string s to the file indicated by dest.
Defined in: turkit_base.js.
Parameters:
dest
s

Documentation generated by JsDoc Toolkit 2.1.0 on Tue Jun 08 2010 19:53:20 GMT-0400 (EDT)