コード例 #1
0
        public HITView addHITtoList(string name, HITData data, int jobNumber)
        {
            HITView hs;

            if (name == ShortnJob.HIT_TYPE)
            {
                hs = new ShortnView(name, data as ShortnData, jobNumber);
            }
            else if (name == CrowdproofJob.HIT_TYPE)
            {
                hs = new CrowdproofView(name, data as CrowdproofData, jobNumber);
            }
            else if (name == HumanMacroJob.HIT_TYPE)
            {
                HumanMacroData hdata = data as HumanMacroData;
                hs = new HumanMacroView(name, hdata, jobNumber);
            }
            else
            {
                hs = new HITView(name, data, jobNumber);
            }
            jobMap[jobNumber] = data;

            return(hs);
        }
コード例 #2
0
        public HITView addHIT(string name, HITData data, int jobNumber)
        {
            HITView hs;

            if (name == ShortnJob.HIT_TYPE)
            {
                hs = new ShortnView(name, data as ShortnData, jobNumber);
            }
            else if (name == CrowdproofJob.HIT_TYPE)
            {
                hs = new CrowdproofView(name, data as CrowdproofData, jobNumber);
            }
            else if (name == HumanMacroJob.HIT_TYPE)
            {
                HumanMacroData hdata = data as HumanMacroData;
                hs = new HumanMacroView(name, hdata, jobNumber);
            }
            else
            {
                hs = new HITView(name, data, jobNumber);
            }
            jobMap[jobNumber] = data;

            // Assign the WPF UserControl to the ElementHost control's
            // Child property.
            sidebar.addHitView(jobNumber, hs);
            //host.Child = hs;

            // Add the ElementHost control to the form's
            // collection of child controls.
            //this.Controls.Add(host);
            return(hs);
        }
コード例 #3
0
ファイル: HumanMacroView.cs プロジェクト: tummykung/soylent
        /// <summary>
        /// HITView subclass specific to Shortn tasks.  This adds the Shortn button and additional necessary functionality.
        /// </summary>
        /// <param name="workType"></param>
        /// <param name="data"></param>
        public HumanMacroView(string workType, HumanMacroData data, int job) : base(workType, data, job)
        {
            //Globals.Soylent.soylent.Controls.Add(new System.Windows.Forms.Button());
            HumanMacroButton         = new Button();
            HumanMacroButton.Content = "View Revisions";
            HumanMacroButton.Name    = "HumanMacro";
            HumanMacroButton.Height  = 23;
            //CrowdproofButton.Width = 90;
            HumanMacroButton.IsEnabled = false;
            HumanMacroButton.Click    += new RoutedEventHandler(HumanMacro_Clicked);

            AcceptRevisions           = new Button();
            AcceptRevisions.Content   = "Accept All";
            AcceptRevisions.Name      = "AcceptRevisions";
            AcceptRevisions.Height    = 23;
            AcceptRevisions.Width     = 100;
            AcceptRevisions.IsEnabled = false;
            AcceptRevisions.Click    += new RoutedEventHandler(AcceptRevisions_Clicked);

            RejectRevisions           = new Button();
            RejectRevisions.Content   = "Reject All";
            RejectRevisions.Name      = "RejectRevisions";
            RejectRevisions.Height    = 23;
            RejectRevisions.Width     = 100;
            RejectRevisions.IsEnabled = false;
            RejectRevisions.Click    += new RoutedEventHandler(RejectRevisions_Clicked);

            buttons             = new StackPanel();
            buttons.Orientation = System.Windows.Controls.Orientation.Horizontal;
            buttons.Children.Add(AcceptRevisions);
            buttons.Children.Add(RejectRevisions);

            stages.Children.Add(HumanMacroButton);
            stages.Children.Add(buttons);

            this.data = data;
            data.register(this);

            jobTurkerName = turkerName + job;
        }
コード例 #4
0
ファイル: SoylentRibbon.cs プロジェクト: tummykung/soylent
        private void button5_Click(object sender, RibbonControlEventArgs e)
        {
            //fake p = new fake();

            //HITData p = new HITData();

            //ShortnData p = ShortnData.getCannedData();

            /*
             * TurKitSocKit.TurKitFindFixVerify tks = new TurKitSocKit.TurKitFindFixVerify();
             * //TurKitSocKit.TurKitFindFixVerifyOption tks = new TurKitSocKit.TurKitFindFixVerifyOption();
             * tks.job = 3;
             * tks.paragraph = 2;
             * tks.patches = new List<TurKitSocKit.TurKitFindFixVerifyPatch>();
             */
            //Sample tks = new Sample();

            //tks.list.Add(2);
            //tks.list.Add(3);

            HumanMacroData tks = new HumanMacroData();


            XmlSerializer x  = new XmlSerializer(tks.GetType());
            StringWriter  sw = new StringWriter();

            x.Serialize(sw, tks);
            string a = sw.ToString();

            Debug.Write(a);

            /*
             * CrowdproofData p = CrowdproofData.getCannedData();
             *
             * XmlSerializer x = new XmlSerializer(p.GetType());
             * StringWriter sw = new StringWriter();
             * x.Serialize(sw, p);
             * string a = sw.ToString();
             * Debug.Write(a);
             *
             * Microsoft.Office.Core.CustomXMLPart employeeXMLPart = Globals.Soylent.Application.ActiveDocument.CustomXMLParts.Add(a);
             */

            /*
             * string s = "";
             *
             * foreach (Microsoft.Office.Core.CustomXMLPart cus in Globals.Soylent.Application.ActiveDocument.CustomXMLParts)
             * {
             *  s = cus.XML;
             *
             * }
             *
             *
             * XmlSerializer y = new XmlSerializer(p.GetType());
             *
             * //StringReader sr = new StringReader(a);
             * StringReader sr = new StringReader(s);
             *
             * XmlReader z = XmlReader.Create(sr);
             * object obj = y.Deserialize(z);
             *
             * CrowdproofData q = obj as CrowdproofData;
             *
             * Word.Bookmark b = Globals.Soylent.Application.ActiveDocument.Bookmarks["Soylent" + q.job];
             * q.range = b.Range;
             */
        }
コード例 #5
0
ファイル: TurKitSocKit.cs プロジェクト: tummykung/soylent
        public static void HandleSocketMessage(string incomingString)
        {
            Regex  typeRegex   = new Regex("\"__type__\"\\s*:\\s*\"(?<messageType>.*)\"");
            Match  regexResult = typeRegex.Match(incomingString);
            string messageType = regexResult.Groups["messageType"].Value;

            Regex  jobtypeRegex   = new Regex("\"__jobType__\"\\s*:\\s*\"(?<jobType>.*)\"");
            Match  jobregexResult = jobtypeRegex.Match(incomingString);
            string jobType        = jobregexResult.Groups["jobType"].Value;


            JavaScriptSerializer serializer = new JavaScriptSerializer();

            if (messageType == "status")
            {
                TurKitStatus receivedObject = serializer.Deserialize <TurKitStatus>(incomingString);

                Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                HITData concernedHIT = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job];    //Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job];

                Debug.WriteLine(receivedObject.hitURL);

                //if (concernedHIT is ShortnData)
                if (jobType == "shortn")
                {
                    Debug.WriteLine("Status update for Shortn");
                    ShortnData shortenData = concernedHIT as ShortnData;
                    shortenData.updateStatus(receivedObject);
                }
                //else if (concernedHIT is CrowdproofData)
                else if (jobType == "crowdproof")
                {
                    CrowdproofData crowdproofData = concernedHIT as CrowdproofData;
                    crowdproofData.updateStatus(receivedObject);
                }
                if (jobType == "human-macro")
                {
                    Debug.WriteLine("Status update for human-macro");
                    HumanMacroData humanMacro = concernedHIT as HumanMacroData;
                    humanMacro.updateStatus(receivedObject);
                }
            }
            else if (messageType == "stageComplete")
            {
                Debug.WriteLine("Stage complete message");
                TurKitStageComplete receivedObject = serializer.Deserialize <TurKitStageComplete>(incomingString);

                if (jobType == "shortn")
                {
                    Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                    ShortnData shortenData = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job] as ShortnData;
                    //Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job] as ShortnData;
                    shortenData.stageCompleted(receivedObject);
                }
                else if (jobType == "crowdproof")
                {
                    Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                    CrowdproofData crowdproofData = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job] as CrowdproofData;
                    //CrowdproofData crowdproofData = fixthis;//Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job] as CrowdproofData;
                    crowdproofData.stageCompleted(receivedObject);
                }
            }
            else if (messageType == "complete")
            {
                if (jobType == "human-macro")
                {
                    TurKitHumanMacroResult receivedObject = serializer.Deserialize <TurKitHumanMacroResult>(incomingString);
                    Debug.WriteLine("\nHUMAN MACRO COMPLEEETE******");
                    Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                    HumanMacroData humanMacro = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job] as HumanMacroData;
                    //HumanMacroData humanMacro = fixthis;//Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job] as HumanMacroData;
                    humanMacro.processSocKitMessage(receivedObject);
                }
                else if (jobType == "shortn")
                {
                    TurKitFindFixVerify receivedObject         = serializer.Deserialize <TurKitFindFixVerify>(incomingString);
                    Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                    ShortnData shortenData = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job] as ShortnData;    //Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job] as ShortnData;
                    shortenData.processSocKitMessage(receivedObject);
                }
                else if (jobType == "crowdproof")
                {
                    TurKitFindFixVerify receivedObject         = serializer.Deserialize <TurKitFindFixVerify>(incomingString);
                    Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                    CrowdproofData crowdproofData = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job] as CrowdproofData;
                    //CrowdproofData crowdproofData = fixthis;//Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job] as CrowdproofData;
                    crowdproofData.processSocKitMessage(receivedObject);
                }
            }
            else if (messageType == "exception")
            {
                Debug.WriteLine("TurKit exception thrown:");
                TurKitException receivedObject = serializer.Deserialize <TurKitException>(incomingString);
                Debug.WriteLine(receivedObject.exceptionString);

                Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                SoylentPanel panel        = Globals.Soylent.soylentMap[doc];
                HITData      concernedHIT = panel.jobMap[receivedObject.job];

                panel.Invoke(new HITData.showErrorDelegate(concernedHIT.showError), new object[] { receivedObject.exceptionString });
                //concernedHIT.showError(receivedObject.exceptionCode);
            }
            //Debug.WriteLine("got it!");
        }
コード例 #6
0
ファイル: Soylent.cs プロジェクト: tummykung/soylent
        void Application_DocumentBeforeSave(Word.Document Doc, ref bool SaveAsUI, ref bool Cancel)
        {
            foreach (Microsoft.Office.Core.CustomXMLPart xmlPart in Globals.Soylent.Application.ActiveDocument.CustomXMLParts)
            {
                if (!(xmlPart.BuiltIn))
                {
                    xmlPart.Delete();
                }
            }
            foreach (object obj in soylentMap[Doc].sidebar.jobs.Children)
            {
                if (!(obj is StackPanel))
                {
                    continue;
                }
                StackPanel elem = obj as StackPanel;
                foreach (object elem2 in elem.Children)
                {
                    HITData raw;
                    if (elem2 is HITView)
                    {
                        raw = (elem2 as HITView).data;
                    }
                    else
                    {
                        raw = (elem2 as HITViewStub).data;
                    }

                    if (raw is ShortnData)
                    {
                        ShortnData hit = raw as ShortnData;

                        XmlSerializer x  = new XmlSerializer(hit.GetType());
                        StringWriter  sw = new StringWriter();
                        x.Serialize(sw, hit);
                        string xml = sw.ToString();
                        Microsoft.Office.Core.CustomXMLPart xmlPart = Globals.Soylent.Application.ActiveDocument.CustomXMLParts.Add(xml);
                    }
                    else if (raw is CrowdproofData)
                    {
                        CrowdproofData hit = raw as CrowdproofData;

                        XmlSerializer x  = new XmlSerializer(hit.GetType());
                        StringWriter  sw = new StringWriter();
                        x.Serialize(sw, hit);
                        string xml = sw.ToString();
                        Microsoft.Office.Core.CustomXMLPart xmlPart = Globals.Soylent.Application.ActiveDocument.CustomXMLParts.Add(xml);
                    }
                    else if (raw is HumanMacroData)
                    {
                        HumanMacroData hit = raw as HumanMacroData;

                        XmlSerializer x  = new XmlSerializer(hit.GetType());
                        StringWriter  sw = new StringWriter();
                        x.Serialize(sw, hit);
                        string xml = sw.ToString();
                        Microsoft.Office.Core.CustomXMLPart xmlPart = Globals.Soylent.Application.ActiveDocument.CustomXMLParts.Add(xml);
                    }
                }
            }
        }
コード例 #7
0
ファイル: Soylent.cs プロジェクト: tummykung/soylent
        void Application_DocumentOpen(Word.Document doc)
        {
            SoylentPanel  soylent = soylentMap[doc];
            List <string> rawHITs = new List <string>();

            //One problem: loads jobs in reverse order.  This is easy to fix.  But is either correct?
            foreach (Microsoft.Office.Core.CustomXMLPart xmlPart in Globals.Soylent.Application.ActiveDocument.CustomXMLParts)
            {
                string xml         = xmlPart.XML;
                Regex  typeRegex   = new Regex("<job>(.*?)</job>"); //To filter out Soylent jobs from the xml parts Word automatically saves
                Match  regexResult = typeRegex.Match(xml);
                string jobString   = regexResult.ToString();
                if (jobString.Length < 6)
                {
                    continue;
                }

                int job = Int32.Parse(jobString.Substring(5, jobString.Length - 11));

                jobToDoc[job] = doc;
                rawHITs.Add(xml);
            }
            rawHITs.Reverse();

            foreach (string xml in rawHITs)
            {
                StringReader sr = new StringReader(xml);
                XmlReader    xr = XmlReader.Create(sr);

                if (new Regex("</ShortnData>").Match(xml).Length > 0)
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(ShortnData));
                    object        raw        = serializer.Deserialize(xr);

                    ShortnData hit = raw as ShortnData;

                    // HACK: have to do this after deserialization because numParagraphs is 0 when the object is deserialized
                    foreach (StageData stage in hit.stages)
                    {
                        stage.FixParagraphNumber(hit.numParagraphs);
                    }

                    Word.Bookmark a = Globals.Soylent.Application.ActiveDocument.Bookmarks["Soylent" + hit.job];
                    hit.range = a.Range;

                    if (hit.jobDone)
                    {
                        ShortnJob s = new ShortnJob(hit, hit.job, false);
                        //Use saved TurKit messages to recreate the results.
                        foreach (TurKitSocKit.TurKitStageComplete message in hit.stageCompletes)
                        {
                            hit.terminateStage(message);
                        }
                        foreach (TurKitSocKit.TurKitFindFixVerify message in hit.findFixVerifies)
                        {
                            hit.postProcessSocKitMessage(message);
                        }
                    }
                    else
                    {
                        // This will work if you are restarting it on the same machine, where the
                        // TurKit javascript file still sits. Otherwise, it will restart the job.
                        ShortnJob s = new ShortnJob(hit, hit.job, true);
                    }
                }

                else if (new Regex("</CrowdproofData>").Match(xml).Length > 0)
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(CrowdproofData));
                    object        raw        = serializer.Deserialize(xr);

                    CrowdproofData hit = raw as CrowdproofData;

                    foreach (StageData stage in hit.stages)
                    {
                        stage.FixParagraphNumber(hit.numParagraphs);
                    }

                    Word.Bookmark a = Globals.Soylent.Application.ActiveDocument.Bookmarks["Soylent" + hit.job];
                    hit.range = a.Range;

                    //SoylentRibbon.setLastJob(hit.job);

                    if (hit.jobDone)
                    {
                        CrowdproofJob s = new CrowdproofJob(hit, hit.job, false);
                        //Use saved TurKit messages to recreate the results.
                        foreach (TurKitSocKit.TurKitStageComplete message in hit.stageCompletes)
                        {
                            hit.terminateStage(message);
                        }
                        foreach (TurKitSocKit.TurKitFindFixVerify message in hit.findFixVerifies)
                        {
                            hit.postProcessSocKitMessage(message);
                        }
                    }
                    else
                    {
                        CrowdproofJob s = new CrowdproofJob(hit, hit.job, true);
                    }
                }

                else if (new Regex("</HumanMacroData>").Match(xml).Length > 0)
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(HumanMacroData));
                    object        raw        = serializer.Deserialize(xr);

                    HumanMacroData hit = raw as HumanMacroData;

                    foreach (StageData stage in hit.stages)
                    {
                        stage.FixParagraphNumber(hit.numParagraphs);
                    }

                    Word.Bookmark a = Globals.Soylent.Application.ActiveDocument.Bookmarks["Soylent" + hit.job];
                    hit.range = a.Range;

                    //SoylentRibbon.setLastJob(hit.job);

                    if (hit.jobDone)
                    {
                        HumanMacroJob s = new HumanMacroJob(hit, hit.job, false);
                        //Use saved TurKit messages to recreate the results.
                        foreach (TurKitSocKit.TurKitHumanMacroResult message in hit.messages)
                        {
                            hit.postProcessSocKitMessage(message);
                        }
                        hit.finishStageData();
                    }
                    else
                    {
                        HumanMacroJob s = new HumanMacroJob(hit, hit.job, true);
                    }
                }
            }
        }
コード例 #8
0
        public void startHumanMacroTask(AmazonKeys keys)
        {
            HumanMacroData data = hdata as HumanMacroData;

            JavaScriptSerializer js = new JavaScriptSerializer();
            string inputs;

            if (data.separator == HumanMacroData.Separator.Paragraph)
            {
                string[] pgraphs;

                if (data.test == HumanMacroData.TestOrReal.Test)
                {
                    pgraphs = new string[1];
                }
                else
                {
                    pgraphs = new string[data.range.Paragraphs.Count];
                }
                for (int i = 0; i < data.range.Paragraphs.Count; i++)
                {
                    Word.Paragraph paragraph = data.range.Paragraphs[i + 1];
                    string         temp      = paragraph.Range.Text;
                    temp       = temp.Trim();
                    pgraphs[i] = temp;

                    /*
                     * Patch patch = new Patch(paragraph.Range, new List<string>());
                     * patch.original = paragraph.Range.Text;
                     */
                    HumanMacroPatch patch = new HumanMacroPatch(paragraph.Range, paragraph.Range.Start - data.range.Start, paragraph.Range.End - data.range.Start);
                    patch.original = paragraph.Range.Text;
                    data.patches.Add(patch);
                    if (data.test == HumanMacroData.TestOrReal.Test)
                    {
                        break;
                    }
                }
                inputs = js.Serialize(pgraphs);
            }
            else
            {
                string[] pgraphs;

                if (data.test == HumanMacroData.TestOrReal.Test)
                {
                    pgraphs = new string[1];
                }
                else
                {
                    pgraphs = new string[data.range.Sentences.Count];
                }
                for (int i = 0; i < data.range.Sentences.Count; i++)
                {
                    Word.Range range = data.range.Sentences[i + 1];

                    string temp = range.Text;
                    // Whitespace characters in the middle of sentences will not be removed
                    temp       = temp.Trim();
                    pgraphs[i] = temp;

                    //Patch patch = new Patch(range, new List<string>());
                    HumanMacroPatch patch = new HumanMacroPatch(range, range.Start - data.range.Start, range.End - data.range.Start);
                    patch.original = range.Text;
                    data.patches.Add(patch);

                    if (data.test == HumanMacroData.TestOrReal.Test)
                    {
                        break;
                    }
                }
                inputs = js.Serialize(pgraphs);
            }

            inputs = "var inputs = " + inputs + ";";

            // figure out whether there are one or two spaces between sentences
            string firstSentence          = data.range.Paragraphs[1].Range.Sentences[1].Text;
            string spacesBetweenSentences = " ";

            if (firstSentence.EndsWith("  "))
            {
                spacesBetweenSentences = "  ";
            }
            data.patchesFound(spacesBetweenSentences);

            string numSpaces = "var sentence_separator = '" + spacesBetweenSentences + "';";

            int request = hdata.job;

            string requestLine = "var soylentJob = " + request + ";";
            string debug       = "var debug = " + (Soylent.DEBUG ? "true" : "false") + ";";

            string reward       = "var reward = " + data.reward + ";";
            string redundancy   = "var redundancy = " + data.redundancy + ";";
            string title        = "var title = '" + data.title + "';";
            string subtitle     = "var subtitle = '" + data.subtitle + "';";
            string instructions = "var instructions = '" + data.instructions + "';";

            string[] script = File.ReadAllLines(Soylent.GetAppDirectory() + @"\turkit\templates\human-macro\macro.data.js");

            int new_lines = 9;

            string[] newScript = new string[new_lines + script.Length];
            newScript[0] = requestLine;
            newScript[1] = inputs;
            newScript[2] = debug;
            newScript[3] = numSpaces;
            newScript[4] = reward;
            newScript[5] = redundancy;
            newScript[6] = title;
            newScript[7] = subtitle;
            newScript[8] = instructions;
            Array.Copy(script, 0, newScript, new_lines, script.Length);

            string requestFile = Soylent.GetDataDirectory() + @"\active-hits\macro." + request + ".data.js";

            File.WriteAllLines(requestFile, newScript, Encoding.UTF8);

            string arguments = " -jar " + TURKIT_VERSION + " -f \"" + requestFile + "\" -a " + keys.amazonID + " -s " + keys.secretKey + " -o 100 -h 1000";

            if (Soylent.DEBUG)
            {
                arguments += " -m sandbox";
            }
            else
            {
                arguments += " -m real";
            }

            //ProcessInformation info = new ProcessInformation("java", arguments, rootDirectory + @"\turkit", Soylent.DEBUG);
            info = new ProcessInformation("java", arguments, Soylent.GetAppDirectory() + @"\turkit", SHOW_WINDOW);

            TimerCallback callback = ExecuteProcess;
            int           timer    = 60 * 1000;

            if (Soylent.DEBUG)
            {
                timer = 30 * 1000;
            }
            turkitLoopTimer = new Timer(callback, info, 0, timer);  // starts the timer every 60 seconds
        }