Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="hitTypeId"></param>
        /// <param name="question"></param>
        /// <param name="lifetime"></param>
        /// <param name="assignmentReviewPolicy"></param>
        /// <param name="hitReviewPolicy"></param>
        /// <param name="requesterAnnotation"></param>
        /// <param name="maxAssignments"></param>
        /// <returns></returns>
        public async Task <CreateHITResponse> CreateHIT(string hitTypeId,
                                                        IQuestion question,
                                                        TimeSpan lifetime,
                                                        ReviewPolicy assignmentReviewPolicy = null,
                                                        ReviewPolicy hitReviewPolicy        = null,
                                                        string requesterAnnotation          = null,
                                                        int maxAssignments = 1)
        {
            var requestToken = Guid.NewGuid();
            var request      = new CreateHITRequest
            {
                HITTypeId              = hitTypeId,
                LifetimeInSeconds      = (long)lifetime.TotalSeconds,
                MaxAssignments         = maxAssignments,
                AssignmentReviewPolicy = assignmentReviewPolicy,
                HITReviewPolicy        = hitReviewPolicy,
                RequesterAnnotation    = requesterAnnotation,
                UniqueRequestToken     = requestToken.ToString("N")
            };

            PackQuestion(question, request);

            var resp = await ExecuteRequest <CreateHITRequest, CreateHITResponse>(request);

            return(resp);
        }
        /// <summary>
        /// Creates a HIT that uses the Plurality hit review policy. This example will auto-approve assignments where the answer agrees with the majority and reject otherwise.
        /// </summary>
        public void CreateHITWithReviewPolicy()
        {
            string hitTypeId = client.RegisterHITType("Answer a plurality question", "This is a HIT created by the Mechanical Turk .Net SDK", 60, 60, 0.01m, ".net test", null);

            ReviewPolicy policy = new ReviewPolicy();
            PolicyParameter[] parameters = new PolicyParameter[4];
            PolicyParameter questionIds = new PolicyParameter();
            questionIds.Key = "QuestionIds";
            questionIds.Value = new string[1] { "1" };
            parameters[0] = questionIds;
            PolicyParameter agreementThreshold = new PolicyParameter();
            agreementThreshold.Key = "QuestionAgreementThreshold";
            agreementThreshold.Value = new string[1] { "50" };
            parameters[1] = agreementThreshold;
            PolicyParameter approveThreshold = new PolicyParameter();
            approveThreshold.Key = "ApproveIfWorkerAgreementScoreIsAtLeast";
            approveThreshold.Value = new string[1] { "100" };
            parameters[2] = approveThreshold;
            PolicyParameter rejectThreshold = new PolicyParameter();
            rejectThreshold.Key = "RejectIfWorkerAgreementScoreIsLessThan";
            rejectThreshold.Value = new string[1] { "100" };
            parameters[3] = rejectThreshold;
            policy.PolicyName = "SimplePlurality/2011-09-01";
            policy.Parameter = parameters;

            CreateHITRequest req = new CreateHITRequest();
            req.HITTypeId = hitTypeId;
            req.Description = "Plurality test hit created by Mechanical Turk .Net SDK";
            req.HITReviewPolicy = policy;
            req.MaxAssignments = 3;
            req.Question = QuestionUtil.ConvertSingleFreeTextQuestionToXML("Hello");
            req.Reward = new Price();
            req.Reward.Amount = 2;
            req.Reward.CurrencyCode = "USD";
            req.Title = "Hello <something>";
            req.AssignmentDurationInSeconds = 60;
            req.LifetimeInSeconds = 3600;

            HIT hit = client.Proxy.CreateHIT(req);

            // output ID and Url of new HIT (URL where HIT is available on the Mechanical Turk worker website)
            Console.WriteLine("Reward: {0}", req.Reward.Amount);
            Console.WriteLine("Created HIT: {0} ({1})", hit.HITId, client.GetPreviewURL(hit.HITTypeId));
        }
Exemple #3
0
        public async Task <CreateHITResponse> CreateHIT(string title,
                                                        string description,
                                                        Price reward,
                                                        TimeSpan assignmentDuration,
                                                        IEnumerable <string> keywords,
                                                        IEnumerable <QualificationRequirement> qualificationRequirements,
                                                        IQuestion question,
                                                        TimeSpan lifetime,
                                                        TimeSpan?autoApprovalDelay          = null,
                                                        ReviewPolicy assignmentReviewPolicy = null,
                                                        ReviewPolicy hitReviewPolicy        = null,
                                                        string requesterAnnotation          = null,
                                                        int maxAssignments = 1)
        {
            var requestToken = Guid.NewGuid();
            var request      = new CreateHITRequest
            {
                Title       = title,
                Description = description,
                Reward      = reward,
                AssignmentDurationInSeconds          = (long)assignmentDuration.TotalSeconds,
                AssignmentDurationInSecondsSpecified = true,
                Keywords = string.Join(",", keywords ?? Enumerable.Empty <string>()),
                AutoApprovalDelayInSeconds          = (long)(autoApprovalDelay ?? TimeSpan.FromDays(30)).TotalSeconds,
                AutoApprovalDelayInSecondsSpecified = autoApprovalDelay != null,
                QualificationRequirement            = (qualificationRequirements ?? Enumerable.Empty <QualificationRequirement>()).ToArray(),
                LifetimeInSeconds       = (long)lifetime.TotalSeconds,
                MaxAssignments          = maxAssignments,
                MaxAssignmentsSpecified = maxAssignments != 1,
                AssignmentReviewPolicy  = assignmentReviewPolicy,
                HITReviewPolicy         = hitReviewPolicy,
                RequesterAnnotation     = requesterAnnotation,
                UniqueRequestToken      = requestToken.ToString("N")
            };

            PackQuestion(question, request);

            var resp = await ExecuteRequest <CreateHITRequest, CreateHITResponse>(request);

            return(resp);
        }