public void terminateStage(TurKitSocKit.TurKitStageComplete donezo) { StageData stage = null; if (donezo.stage == "find") { stage = findStageData; } else if (donezo.stage == "fix") { stage = fixStageData; } else if (donezo.stage == "verify") { stage = verifyStageData; } stage.terminateStage(donezo); (view as CrowdproofView).updateView(); }
public override void updateStatus(TurKitSocKit.TurKitStatus status) { string stringtype = status.stage; System.Diagnostics.Debug.WriteLine(stringtype); //System.Diagnostics.Debug.WriteLine("^^^^^ stringtype ^^^^^^"); /* ResultType type = typeMap[stringtype]; StageData stage = stages[type]; */ StageData stage = null;//stages[type]; if (stringtype == "find") { stage = findStageData; } else if (stringtype == "fix") { stage = fixStageData; } else if (stringtype == "verify") { stage = verifyStageData; } //stage.updateStage(status.numCompleted, status.paragraph); stage.updateStage(status); (view as CrowdproofView).updateView(); cost = (view as CrowdproofView).cost; //System.Diagnostics.Debug.WriteLine("GOT A ************"); }
public void processSocKitMessage(TurKitSocKit.TurKitFindFixVerify message) { findFixVerifies.Add(message); postProcessSocKitMessage(message); /* Word.Range curParagraphRange = range.Paragraphs[message.paragraph + 1].Range; Word.Document doc = Globals.Soylent.jobToDoc[job]; foreach (TurKitSocKit.TurKitFindFixVerifyPatch tkspatch in message.patches) { int start = curParagraphRange.Start + tkspatch.editStart; int end = curParagraphRange.Start + tkspatch.editEnd; //Word.Range patchRange = Globals.Soylent.Application.ActiveDocument.Range(start, end); //New range for this patch, yay! Word.Range patchRange = doc.Range(start, end); List<string> alternatives = new List<string>(); foreach (TurKitSocKit.TurKitFindFixVerifyOption option in (from option in tkspatch.options where option.field == "revision" select option)) { alternatives.AddRange(from alternative in option.alternatives select alternative.editedText); } List<string> reasons = new List<string>(); foreach (TurKitSocKit.TurKitFindFixVerifyOption option in (from option in tkspatch.options where option.field == "reason" select option)) { reasons.AddRange(from alternative in option.alternatives select alternative.text); } CrowdproofPatch thisPatch = new CrowdproofPatch(patchRange, alternatives, reasons); // add the original as an option //thisPatch.replacements.Add(tkspatch.originalText); patches.Add(thisPatch); } paragraphsCompleted++; if (paragraphsCompleted == numParagraphs) //If we have done all paragraphs, make them available to the user! { //TODO: use a delegate. //Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].Invoke(new crowdproofDelegate(this.crowdproofDataReceived), new object[] { }); Globals.Soylent.soylentMap[doc].Invoke(new crowdproofDelegate(this.crowdproofDataReceived), new object[] { }); this.tk.turkitLoopTimer.Dispose(); //CrowdproofView view = this.view as CrowdproofView; //view.crowdproofDataReceived(); //this.AnnotateResult(); } */ }
public void stageCompleted(TurKitSocKit.TurKitStageComplete donezo) { stageCompletes.Add(donezo); StageData stage = null; if (donezo.stage == "find") { stage = findStageData; } else if (donezo.stage == "fix") { stage = fixStageData; } else if (donezo.stage == "verify") { stage = verifyStageData; } stage.terminatePatch(donezo.paragraph, donezo.patchNumber); }
/// <summary> /// This function should only be used to reprocess a StageComplete message after loading a saved document /// </summary> /// <param name="message"></param> public void terminateStage(TurKitSocKit.TurKitStageComplete message) { //totalRequested[message.paragraph] = new List<int>(); while (totalRequested.Count < message.paragraph + 1) { totalRequested.Add(new List<int>()); } while (totalRequested[message.paragraph].Count < message.patchNumber + 1) { totalRequested[message.paragraph].Add(0); } totalRequested[message.paragraph][message.patchNumber] = message.totalRequested; /* done[message.paragraph] = new List<bool>(); done[message.paragraph].Add(true); */ while (numCompletedperParagraph.Count < message.paragraph + 1) { numCompletedperParagraph.Add(new List<int>()); } while (numCompletedperParagraph[message.paragraph].Count < message.patchNumber + 1) { numCompletedperParagraph[message.paragraph].Add(0); } numCompletedperParagraph[message.paragraph][message.patchNumber] = message.totalRequested; moneySpent = message.payment * numCompleted; if (listener != null) { listener.notify(); } }
/// <summary> /// Updates the Model with a new status message and then notifies the listener /// </summary> /// <param name="status"></param> public void updateStage(TurKitSocKit.TurKitStatus status) { if (numPatches[status.paragraph] != status.totalPatches) // we need to update the total number of patches { numPatches[status.paragraph] = status.totalPatches; numCompletedperParagraph[status.paragraph] = new List<int>(); totalRequested[status.paragraph] = new List<int>(); // need to initialize the list for the number of patches we have for (int i = 0; i < status.totalPatches; i++) { numCompletedperParagraph[status.paragraph].Add(0); totalRequested[status.paragraph].Add(0); done[status.paragraph].Add(false); } } if (done[status.paragraph][status.patchNumber]) { return; } numCompletedperParagraph[status.paragraph][status.patchNumber] = status.numCompleted; moneySpent = status.payment * numCompleted; totalRequested[status.paragraph][status.patchNumber] = status.totalRequested; if (listener != null) { listener.notify(); } }
/// <summary> /// Processes a shortn message, one that contains the final results of the algorithm. One per paragraph /// </summary> /// <param name="message"></param> public void processSocKitMessage(TurKitSocKit.TurKitFindFixVerify message) { findFixVerifies.Add(message); postProcessSocKitMessage(message); }
public void postProcessSocKitMessage(TurKitSocKit.TurKitFindFixVerify message) { if (paragraphsCompleted.Contains(message.paragraph)) { return; // we've already processed this paragraph } Word.Range curParagraphRange = range.Paragraphs[message.paragraph + 1].Range; int nextStart = 0; //Is always the location where the next patch (dummy or otherwise) should start. int nextEnd; //Is where the last patch ended. Kinda poorly named. Tells us if we need to add a dummy patch after the last real patch Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[this.job]; foreach (TurKitSocKit.TurKitFindFixVerifyPatch tkspatch in message.patches) { //For text in between patches, we create dummy patches. if (tkspatch.editStart > nextStart) { nextEnd = tkspatch.editStart; int dummyStart = curParagraphRange.Start + nextStart; int dummyEnd = curParagraphRange.Start + nextEnd; Word.Range dummyRange = doc.Range(dummyStart, dummyEnd); DummyPatch dummyPatch = new DummyPatch(dummyRange); Debug.WriteLine("dummy patch: " + dummyRange.Text); patches.Add(dummyPatch); } int start = curParagraphRange.Start + tkspatch.editStart; int end = curParagraphRange.Start + tkspatch.editEnd; Word.Range patchRange = doc.Range(start, end); Debug.WriteLine("new patch: " + patchRange.Text); List<string> alternatives = new List<string>(); foreach (TurKitSocKit.TurKitFindFixVerifyOption option in (from option in tkspatch.options where option.editsText select option)) { alternatives.AddRange(from alternative in option.alternatives select alternative.editedText); } ShortnPatch thisPatch = new ShortnPatch(patchRange, alternatives); // add the original as an option thisPatch.replacements.Add(tkspatch.originalText); patches.Add(thisPatch); nextStart = tkspatch.editEnd; } //If the last patch we found isn't the end of the paragraph, create a DummyPatch if (nextStart < (curParagraphRange.Text.Length - 1)) { nextEnd = curParagraphRange.Text.Length; Word.Range dummyRange = doc.Range(curParagraphRange.Start + nextStart, curParagraphRange.End); Debug.WriteLine("dummy patch: " + dummyRange.Text); DummyPatch dummyPatch = new DummyPatch(dummyRange); patches.Add(dummyPatch); } paragraphsCompleted.Add(message.paragraph); if (paragraphsCompleted.Count() == numParagraphs) //If we have done all paragraphs, make them available to the user! { //TODO: use a delegate. if (this.tk.turkitLoopTimer != null) { this.tk.turkitLoopTimer.Dispose(); } this.jobDone = true; /* foreach (Patch patch in patches) { Debug.WriteLine(patch.range.Start + " - " + patch.range.End + " : " + patch.range.Text + " || " + (patch is DummyPatch)); } */ returnShortnResults(); } }
public override void updateStatus(TurKitSocKit.TurKitStatus status) { StageData stage = macroStageData;//stages[HITData.ResultType.Macro]; //stage.updateStage(status.numCompleted, status.paragraph); stage.numParagraphs = patches.Count; stage.updateStage(status); (view as HumanMacroView).updateView(); cost = (view as HumanMacroView).cost; //System.Diagnostics.Debug.WriteLine("GOT A ************"); }
public void processSocKitMessage(TurKitSocKit.TurKitHumanMacroResult message) { messages.Add(message); postProcessSocKitMessage(message); /* Patch patch = patches[message.input]; if (patch.replacements.Count == 0) { foreach (string replacement in message.alternatives) { if (this.separator == Separator.Sentence) { patch.replacements.Add(replacement + spacesBetweenSentences); } else { patch.replacements.Add(replacement); } } numberReturned++; } if (numberReturned == patches.Count) { this.tk.turkitLoopTimer.Dispose(); Globals.Soylent.soylentMap[Globals.Soylent.jobToDoc[this.job]].Invoke(new resultsBackDelegate(this.resultsBack), new object[] { }); } */ }
public abstract void updateStatus(TurKitSocKit.TurKitStatus status);