private void splitSentence(WordData sentence) { string description = sentence.GetDesc(); char[] descriptionArr = description.ToLower().ToCharArray(); int splitLength; //sentence will be split in four parts int numSpaces = 0; List<int> spaceIndices = new List<int>(); spaceIndices.Add(0); for (int i = 0; i < descriptionArr.Length; i++) //find spaces { if (char.IsWhiteSpace(descriptionArr[i])) { numSpaces++; spaceIndices.Add(i); } } splitLength = numSpaces / 4; if (splitLength > 0) { int k = 0; int j; string str; for (j=0; j < numSpaces; j = +splitLength) { str = new string(descriptionArr, spaceIndices[j], spaceIndices[j + splitLength]); fragments[k] = str; k++; } str = new string(descriptionArr, spaceIndices[j], descriptionArr.Length); fragments[3] = str; } }
public WordData(WordData wd) { this.word = wd.word; this.translation = wd.translation; this.description = wd.description; this.id = wd.id; }
/// <summary> /// Reads and processed the user input /// </summary> /// <param name="wordData">The data object that holds information for the current word</param> public void GetUserInput(WordData wordData) { Console.WriteLine("The secret word is " + wordData.HiddenWord); Console.Write("Enter your guess: "); string inputString = Console.ReadLine(); this.ProcessInput(inputString); }
public void InitGame () { grid = GetComponent<Grid> (); wordData = GetComponent<WordData> (); selectedTiles = new List<Tile> (); selectedTile = null; grid.BuildGrid (); statusLabel.text = ""; }
//https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading //Saves to local storage public void Save() { BinaryFormatter bf = new BinaryFormatter (); FileStream file = File.Create (Application.persistentDataPath + "/wordInfo.dat"); WordData data = new WordData (); data.unsolvedWords = unsolvedWords; data.solvedWords = solvedWords; bf.Serialize (file, data); file.Close (); }
public string FindMatchingText(WordData wd) { string description = wd.GetDesc(); string word = wd.GetWord(); char[] descriptionArr = description.ToLower().ToCharArray(); char[] wordArr = word.ToLower().ToCharArray(); for (int i = 0; i < descriptionArr.Length; i++) { if (CheckCurrentIndex(i, descriptionArr, wordArr)) { return addBeginEnd(i, description, word); } } return description.Insert(0, beginWord + word + endWord + "\n"); }
public void CheckWord_Hello_InList_MustReturn_False() { string wordToSearch = "HELLO"; SettingsModel settingsModel = new SettingsModel() { Words = "VITAMIN A;FIBER;MICKEY MOUSE" }; var mockSettings = new Mock <IOptions <SettingsModel> >(); mockSettings.Setup(w => w.Value).Returns(settingsModel); var wordData = new WordData(mockSettings.Object); var result = wordData.ValidateWordInList(wordToSearch); Assert.False(result); }
public List <LetterData> FindCorrectLetters(WordData selectedWord, List <LetterData> wordLetters) { var vocabularyHelper = AppManager.I.VocabularyHelper; var eligibleLetters = new List <LetterData>(); var badWords = new List <WordData>(currentRound_words); badWords.Remove(selectedWord); foreach (var letter in wordLetters) { // Avoid using letters that appeared in previous words if (vocabularyHelper.IsLetterContainedInAnyWord(letter, badWords)) { continue; } eligibleLetters.Add(letter); } return(eligibleLetters); }
public void LaunchGrenades(WordData wordData) { _launching = true; if (_grenadeObjectPool == null) { PopulatePool(); } slower.slowingValue = stage.slowingSpeed; CharacterData[] charactersData = wordData.charsData; int worldLength = wordData.word.Length; int[] indicies = GetLauncherIndicies(worldLength); for (int i = 0; i < worldLength; i++) { _grenadeObjectPool[i].SetGrenade(splines[indicies[i]], stage.launchspeed, charactersData[i], stageCamera); _grenadeObjectPool[i].Launch(); } }
private void FillModel(WordData model, CategorizedWord catWord) { var word = _context.Words.Find(catWord.WordId); var language = _context.Languages.Find(word.LanguageId); var category = _context.Categories.Find(catWord.CategoryId); var translations = _context.Translations.Where(t => t.CategorizedWordId == catWord.Id).ToList(); WordDataHelper helper = new WordDataHelper(_context, _accessor); model.Word = word.ThisWord; model.WordId = catWord.WordId; model.Language = language.Name; model.LanguageId = word.LanguageId; model.Category = catWord.Category.Name; model.CategoryId = catWord.CategoryId; model.CatWordId = catWord.Id; model.TranslationIds = helper.TranslationIdsToString(translations); model.Translation = helper.TranslationsToString(translations); }
public void CreateTranslations(WordData model, int catWordId, out bool error) { error = false; List <Translation> translations = new List <Translation>(); if (!SplitTranslations(model.Translation, ref translations)) { error = true; return; } foreach (var translation in translations) { translation.CategorizedWordId = catWordId; } _context.Translations.AddRange(translations); _context.SaveChanges(); }
public void CreateWord(WordData model, out int wordId) { var word = new Word(); var sameWord = _context.Words.FirstOrDefault(w => w.ThisWord.Equals(model.Word) && w.LanguageId == model.LanguageId); word.LanguageId = model.LanguageId; word.ThisWord = model.Word; if (sameWord == null) { _context.Words.Add(word); _context.SaveChanges(); wordId = word.Id; } else { wordId = sameWord.Id; } }
void ShowWordSelected(GameObject word) { //DESELECT OLD ONE if (wordGO) { wordGO.GetComponent <WordButton>().label.color = new Color(212, 212, 212); } wordGO = word; wordData = wordGO.GetComponent <WordButton>().wordData; wordGO.GetComponent <WordButton>().label.color = new Color(0, 225, 100); textField.text = wordData.text; timeField.text = wordData.time; if (double.IsNaN(wordData.duration)) { wordData.duration = 0; } durationField.text = wordData.duration.ToString(); }
public IActionResult Delete(WordData model, string returnController, string returnAction) { var wordEntity = _context.Words.First(w => w.ThisWord.Equals(model.Word) && w.LanguageId == model.LanguageId); var catWordEntity = _context.CategorizedWords.First(cw => cw.WordId == wordEntity.Id && cw.CategoryId == model.CategoryId); if (_context.CategorizedWords.Count(cw => cw.WordId == wordEntity.Id) == 1) { _context.Remove(wordEntity); } else { _context.Remove(catWordEntity); } _context.SaveChanges(); ViewBag.LangId = model.LanguageId; ViewBag.Language = _context.Languages.First(l => l.Id == model.LanguageId).Name; FillReturnPath(returnController, returnAction); return(RedirectToAction(returnAction, returnController, new { langId = model.LanguageId })); }
public List <LetterData> FindWrongLetters(WordData selectedWord, List <LetterData> wordLetters) { var vocabularyHelper = AppManager.I.VocabularyHelper; var noWordLetters = vocabularyHelper.GetLettersNotIn(LetterEqualityStrictness.LetterOnly, parameters.letterFilters, wordLetters.ToArray()); var eligibleLetters = new List <LetterData>(); var badWords = new List <WordData>(currentRound_words); badWords.Remove(selectedWord); foreach (var letter in noWordLetters) { // Avoid using letters that appeared in previous words if (vocabularyHelper.IsLetterContainedInAnyWord(letter, badWords)) { continue; } eligibleLetters.Add(letter); } return(eligibleLetters); }
public void CheckWord_Count_Of_Words_MustReturn_AtLeast_3_Words() { SettingsModel settingsModel = new SettingsModel() { Words = "VITAMIN A;FIBER;MICKEY MOUSE;MULTIVITAMIN;PHINEAS;FERB" }; var mockSettings = new Mock <IOptions <SettingsModel> >(); mockSettings.Setup(w => w.Value).Returns(settingsModel); var wordData = new WordData(mockSettings.Object); var result = wordData.GetRandomWords(); Assert.NotNull(result); Assert.NotEmpty(result); Assert.NotEqual(1, result.Count); Assert.NotEqual(2, result.Count); }
//dictionary with location as key and list of word data as value private void AddToDictionary(Dictionary <string, List <WordData> > dictionary, IEnumerable <KeyValuePair <string, WordData> > items) { foreach (var item in items) { var newElement = new WordData() { Weight = item.Value.Weight, Word = item.Value.Word }; if (dictionary.ContainsKey(item.Key)) { dictionary[item.Key].Add(newElement); } else { dictionary.Add(item.Key, new List <WordData>() { newElement }); } } }
public void TestHelpRequestEvent() { bool isTriggered = false; IUserInterface consoleInterface = new ConsoleInterface(); consoleInterface.HelpRequest += (sender, eventInfo) => { isTriggered = true; }; Word currentWord = new Word("test"); WordData currentWordDate = new WordData(currentWord); string inputString = string.Format("help{0}", Environment.NewLine); using (StringReader sr = new StringReader(inputString)) { Console.SetIn(sr); consoleInterface.GetUserInput(currentWordDate); } Assert.IsTrue(isTriggered); }
private async void OnSave() { Category newCategory = new Category() { Name = Name, LastUse = DateTime.MinValue, Words = new List <Word>() }; foreach (string s in Words) { newCategory.Words.Add(new Word() { Text = s }); } await WordData.AddItemAsync(newCategory); // This will pop the current page off the navigation stack await Shell.Current.GoToAsync(".."); }
public void SetupLetters(WordData wordData) { List <LetterBox> letters = new List <LetterBox>(); for (int i = 0; i < wordData.word.Length; i++) { letters.Add(NewLetter(wordData.word[i])); } while (letters.Count < letterCount) { letters.Add(NewLetter(wordData.word[Random.Range(0, wordData.word.Length)])); } int idx = 0; while (letters.Count > 0) { int pos = Random.Range(0, letters.Count); LetterBox letter = letters[pos]; letters.RemoveAt(pos); letter.transform.position = startPos + spawnSpacing * (idx++); } }
private SubmissionResponse SubmitTextInternal(DirectionalProcess dirProcess, int sizeValue, string text) { var finalResult = false; WordData wordData = null; var originalCol = dirProcess.StartRowCol; var iterateCol = originalCol; var exitLoop = false; InsertionSpace space = null; do { space = GetSuitableSpaces(dirProcess, iterateCol, text); var canInsert = space != null && text.Length <= space.EmptySpaces; // When it can't insert try the next row, moving back to the beginning when it hits the end of the rows. if (!canInsert) { iterateCol = iterateCol + 1 > sizeValue - 1 ? 0 : iterateCol + 1; } finalResult = canInsert; // Exit loop if it can insert, or if we've tried every row and gone back to the original row. exitLoop = canInsert || originalCol == iterateCol; } while (!exitLoop); // If validation passes, then insert it. if (finalResult) { wordData = PerformInsert(dirProcess, text, space); } return(new SubmissionResponse(finalResult, wordData)); }
/// <summary> /// 用語情報(1行)をパース /// </summary> /// <param name="line">パース対象</param> /// <returns>パース結果を格納したWordDataオブジェクト</returns> private WordData Parse(string line) { var tmp = line.Trim(); if (tmp == "{" || tmp == "}") { return(null); } var wordData = new WordData() { Meanings = new List <MeaningData>() }; var meaningData = new MeaningData(); wordData.Meanings.Add(meaningData); var pos = tmp.IndexOf(":"); wordData.Word = TrimJsonData(tmp.Substring(0, pos - 1)); meaningData.Meaning = TrimJsonData(tmp.Substring(pos + 1)); return(wordData); }
private string GetInfo(WordData data) { var info = new StringBuilder(); if (0 < data.Syllable.Length) { info.Append($"<span class='syllable'>音節</span> {data.Syllable} "); } if (0 < data.Pronunciation.Length) { info.Append($"<span class='pronumciation'>発音</span> {data.Pronunciation}"); if (0 < data.Kana.Length) { info.Append($"({data.Kana})"); } info.Append(" "); } if (0 < data.Change.Length) { info.Append($"<span class='change'>変化</span> {data.Change} "); } return(info.ToString()); }
async Task ExecuteLoadItemsCommand() { IsBusy = true; try { Categories.Clear(); var recent = await WordData.GetItemsAsync(); foreach (Vocabulary.Model.Category item in recent) { Categories.Add(MapCategory(item)); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
async Task ExecuteLoadRecentCommand() { IsBusy = true; try { RecentCategories.Clear(); var recent = await WordData.GetRecentAsync(true); foreach (Vocabulary.Model.Category item in recent) { RecentCategories.Add(MapCategory(item)); } NoRecentFound = RecentCategories.Count == 0; } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public void TestGameRestartEvent() { bool isTriggered = false; IUserInterface consoleInterface = new ConsoleInterface(); consoleInterface.GameRestart += (sender, eventInfo) => { isTriggered = true; }; Word currentWord = new Word("test"); WordData currentWordDate = new WordData(currentWord); string inputString = string.Format("restart{0}", Environment.NewLine); using (StringReader sr = new StringReader(inputString)) { Console.SetIn(sr); consoleInterface.GetUserInput(currentWordDate); } Assert.IsTrue(isTriggered); }
private bool ResolveNewLangCat(WordData model) { var lang = _context.Languages.FirstOrDefault(l => l.Name.Equals(model.Language) && (l.UserName.Equals(_user.Identity.Name))); var cat = _context.Categories.FirstOrDefault(c => c.Name.Equals(model.Category) && (c.UserName.Equals(_user.Identity.Name))); if (lang == null) { if (cat != null) { model.CategoryId = cat.Id; } return(false); } else { model.LanguageId = lang.Id; if (cat == null) { return(false); } model.CategoryId = cat.Id; } return(true); }
private bool WordIsEligible(WordData word, LetterData containedLetter, LetterForm form, int maxWordLength) { // Check max length if (word.Letters.Length > maxWordLength) { return(false); } // Check that it contains the letter only once if (AppManager.I.VocabularyHelper.WordContainsLetterTimes(word, containedLetter) > 1) { return(false); } // Check that it contains a letter in the correct form var letterWithForm = AppManager.I.VocabularyHelper.ConvertToLetterWithForcedForm(containedLetter, form); if (!AppManager.I.VocabularyHelper.WordContainsLetter(word, letterWithForm, LetterEqualityStrictness.WithActualForm)) { return(false); } return(true); }
public void DetailLetter(LetterInfo letterInfo) { DetailPanel.SetActive(true); myLetterInfo = letterInfo; myLetterData = letterInfo.data; if (ApplicationConfig.I.VerboseBook) { Debug.Log("[DetailLetter]" + myLetterData.Number + " " + myLetterData.Id); } HighlightLetterItem(myLetterInfo.data.Id); if (AppManager.I.ParentEdition.BookShowRelatedWords) { // show related words RelatedWordsContainer.SetActive(true); DiacriticsContainer.SetActive(false); emptyContainer(RelatedWordsContainer); foreach (var word in letterInfo.data.LinkedWords) { WordData wdata = AppManager.I.DB.GetWordDataById(word); WordInfo winfo = new WordInfo(); winfo.data = wdata; btnGO = Instantiate(WordItemPrefab); btnGO.transform.SetParent(RelatedWordsContainer.transform, false); btnGO.GetComponent <ItemWord>().Init(this, winfo, false); } } else { // show related diacritics RelatedWordsContainer.SetActive(false); DiacriticsContainer.SetActive(true); emptyContainer(DiacriticsContainer); var letterbase = myLetterInfo.data.Id; var variationsletters = AppManager.I.DB.FindLetterData( (x) => (x.BaseLetter == letterbase && (x.Kind == LetterDataKind.DiacriticCombo && x.Active)) ); variationsletters.Sort((x, y) => x.Number - y.Number); // diacritics box var letterGO = Instantiate(DiacriticSymbolItemPrefab); letterGO.transform.SetParent(DiacriticsContainer.transform, false); letterGO.GetComponent <ItemDiacriticSymbol>().Init(this, myLetterInfo, true); List <LetterInfo> info_list = AppManager.I.ScoreHelper.GetAllLetterInfo(); info_list.Sort((x, y) => x.data.Number - y.data.Number); foreach (var info_item in info_list) { if (variationsletters.Contains(info_item.data)) { if (AppConfig.DisableShaddah && info_item.data.Symbol == "shaddah") { continue; } btnGO = Instantiate(DiacriticSymbolItemPrefab); btnGO.transform.SetParent(DiacriticsContainer.transform, false); btnGO.GetComponent <ItemDiacriticSymbol>().Init(this, info_item, false); //debug_output += info_item.data.GetDebugDiacriticFix(); } } } //Debug.Log(debug_output); ShowLetter(myLetterInfo); }
public static string word_next_read(ref WordData data, string s, ref bool done) //****************************************************************************80 // // Purpose: // // WORD_NEXT_READ "reads" words from a string, one at a time. // // Discussion: // // This routine was written to process tokens in a file. // A token is considered to be an alphanumeric string delimited // by whitespace, or any of various "brackets". // // The following characters are considered to be a single word, // whether surrounded by spaces or not: // // " ( ) { } [ ] // // Also, if there is a trailing comma on the word, it is stripped off. // This is to facilitate the reading of lists. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 20 October 2010 // // Author: // // John Burkardt // // Parameters: // // Input, string S, a string, presumably containing words // separated by spaces. // // Input/output, bool *DONE. // On input with a fresh string, set DONE to TRUE. // On output, the routine sets DONE: // FALSE if another word was read, // TRUE if no more words could be read. // // Output, string WORD_NEXT_READ. // If DONE is FALSE, then WORD contains the "next" word read. // If DONE is TRUE, then WORD is NULL, because there was no more to read. // { int i; int j; const char TAB = '9'; string word; char[] word_chstar; switch (done) { // // We "remember" LENC and NEXT from the previous call. // // An input value of DONE = TRUE signals a new line of text to examine. // case true: { data.next = 0; done = false; data.lenc = s.Length; switch (data.lenc) { case <= 0: done = true; word = "\n"; return(word); } break; } } // // Beginning at index NEXT, search the string for the next nonblank, // which signals the beginning of a word. // int ilo = data.next; // // ...S(NEXT:) is blank. Return with WORD = ' ' and DONE = TRUE. // for (;;) { if (data.lenc < ilo) { word = "\n"; done = true; data.next = data.lenc + 1; return(word); } // // If the current character is blank, skip to the next one. // if (s[ilo] != ' ' && s[ilo] != TAB) { break; } ilo += 1; } switch (s[ilo]) { // // ILO is the index of the next nonblank character in the string. // // If this initial nonblank is a special character, // then that's the whole word as far as we're concerned, // so return immediately. // case '"': word = "\"\""; data.next = ilo + 1; return(word); case '(': word = "("; data.next = ilo + 1; return(word); case ')': word = ")"; data.next = ilo + 1; return(word); case '{': word = "{"; data.next = ilo + 1; return(word); case '}': word = "}"; data.next = ilo + 1; return(word); case '[': word = "["; data.next = ilo + 1; return(word); case ']': word = "]"; data.next = ilo + 1; return(word); } // // Now search for the last contiguous character that is not a // blank, TAB, or special character. // data.next = ilo + 1; while (data.next <= data.lenc) { if (s[data.next] == ' ') { break; } if (s[data.next] == TAB) { break; } if (s[data.next] == '"') { break; } if (s[data.next] == '(') { break; } if (s[data.next] == ')') { break; } if (s[data.next] == '{') { break; } if (s[data.next] == '}') { break; } if (s[data.next] == '[') { break; } if (s[data.next] == ']') { break; } data.next += 1; } switch (s[data.next - 1]) { // // Allocate WORD, copy characters, and return. // case ',': { word_chstar = new char[data.next - ilo]; i = 0; for (j = ilo; j <= data.next - 2; j++) { word_chstar[i] = s[j]; i += 1; } word_chstar[i] = '\0'; word = new string( word_chstar ); break; } default: { word_chstar = new char[data.next + 1 - ilo]; i = 0; for (j = ilo; j <= data.next - 1; j++) { word_chstar[i] = s[j]; i += 1; } word_chstar[i] = '\0'; word = new string(word_chstar); break; } } return(word); }
private void PrepareData() { WordData.UpdateData(dataDict); }
/* * The UpdateGame method makes sure everything in the game is correct at any point in time. * It sets the right words for the buttons and selects new ones if needed. */ private void UpdateGame() { if (toDoList.Count < 1) { CreateEndscreen(); return; } currentWord = nextWord; string wrongTrans; do { wrongTrans = SelectRandomWord(totalWordList).GetTrans(); } while (currentWord.GetTrans().Equals(wrongTrans)); correct = UnityEngine.Random.Range(0, 2); middleText.GetComponent<UpdateMiddleText>().UpdateText(descWithWord, currentWord.GetTrans(), wrongTrans, correct); timer.StartTiming(); }
public void RunWordSearch() { if (TrackedSkeleton != null) { Joint MotionHandJoint = (TrackedSkeleton.Joints[MotionHand]).ScaleTo(222, 1044); Joint MotionHandJointScaled = TrackedSkeleton.Joints[MotionHand].ScaleTo(1366, 768, 0.55f, 0.55f); Joint SelectionHandJoint = (TrackedSkeleton.Joints[SelectionHand]).ScaleTo(222, 656); Joint SelectionHandJointScaled = (TrackedSkeleton.Joints[SelectionHand]).ScaleTo(1366, 768, 0.55f, 0.55f); Point MotionHandPosition = new Point((MotionHandJointScaled.Position.X), (MotionHandJointScaled.Position.Y)); Point SelectionHandPosition = new Point((SelectionHandJointScaled.Position.X), (SelectionHandJointScaled.Position.Y)); //Move Cursor //SetCursorPos((int)(MotionHandPosition.X), (int)(MotionHandPosition.Y)); Point destination_top_left = theCanvas.PointFromScreen(MotionHandPosition); if (selected.Count > 0) { Pointer_Ellipse.Visibility = Visibility.Hidden; int best = 0; for (int i = 1; i < selected.Count; i++) { if (selected_time[i][1].Subtract(selected_time[i][0]).TotalDays > selected_time[best][1].Subtract(selected_time[best][0]).TotalDays) { best = i; } } Bubble select = selected[best]; if (halo != null) { halo.RemoveFromParent(); } halo = select.ConstructClone(destination_top_left); halo_parent = select; } else { Pointer_Ellipse.Visibility = Visibility.Visible; if (halo != null) { halo.RemoveFromParent(); halo = null; halo_parent = null; } } destination_top_left = Point.Add(destination_top_left, new System.Windows.Vector(Pointer_Ellipse.Width / -2, Pointer_Ellipse.Height / -2)); Canvas.SetTop(Pointer_Ellipse, destination_top_left.Y); Canvas.SetLeft(Pointer_Ellipse, destination_top_left.X); //Added data position to a queue of positions that will be loaded for each letter PositionData.Enqueue("\r\n\t\t\t\t<entry motionhand_x=\"" + MotionHandPosition.X + "\" motionhand_y=\"" + MotionHandPosition.Y + "\" selectionhand_x=\"" + SelectionHandPosition.X + "\" selectionhand_y=\"" + SelectionHandPosition.Y + "\" relative_timestamp=\"" + DateTime.Now.Subtract(StartTime).TotalMilliseconds + "\" />"); //Setup the default colors of the bubbles foreach (Bubble beta in Letters) { if (CurrentNode.HasChild(beta.Word()) != null) { beta.SetColor(Brushes.Yellow); } else { beta.SetColor(Brushes.LightYellow); } } for (int i = 0; i < selected.Count; i++) { if (!selected_off[i] && !CircleOver(selected[i].Ellipse)) { selected_off[i] = true; selected_time[i][1] = DateTime.Now; } else if (!selected_off[i] && CircleOver(selected[i].Ellipse)) { selected_time[i][1] = DateTime.Now; } else if (selected_off[i] && CircleOver(selected[i].Ellipse)) { TimeSpan t = selected_time[i][1].Subtract(selected_time[i][0]); selected_time[i][0] = DateTime.Now.Subtract(t); selected_time[i][1] = DateTime.Now; selected_off[i] = false; } } //Starting Case (only occurs once) if (SelectionHandLast == null) { SelectionHandLast = SelectionHandPosition; } else { //Measures the distance traveled by the selection hand SelectionHandDistance += Point.Subtract(SelectionHandLast, SelectionHandPosition).Length; SelectionHandLast = SelectionHandPosition; } //Measures the distance traveled by the motion hand if (MotionHandLast == null) { MotionHandLast = MotionHandPosition; } else { MotionHandDistance += Point.Subtract(MotionHandLast, MotionHandPosition).Length; MotionHandLast = MotionHandPosition; } //foreach (Bubble beta in Letters) //{ // if (Shift) // { // beta.setText(beta.Word().ToString().ToUpperInvariant()[0]); // } // else // { // beta.setText(beta.Word().ToString().ToLowerInvariant()[0]); // } //} Gesture MotionHandGesture = keyboardGestureTracker.track(TrackedSkeleton, TrackedSkeleton.Joints[MotionHand], nui.NuiCamera.ElevationAngle); Gesture SelectionHandGesture = regularGestureTracker.track(TrackedSkeleton, TrackedSkeleton.Joints[SelectionHand], nui.NuiCamera.ElevationAngle); if (CircleOver(CenterBubble_Ellipse)) { ReturnedToCenter = true; if (!EnterCenterFirst) { PositionData = new Queue <string>(); EnterCenterFirst = true; } if (SelectionHandGesture != null && ((SelectionHandGesture.id == GestureID.SwipeLeft && SelectionHand == JointID.HandRight) || (SelectionHandGesture.id == GestureID.SwipeRight && SelectionHand == JointID.HandLeft))) { SendKeys.SendWait("{Backspace}"); if (CenterBubble_Label.Content.ToString().Length > 0) { CenterBubble_Label.Content = CenterBubble_Label.Content.ToString().Substring(0, CenterBubble_Label.Content.ToString().Length - 1); CurrentNode = (CurrentNode.parent != null ? CurrentNode.parent : CurrentNode); } RemoveLayout(); ConstructLetterLayout(); PositionData.Enqueue("\r\n\t\t\t\t<backspace motionhand_x=\"" + MotionHandPosition.X + "\" motionhand_y=\"" + MotionHandPosition.Y + "\" selectionhand_x=\"" + SelectionHandPosition.X + "\" selectionhand_y=\"" + SelectionHandPosition.Y + "\" relative_timestamp=\"" + DateTime.Now.Subtract(StartTime).TotalMilliseconds + "\" />"); } else if (SelectionHandGesture != null && SelectionHandGesture.id == GestureID.Push) { if (DateTime.Now.Subtract(last_space).TotalSeconds > 0.75) { RemoveLayout(); CurrentNode = InitialNode; ConstructLetterLayout(); SendKeys.SendWait(" "); WordStack.Push(CenterBubble_Label.Content.ToString()); string word = "\r\n\t\t<word text=\"" + WordStack.Peek() + "\">"; while (WordData.Count > 0) { word += WordData.Dequeue(); } word += "\r\n\t\t</word>"; SentenceData.Enqueue(word); WordData = new Queue <string>(); CenterBubble_Label.Content = ""; last_space = DateTime.Now; } } //if ((SelectionHandGesture != null && SelectionHandGesture.id == GestureID.SwipeUp) || Shift == true) //{ // Shift = true; // foreach (Bubble beta in Letters) // { // beta.setText(beta.Word().ToString().ToUpperInvariant()[0]); // } //} //if ((SelectionHandGesture != null && SelectionHandGesture.id == GestureID.SwipeDown) || Shift == false) //{ // Shift = false; // foreach (Bubble beta in Letters) // { // beta.setText(beta.Word().ToString().ToLowerInvariant()[0]); // } //} if (selected.Count > 0 && MotionHandGesture != null && MotionHandGesture.id == GestureID.Still) { Bubble select = halo; //Shift = false; ReturnedToCenter = false; char c = select.GetCharacter(); RemoveLayout(); WordTreeNode NextNode = CurrentNode.HasChild(c); if (NextNode == null) { NextNode = new WordTreeNode(c, false); NextNode.parent = CurrentNode; } CurrentNode = NextNode; ConstructLetterLayout(); SendKeys.SendWait(c.ToString()); CenterBubble_Label.Content = CenterBubble_Label.Content.ToString() + c.ToString(); string letter = ""; string InnerRing = (select.r == Bubble.RingStatus.INNER ? "true" : (PreviousCharacterLocation.Contains(CurrentNode) ? "false" : "outside")); letter += ("\r\n\t\t\t<print char=\"" + c + "\" selection_hand_distance=\"" + SelectionHandDistance + "\" motion_hand_distance=\"" + MotionHandDistance + "\" InnerRing=\"" + InnerRing + "\""); while (PositionData.Count > 0) { letter += PositionData.Dequeue(); } PositionData = new Queue <string>(); letter += ("\r\n\t\t\t</print>"); WordData.Enqueue(letter); SelectionHandDistance = 0.0; MotionHandDistance = 0.0; if (CurrentNode.HasChild('!') != null) { CenterBubble_Ellipse.Fill = Brushes.AntiqueWhite; } else { CenterBubble_Ellipse.Fill = Brushes.GreenYellow; } selected = new List <Bubble>(); selected_time = new List <DateTime[]>(); selected_off = new List <bool> (); } } // We can make changes to the layout if (ReturnedToCenter) { if (MotionHandGesture.id == GestureID.Still) { foreach (Bubble beta in Letters) { if (CircleOver(beta.Ellipse) && !selected.Contains(beta)) { selected.Add(beta); DateTime[] arr = new DateTime[2]; arr[0] = DateTime.Now; arr[1] = DateTime.Now; selected_time.Add(arr); selected_off.Add(false); } if (CurrentNode.HasChild(beta.Word()) != null) { beta.SetColor(Brushes.Yellow); } else { beta.SetColor(Brushes.LightYellow); } } } } } if (DateTime.Now.Subtract(BlueFlash).TotalMilliseconds < 500) { CenterBubble_Ellipse.Fill = Brushes.LightBlue; } else { if (CurrentNode.HasChild('!') != null) { CenterBubble_Ellipse.Fill = Brushes.AntiqueWhite; } else { CenterBubble_Ellipse.Fill = Brushes.GreenYellow; } } if (halo_parent != null) { halo_parent.SetColor(Brushes.LightGreen); } }
public void RunWordSearch() { if (TrackedSkeleton != null) { Joint MotionHandJoint = (TrackedSkeleton.Joints[MotionHand]).ScaleTo(222, 1044); Joint MotionHandJointScaled = TrackedSkeleton.Joints[MotionHand].ScaleTo(1366, 768, 0.55f, 0.55f); Joint SelectionHandJoint = (TrackedSkeleton.Joints[SelectionHand]).ScaleTo(222, 656); Joint SelectionHandJointScaled = (TrackedSkeleton.Joints[SelectionHand]).ScaleTo(1366, 768, 0.55f, 0.55f); Point MotionHandPosition = new Point((MotionHandJointScaled.Position.X), (MotionHandJointScaled.Position.Y)); Point SelectionHandPosition = new Point((SelectionHandJointScaled.Position.X), (SelectionHandJointScaled.Position.Y)); //Move Cursor //SetCursorPos((int)(MotionHandPosition.X), (int)(MotionHandPosition.Y)); Point destination_top_left = theCanvas.PointFromScreen(MotionHandPosition); destination_top_left = Point.Add(destination_top_left, new System.Windows.Vector(Pointer_Ellipse.Width / -2, Pointer_Ellipse.Height / -2)); Canvas.SetTop(Pointer_Ellipse, destination_top_left.Y); Canvas.SetLeft(Pointer_Ellipse, destination_top_left.X); //Added data position to a queue of positions that will be loaded for each letter PositionData.Enqueue("\r\n\t\t\t\t<entry motionhand_x=\"" + MotionHandPosition.X + "\" motionhand_y=\"" + MotionHandPosition.Y + "\" selectionhand_x=\"" + SelectionHandPosition.X + "\" selectionhand_y=\"" + SelectionHandPosition.Y + "\" relative_timestamp=\"" + DateTime.Now.Subtract(StartTime).TotalMilliseconds + "\" />"); Gesture SelectionHandGesture = GestureTracker.track(TrackedSkeleton, TrackedSkeleton.Joints[SelectionHand], nui.NuiCamera.ElevationAngle); if (SelectionHandGesture != null && (SelectionHandGesture.id == GestureID.Push)) { foreach (System.Windows.Controls.Button beta in Buttons) { if (PointerOver(beta)) { if ((((string)(beta.Content)).Equals(last_char) && DateTime.Now.Subtract(last_char_time).TotalSeconds > 0.75) || (!((string)(beta.Content)).Equals(last_char))) { SendKeys.SendWait(beta.Content.ToString().ToLowerInvariant()); CurrentWord += (beta.Content.ToString().ToLowerInvariant()); string letter = ("\r\n\t\t\t<print char=\"" + (beta.Content.ToString().ToLowerInvariant()) + "\" selection_hand_distance=\"" + SelectionHandDistance + "\" motion_hand_distance=\"" + MotionHandDistance + "\""); while (PositionData.Count > 0) { letter += PositionData.Dequeue(); } PositionData = new Queue <string>(); letter += ("\r\n\t\t\t</print>"); WordData.Enqueue(letter); SelectionHandDistance = 0.0; MotionHandDistance = 0.0; last_char = (string)(beta.Content); last_char_time = DateTime.Now; } } } if (PointerOver(Button_Space)) { if ((((string)(Button_Space.Content)).Equals(last_char) && DateTime.Now.Subtract(last_char_time).TotalSeconds > 0.75) || (!((string)(Button_Space.Content)).Equals(last_char))) { SendKeys.SendWait(" "); string word = "\r\n\t\t<word text=\"" + CurrentWord + "\">"; CurrentWord = ""; while (WordData.Count > 0) { word += WordData.Dequeue(); } word += "\r\n\t\t</word>"; SentenceData.Enqueue(word); WordData = new Queue <string>(); last_char = (string)(Button_Space.Content); last_char_time = DateTime.Now; } } else if (PointerOver(Button_Backspace)) { if ((last_char.Equals("bksp") && DateTime.Now.Subtract(last_char_time).TotalSeconds > 0.75) || (!last_char.Equals("bksp"))) { SendKeys.SendWait("{Backspace}"); PositionData.Enqueue("\r\n\t\t\t\t<backspace motionhand_x=\"" + MotionHandPosition.X + "\" motionhand_y=\"" + MotionHandPosition.Y + "\" selectionhand_x=\"" + SelectionHandPosition.X + "\" selectionhand_y=\"" + SelectionHandPosition.Y + "\" relative_timestamp=\"" + DateTime.Now.Subtract(StartTime).TotalMilliseconds + "\" />"); last_char = "bksp"; last_char_time = DateTime.Now; } } } } }
private string GetDisplayData(WordData data) { var body = new StringBuilder(); body.Append("<main>"); body.Append($"<h1>{data.Word}</h1>"); var info = this.GetInfo(data); if (0 < info.Length) { body.Append($"<div class='info'>{info}</div>"); } var startUl = false; var partOfSpeech = ""; foreach (var meaning in data.Meanings) { var className = ""; switch ((Constants.DicType)meaning.SourceId) { case Constants.DicType.Eijiro: className = " class='eijiro'"; break; case Constants.DicType.Webster: className = " class='webster'"; break; } if (meaning.PartOfSpeach == "" || partOfSpeech != meaning.PartOfSpeach) { if (startUl) { body.Append("</ul>"); body.Append("</div>"); } startUl = true; body.Append($"<div{className}>"); if (0 < meaning.PartOfSpeach.Length) { body.Append($"<h4>{meaning.PartOfSpeach}</h4>"); } body.Append($"<ul{className}>"); } body.Append($"<li>{meaning.Meaning}"); if (0 < meaning.Additions.Count) { body.Append("<div class='note'>"); for (var j = 0; j < meaning.Additions.Count; j++) { var addition = meaning.Additions[j]; switch (addition.Type) { case Constants.AdditionType.Supplement: body.Append($"<span class='supplement'>{addition.Data}</span>"); break; case Constants.AdditionType.Example: body.Append($"<span class='example'>{addition.Data}</span>"); break; } if (j < meaning.Additions.Count - 1) { body.Append("<br/>"); } } body.Append("</div>"); } body.Append("</li>"); partOfSpeech = meaning.PartOfSpeach; } if (startUl) { body.Append("</ul>"); body.Append("</div>"); } body.Append("</div>"); body.Append("</main>"); return(body.ToString()); }
public void MergeLyricsAndTimes() { if (string.IsNullOrEmpty(lyricsString)) { UIEventManager.FireAlert("Not all files prsent !", "ALERT"); return; } // remove first 5 lines and the last one; string[] remN = lyricsString.Split('\n'); List <string> strLst = new List <string>(remN); strLst.RemoveRange(0, 5); strLst.RemoveRange(strLst.Count - 2, 2); string strFromLst = String.Join(" ", strLst.ToArray()); // remove line breaks string stringOneLine = Regex.Replace(strFromLst, @"\r\n?|\n", String.Empty); // replace < and > for [ and ] and add one "[" at the end string strClean = StringExtention.clean(stringOneLine) + "["; jsonOutputTxt.text = strClean; // pull out all the timestamps from mm:ss.ss string patternTimestamps = @"\d\:\d{1,2}.\d{1,2}"; matchTimestamps = Regex.Matches(strClean, patternTimestamps); // pull the words between ] and [ string patternWords = @"\](.*?)\["; matchWords = Regex.Matches(strClean, patternWords); if (matchWords.Count != matchTimestamps.Count) { UIEventManager.FireAlert("Count doesn't match \n" + "lyrics lines: " + matchWords.Count + " - vs - " + "timestamps lines: " + matchTimestamps.Count, "WORD COUNT MISSMATCH"); return; } //Debug.Log("All is OK... proceed"); //songWords = new string[matchWords.Count]; int i = 0; int w = matchWords.Count; // for (i = 0; i < w; i++) //{ //songWords[i] = matchWords[i].ToString().TrimStart(']', ' ').TrimEnd('['); // } //songTimestamps = new string[matchTimestamps.Count]; // int n = matchTimestamps.Count; //for (i = 0; i < n; i++) //{ //songTimestamps[i] = formatTimeToSeconds(matchTimestamps[i].ToString()); //} WordData word; string clearedStr; string trimedStr; wordsList = new WordData[matchWords.Count]; for (i = 0; i < w; i++) { word = new WordData(); clearedStr = matchWords[i].ToString().TrimStart(']', ' ').TrimEnd('['); trimedStr = clearedStr.TrimEnd(); word.text = trimedStr; word.time = formatTimeToSeconds(matchTimestamps[i].ToString()); word.index = i; wordsList[i] = word; } //// Proceed to Save SaveToJson(); }
private LL_WordData BuildWordData_LL(WordData data) { return(new LL_WordData(data.GetId(), data)); }
private void HandleGetCustomWord(WordData word, Dictionary <string, object> customData) { Log.Debug("ExampleSpeechToText.HandleGetCustomWord()", "{0}", customData["json"].ToString()); _getCustomWordTested = true; }
public void WordsReader(string filename) { this.fileName = filename; XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; settings.IgnoreWhitespace = true; settings.ValidationType = ValidationType.None; XmlReader reader = XmlTextReader.Create(filename, settings); while (reader.Read()) { WordData word = null; switch (reader.NodeType) { case XmlNodeType.Element: string tagName = reader.LocalName; if (tagName.Equals(WordTag.Word)) { word = new WordData(reader[WordTag.Name]); this.wordList.Add(word); } break; default: break; } } reader.Close(); }