static public object Cropped(this Stroq stroke, Stroq balance, CropTest test) { object sel = null; DictLookup dict = null; if (!stroke.Property.Exists(CROP)) { dict = new DictLookup(); stroke.Property[CROP] = dict; } else { dict = (DictLookup)stroke.Property[CROP]; } if (dict.ContainsKey(test)) { sel = dict[test]; } else { sel = test(stroke, balance); dict.Add(test, sel); } return(sel); }
static public object ScribbledOver(this Stroq stroke, ScribbleTest test) { object sel = null; DictLookup dict = null; if (!stroke.Property.Exists(SCRIBBLE)) { dict = new DictLookup(); stroke.Property[SCRIBBLE] = dict; } else { dict = (DictLookup)stroke.Property[SCRIBBLE]; } if (dict.ContainsKey(test)) { sel = dict[test]; } else { sel = test(stroke); dict.Add(test, sel); } return(sel); }
Random r = new Random(); // can be done centrally for the entire application // // GET: /Definition/ //[Route("def/{id}")] public ActionResult Index(String id = null) { String word = id; if (word == null) { word = "syzygy"; } LookupResult result = DictLookup.Get(word); String def = result.Definition.First().Text; String[] titles = new String[] { "Definition of the word “" + word + "”", "This is what we mean by “" + word + "”", "“" + word + "” means...", "“" + word + "” has the meaning...", "When we use “" + word + "” we mean...", "What is “" + word + "”?", "What does “" + word + "” mean?" }; String[] descriptions = new String[] { "“" + word + "” is " + def, word + " - " + def, "Definition: " + def }; ViewBag.Word = word; ViewBag.Description = descriptions[r.Next(descriptions.Length)]; ViewBag.Title = titles[r.Next(titles.Length)]; // todo: make sure name comes from dictionary (so doesn't contain funny characters WebPageBitmap.LoadBitmapSTA(word, Config.WebRoot); ViewBag.Image = Config.GetImagePath(word, ShareMode.Definition); ViewBag.Url = Request.Url.AbsoluteUri; // needs to be set same as actual URL, probably helps FB to know how to cache, can test at https://developers.facebook.com/tools/debug/ //ViewBag.Audio = "http://mapto.ko64eto.com/po-zodia.mp3"; // just a placeholder return(View()); }
static public object Lassoed(this Stroq stroke, LassoTest test) { object sel = null; DictLookup dict = null; if (!stroke.Property.Exists(LASSO)) { dict = new DictLookup(); stroke.Property[LASSO] = dict; } else { dict = (DictLookup)stroke.Property[LASSO]; } if (dict.ContainsKey(test)) { sel = dict[test]; } else { double threshold = stroke.GetBounds().MaxDim * .2; Stroq lasso = stroke; // truncate the lasso where it retraces closest to its starting point. for (int i = stroke.Count - 1; i > Math.Max(stroke.Count / 2, stroke.Cusps()[-2].index); i--) { if ((stroke[i] - stroke[0]).Length < threshold) { List <Pt> lassoPts = new List <Pt>(); for (int j = 0; j < i; j++) { lassoPts.Add(stroke[j]); } lasso = new Stroq(lassoPts.ToArray()); } } sel = test(lasso); dict.Add(test, sel); } return(sel); }
async void ExecuteFindDefinitionCommand() { if (String.IsNullOrEmpty(Exercise.Word)) { await _pageDialogService.DisplayAlertAsync("Error", "Please provide a word first.", "Ok"); return; } try { var lookup = await DictLookup.Get(Exercise.Word); if (lookup == null) { return; } var sense = lookup.Results.FirstOrDefault().Senses.FirstOrDefault(); if (sense.Examples != null) { Exercise.Phrase = sense.Examples.FirstOrDefault().Text; Exercise.Phrase = char.ToUpper(Exercise.Phrase[0]) + Exercise.Phrase.Substring(1); } if (sense.Definition != null) { Exercise.Definition = sense.Definition.FirstOrDefault(); Exercise.Definition = char.ToUpper(Exercise.Definition[0]) + Exercise.Definition.Substring(1); } RaisePropertyChanged("Exercise"); } catch (Exception e) { Debug.WriteLine(e.ToString()); } }