示例#1
0
import sys

sys.path.append("../../")
import VisipediaAPI as vis

# set up connection
vc = vis.Connection('../../config.yaml')

# GLOBALS
ANN_TYPE_ID = 4  # Use the dedicated test type
API_KEY_ID = 2  # Change this to your own key
ANN_INST_ID = 1135  # Change this to your own annotation instance

# To find your API keys, the following will return a list:
resp = vc.call('api_keys')
# then pick the 'id' of the API key you want to use

## create a new hit type
# set up the qualification requirements
qual_reqs = vis.yaml_field([
    vis.qual_field("00000000000000000071", "US", "eql"),  # US workers only
    vis.qual_field("000000000000000000L0", "95", "gte")
])  # >95% appr. rate
# create the hit type on the Visipedia server, but don't register it yet
resp = vc.call('hit_types',
               'create',
               params={
                   'identifier': 'Example Presence/Absence HIT',
                   'title': 'Example Test HIT',
                   'description': 'Test HIT to see if API works.',
                   'keywords': 'images,labeling,test,example',
import sys
sys.path.append("../../")
import VisipediaAPI as vis

# set up connection
vc = vis.Connection('../../config.yaml')

# get information about image with ID=1000 (including Flickr meta info)
resp = vc.call('images', 'show', id=1000, params={'show_meta' : 1})

# to create a new image, you just call the create function
# NOTE the name of the field, 'image[image]', this is due to legacy code
# and will be changed in the future, so please make it easy to switch this
# in your code if you upgrade to a new version of these bindings
FILENAME = 'solvay_conference_1927.jpg'
resp = vc.call('images', 'create', 
               files=[('image[image]', vis.file_field(FILENAME))])
# you can get the info about the file from:
img_id = resp.content['id'] # Saved as id=174845 already...
resp = vc.call('images', 'show', id=img_id)
annotation_type_id = resp.content["id"]

# show it
resp = vc.call("annotation_types", "show", id=annotation_type_id)

# destroy it
resp = vc.call("annotation_types", "destroy", id=annotation_type_id)

## create a new annotation type version
# use a dedicated annotation type for testing the other functionality
ID = 4  # don't remove this annotation_type -- it is used for testing...
resp = vc.call(
    "annotation_type_versions",
    "create",
    params={"annotation_type_id": ID},
    files=[("code", vis.folder_field("presence_absence"))],
)
annotation_type_version_id = resp.content["id"]

## create an instance for the annotation type
# format the parameters for the instance
# NOTE: you must format them EXACTLY like you want them to appear in the
#       javascript code!
prm = vis.yaml_field(
    {
        "object_name": "'Foo Bird'",
        "wikipedia_url": "'http://en.wikipedia.org/wiki/Foo'",
        "example_ids": "[1001, 1002, 1003]",
    }
)
# create the instance
示例#4
0
# set up connection
vc = vis.Connection('../../config.yaml')

# GLOBALS
ANN_TYPE_ID = 4 # Use the dedicated test type
API_KEY_ID = 2 # Change this to your own key
ANN_INST_ID = 1135 # Change this to your own annotation instance

# To find your API keys, the following will return a list:
resp = vc.call('api_keys')
# then pick the 'id' of the API key you want to use

## create a new hit type
# set up the qualification requirements
qual_reqs = vis.yaml_field(
    [vis.qual_field("00000000000000000071", "US", "eql"),  # US workers only
     vis.qual_field("000000000000000000L0", "95", "gte")]) # >95% appr. rate
# create the hit type on the Visipedia server, but don't register it yet
resp = vc.call('hit_types', 'create', 
                params={'identifier' : 'Example Presence/Absence HIT',
                        'title' : 'Example Test HIT',
                        'description' : 'Test HIT to see if API works.',
                        'keywords' : 'images,labeling,test,example',
                        'reward' : 1,
                        'assignment_duration' : 500,
                        'auto_approval_delay' : 2592000,
                        'annotation_type_id' : ANN_TYPE_ID,
                        'api_key_id' : API_KEY_ID,
                        'sandbox' : 1,
                        'qualification_requirement' : qual_reqs,
                        'register' : 0})
示例#5
0
import sys

sys.path.append("../../")
import VisipediaAPI as vis

# set up connection
vc = vis.Connection('../../config.yaml')

## create a new annotation type
resp = vc.call('annotation_types',
               'create',
               params={
                   'name':
                   'Example Task',
                   'description':
                   'This task is only used for API testing purposes.'
               })
annotation_type_id = resp.content['id']

# show it
resp = vc.call('annotation_types', 'show', id=annotation_type_id)

# destroy it
resp = vc.call('annotation_types', 'destroy', id=annotation_type_id)

## create a new annotation type version
# use a dedicated annotation type for testing the other functionality
ID = 4  # don't remove this annotation_type -- it is used for testing...
resp = vc.call('annotation_type_versions',
               'create',
               params={
示例#6
0
import sys
sys.path.append("../../")
import VisipediaAPI as vis

# set up connection
vc = vis.Connection('../../config.yaml')

# get information about image with ID=1000 (including Flickr meta info)
resp = vc.call('images', 'show', id=1000, params={'show_meta': 1})

# to create a new image, you just call the create function
# NOTE the name of the field, 'image[image]', this is due to legacy code
# and will be changed in the future, so please make it easy to switch this
# in your code if you upgrade to a new version of these bindings
FILENAME = 'solvay_conference_1927.jpg'
resp = vc.call('images',
               'create',
               files=[('image[image]', vis.file_field(FILENAME))])
# you can get the info about the file from:
img_id = resp.content['id']  # Saved as id=174845 already...
resp = vc.call('images', 'show', id=img_id)