[Script] MLDatalabeler script help

Discussion in 'mTurk Scripts & Resources' started by hyperkilljoy, Sep 4, 2019.

  1. hyperkilljoy

    hyperkilljoy Active Turker

    Messages:
    206
    Gender:
    Male
    Ratings:
    +216
    If you're doing a lot of batches, is there a way to get the window to auto-focus so you don't have to click inside the window with your mouse? The script seems to work viewing the frame source, but not after the hit is clicked in panda crazy
     
  2. DarkChild

    DarkChild Survey Slinger

    Messages:
    6,723
    Gender:
    Male
    Ratings:
    +11,312
    You're either including the wrong site at the top of the script or you need to use a timeout or document.ready because the script is firing before the frame loads.
     
    • Today I Learned Today I Learned x 2
  3. hyperkilljoy

    hyperkilljoy Active Turker

    Messages:
    206
    Gender:
    Male
    Ratings:
    +216
    It's weird because some days it works, some days it says the form is null. I have like a wait timer of 10 seconds. Same page layout

    Why would this work one day
    const answer = document.querySelector("body > crowd-form > form > crowd-classifier");
    then it breaks

    and now this works

    const answer = document.querySelector("body > crowd-form > crowd-classifier")

    In the page hierarchy, form is still before crowd-classifier


    Some real voodoo is going down.
    12 minutes later the original works again and the new doesn't.

    I guess I don't understand web dev
     
    Last edited: Sep 28, 2019
  4. hyperkilljoy

    hyperkilljoy Active Turker

    Messages:
    206
    Gender:
    Male
    Ratings:
    +216
    Woking on Jquery version for the text job
    Code:
        let text = $("classification-target").text().trim();
    
        if (text == `al henry albert al henry jr. ( born february 9 1949 ) is a retired center who played in the national basketball association . he was drafted in the first round of the 1970 nba draft by the philadelphia 76ers and would play two seasons with the team .`) {
            //Do Something
            console.log("Classify al henry text");
        }
        else if (text == `gilia austro-occidentalis gilia austro-occidentalis is a species of flowering plant in the phlox family known by the common name southwestern gilia . it is endemic to the central coast ranges of california where it grows in local hill and valley habitat .`) {
            //Do Something
            console.log("Classify gilia text");
        }
        else {
         console.log("No text matches");
        }
    There's gotta be a way to check for just one word, right? Like gilia instead of the whole paragraph.
     
  5. DarkChild

    DarkChild Survey Slinger

    Messages:
    6,723
    Gender:
    Male
    Ratings:
    +11,312
    For this, your selectors are really specific which is causing it to be messy. You can just target crowd-classifier with jquery and use it's index number, or select it numerous different ways that are less specific.

    you can use a statement like .textContent.indexOf('your words here') > -1 to avoid having to use a full statement match.
     
  6. hyperkilljoy

    hyperkilljoy Active Turker

    Messages:
    206
    Gender:
    Male
    Ratings:
    +216
    I've got this down so far.

    Code:
    // ==UserScript==
    // @name         MLDL JQuerry
    // @namespace    http://tampermonkey.net/
    // @author       Hyperkilljoy (credits to Fuzzy_Dunlop, Ornac, & DarkChild of www.turkerview.com for the help)
    // @version      0.47z
    // @description  Basic starting blocks for 3 of the MDataLabeler Mturk tasks (Answer Validation, Classify Text & Classify Image)
    // @grant        GM_log
    // @include      /^http(s)?://worker\.mturk\.com/
    // @include      https://bxcb.public-workforce.*
    // @require      http://code.jquery.com/jquery-2.1.4.min.js
    // ==/UserScript==
    
    if (document.querySelector("iframe")) document.querySelector("iframe");
    
    $(window).onload=setTimeout(function()
    {
        'use strict';   
        try {
            let text = $("classification-target").text().trim();
    
            if (text.indexOf('al henry') > -1) {
                //Do Something
                console.log("Classify al henry text");
            }
            else if (text.indexOf('gilia austro-occidentalis') > -1) {
                //Do Something
                console.log("Classify gilia text");
            }
            else if (text.indexOf('thin lizzy') > -1) {
                console.log("Thin Lizzy text");
            }
            else if (text.indexOf('volkswagen passat nms') > -1) {
                console.log("volkswagen passat nms text");
            }
            else if (text.indexOf('lycée charlemagne') > -1) {
                console.log("lycée charlemagne text");
            }
            else {
                console.log("Haven't found yet");
            }
        } catch(e) {
    
        }
    }, 3000);
    Thoughts?
     
  7. hyperkilljoy

    hyperkilljoy Active Turker

    Messages:
    206
    Gender:
    Male
    Ratings:
    +216
    Well All that needs to be added is the auto-submit, but here is the Jquery script for just the text Categorization.
    Code:
    // ==UserScript==
    // @name         MLDL Classify Text JQuerry
    // @namespace    http://tampermonkey.net/
    // @author       Hyperkilljoy (credits to Fuzzy_Dunlop, Ornac, & DarkChild of www.turkerview.com for the help)
    // @version      0.54g
    // @description  Basic starting blocks for the MDataLabeler Mturk task (Classify Text)
    // @grant        GM_log
    // @include      /^http(s)?://worker\.mturk\.com/
    // @include      https://bxcb.public-workforce.*
    // @require      http://code.jquery.com/jquery-3.4.1.min.js
    // ==/UserScript==
    
    if (document.querySelector("iframe")) document.querySelector("iframe");
    let dict = {
        "al henry": 4,
        "gilia austro-occidentalis": 11,
        "thin lizzy": 12,
        "volkswagen passat nms": 6,
        "lycée charlemagne": 7,
        "park jong-woo": 4,
        "polyptychus": 10,
        "granville primary": 2,
        "Cho": 4,
        "mapire river": 8,
        "choi yun-hee": 4
    };
    $(window).onload=setTimeout(function()
    {
        'use strict';
        let text = $("classification-target").text().trim();
        function Button(number) {
            let button = document.querySelector("body > crowd-form > form > crowd-classifier")
            .shadowRoot.querySelector(`div > div > div > div > awsui-app-layout.awsui-util-no-gutters > div > main > div > div > span > span > div > div >
                    div > div > div > button:nth-child(` + number + `)`);
            $(button).trigger("click");
        }
     
        for (var key in dict) {
            if(text.indexOf(key) > -1) {
                Button(dict[key]);
            }
        }
        console.log("Haven't found text yet");
    }, 2750);
    
    It could probably be cleaned up a bit more, but AFAIK you had to use JS to get into the shadowroot as Jquery doesn't traverse into it.

    Any feedback is appreciated!
     
    Last edited: Dec 1, 2019
  8. Ornac

    Ornac Survey Slinger TurkerView Masters

    Messages:
    8,739
    Gender:
    Male
    Ratings:
    +11,092
    I haven't had time to play with it. Still hitting the morning coffee. One thing though. I would be careful about having it auto-submit.

    There are a couple of other concerns, but the first and big reason: This would break the https://www.mturk.com/acceptable-use-policy. Specifically, "(1) do not serve as a substitute for your human judgment to complete work." It should be fine to set it to one key submit after the script chooses the box, but the user needs to be involved at some level.
     
  9. hyperkilljoy

    hyperkilljoy Active Turker

    Messages:
    206
    Gender:
    Male
    Ratings:
    +216
    Thanks for the heads up!
     
    • Like Like x 1