/// <summary> /// Find and remove word /// </summary> /// <param name="wordText">Text to remove</param> public void RemoveWord(string wordText) { float minEditDistance = WordProcessor.GetWordTyping(wordText) / 2; WordObject missWord = null; foreach (WordObject child in words) { if (child.wordText == wordText) { child.Destroy(); WordSpawner.inst.lastNameWordCreated -= PhaseInfo.NameSpawnReduce(currentPhase); return; } else { int editDistance = WordProcessor.GetEditDistance(child.wordText, wordText); if (editDistance <= minEditDistance) { minEditDistance = editDistance; missWord = child; } } } if (missWord != null) { //For test, do word miss reaction Debug.Log("Missed word " + missWord.wordText); } //Check edit distance }
public WorldObject(WordObject word) { this.Word = word.Text; this.Entity = new entity(); Entity.entityValue = word.Text; Entity.entityType = word.TypefromEnum(word.WordT); }
/// <summary> /// Show a random sentence on the screen /// </summary> //public void ShowScramble() //{ // ShowScramble(UnityEngine.Random.Range(0, sentences.Length - 1)); //} /// <summary> /// Show sentence from collection with desired index /// </summary> /// <param name="index"index of the element></param> public void ShowScramble(int index) { wordObjects.Clear(); foreach (Transform child in container) { Destroy(child.gameObject); } //Sentences finished //if (index > sentences.Length - 1) //{ // UnityEngine.Debug.LogError("Index out of range, please enter range between 0-" + (sentences.Length - 1).ToString()); // return; //} string wordString = sentences[index].GetString(); string[] wordsInSentence = Regex.Matches(wordString, "\\w+").OfType <Match>().Select(m => m.Value).ToArray(); originalWords = sentences[index].ActualString(); //UnityEngine.Debug.Log("Sentences are"); //UnityEngine.Debug.Log(originalWords[0]); foreach (string w in wordsInSentence) { WordObject clone = Instantiate(prefab.gameObject).GetComponent <WordObject>(); clone.transform.SetParent(container); wordObjects.Add(clone.Init(w)); } currentSentence = index; }
/// <summary> /// Processes the word object, adding new words to the database /// with the appropriate properties. /// Returns true if the wordObject meets the criteria to be a tag. /// </summary> /// <param name="wordObject"></param> /// <returns></returns> private bool ProcessWordObject(string originalWord, WordObject wordObject) { if (wordObject == null) { return(false); } bool wordIsTag = WordQualifiesAsTag(wordObject); var newWord = new Word(); newWord.IsTag = wordIsTag; newWord.Word1 = originalWord; newWord.BaseWord = wordObject.Word; _repo.AddWord(newWord); if (wordObject.Word != originalWord) { var baseWord = new Word(); baseWord.IsTag = wordIsTag; baseWord.Word1 = wordObject.Word; baseWord.BaseWord = wordObject.Word; _repo.AddWord(baseWord); } return(wordIsTag); }
public TextProcessor(string text) { Input = text; Input = HttpUtility.HtmlDecode(Input); CurrentText = Input; CurrentText = CurrentText.StripHtml().ToStandard(); var _models = CurrentText.ToWords(); _models = _models.Where(t => t.IsWord()).ToArray(); for (int i = 0; i < _models.Length; i++) { var _word = new Word(_models[i]); if (_word.CanRead()) { WordObject _object = new WordObject(_models[i], i); _object.Indexs = CurrentText.IndexAll(_word.Value); FullWordObjects.Add(_object); _object.ToClean(); if (_object.IsClean()) { CleanWordObjects.Add(_object); } } } CountOfWords = CleanWordObjects.Count; CountOfFullWords = FullWordObjects.Count; TimeToRead = CountOfWords / 200; //Normal read speed LoadFull(); }
private void addMatch(WordObject word, bool isUserInput, List <WordObject> newSentence, IEnumerable <Ientity> match) { Ientity entity = null; if (match.Count() > 1) { var list = match.ToList(); list.Sort((x, y) => entitySelector(x) - entitySelector(y)); entity = list.FirstOrDefault(); } else { entity = match.FirstOrDefault(); } if (!isUserInput) { var newWord = word.clone();; newWord.Text = entity.entityValue; newWord.Lemma = entity.entityValue; newWord.WordT = WordObject.typeFromString(entity.entityType); newSentence.Add(newWord); } else { foreach (var w in match) { var newWord = word.clone();; newWord.Text = w.entityValue; newWord.Lemma = w.entityValue; newWord.WordT = WordObject.typeFromString(w.entityType); newSentence.Add(newWord); } } }
internal void initializeObject() { SubQqestion1 = new SubQuestion(); SubQqestion1.questionText = "הצג כיצד הסתיימה מלחמת העצמאות ואילו בעיות נותרו בלתי פתורות בעקבותיה."; SubQqestion1.answerText = "בעיית הפליטים - כ500 אלף ערבים עזבו את בתיהם והפכו לפליטים. רובם לא קיבלו אזרחות במדינות אליהם ברחו והם שואפים לחזור לבתיהם - זכות השיבה | ירושליים נותרה מחולקת בשלטון הירדנים;"; SubQqestion1.flags = "needAll"; userAnswerSubQuestion1 = "ירושלים נותרה מחולקת, והרבה ערבים נותרו כפליטים במדינות השכנות"; WordObject1.Text = "ערבים"; WordObject1.Lemma = "ערבי"; WordObject1.WordT = WordObject.WordType.organizationWord; WordObject1.Gender = genderType.masculine; WordObject1.Amount = amountType.plural; WordGufObjectThey = new WordObject(); WordGufObjectThey.WordT = WordObject.WordType.gufWord; WordGufObjectThey.Gender = genderType.masculine; WordGufObjectThey.Amount = amountType.plural; Entity1.entityValue = "ערבי"; Entity1.entityType = "organizationWord"; WordObject2.Text = "ירושלים"; WordObject2.WordT = WordObject.WordType.locationWord; WordObject2.Amount = amountType.singular; WordObject2.Gender = genderType.feminine; Entity2.entityValue = "ירושלים"; Entity2.entityType = "locationWord"; WordObject3.Text = "פליטים"; WordObject3.WordT = WordObject.WordType.conceptWord; WordObject3.Gender = genderType.masculine; WordObject3.Amount = amountType.plural; Entity3.entityValue = "פליטים"; Entity3.entityType = "personWord"; WordObject4.Text = "ירדן"; WordObject4.WordT = WordObject.WordType.organizationWord; WordObject4.Gender = genderType.feminine; Entity4.entityValue = "ירדן"; Entity4.entityType = "locationWord"; multyEntity.entityValue = "בעיית הפליטים"; multyEntity.entityType = "conceptWord"; Question1.QuestionID = "1"; Question2.QuestionID = "2"; Question3.QuestionID = "3"; }
private string removePrefix(string searchText, WordObject wordObject) { foreach (var c in wordObject.Prefixes) { // if(c != "ה" && searchText.Length > 0) searchText = searchText.Remove(0, 1); } return(searchText); }
public WordObject Previous(WordObject current) { try { return(GetWord(current.Index - 1)); } catch { return(null); } }
public void Swap(int indexA, int indexB) { WordObject tmpA = wordObjects[indexA]; wordObjects[indexA] = wordObjects[indexB]; wordObjects[indexB] = tmpA; wordObjects[indexA].transform.SetAsLastSibling(); wordObjects[indexB].transform.SetAsLastSibling(); //CheckSentence(); }
public List <WordObject> getWordsObjectFromParserServer(String str) { List <WordObject> sentenceFromServer = new List <WordObject>(); var res = new List <WordObject>(); try { string JsonRes = HttpCtrl.sendToHebrewMorphAnalizer(str); if (JsonRes != null && JsonRes != "") { sentenceFromServer = JsonConvert.DeserializeObject <List <WordObject> >(JsonRes); } //may be mispelling for the first time var firstWord = true; // print tagged sentence by using AnalysisInterface, as follows: foreach (WordObject w in sentenceFromServer) { WordObject word = w; //two NRI in a row //join word if ist part of a name if (res.Count > 0) { var last = res.LastOrDefault(); if (((last.Ner == word.Ner && last.Ner != "O") || (last.isA(properNameWord) && word.isA(properNameWord))) && !word.Prefixes.Contains("ו") && !firstWord) { res.LastOrDefault().Text = res.LastOrDefault().Text.Remove(0, res.LastOrDefault().Prefixes.Count()); res.LastOrDefault().Text += " " + word.Text; res.LastOrDefault().Lemma = res.LastOrDefault().Text; continue; } } firstWord = false; res.Add(w); } } catch (Exception ex) //if parser server is down { var words = str.Split(' '); foreach (var w in words) { var word = new WordObject(w, nounWord); sentenceFromServer.Add(word); } } return(res); }
public bool HasNext(WordObject model) { if (model != null) { if (model.Index < CountOfWords) { return(true); } } return(false); }
public WordObject Next(WordObject current) { int _index = current.Index; if (_index < CountOfWords) { return(GetWord(_index + 1)); } else { return(null); } }
public WordObject GetWord(int index) { if (index < CountOfWords) { WordObject model = CleanWordObjects[index]; model.Indexs = CurrentText.IndexAll(model.Value); return(model); } else { return(null); } }
public void isATest() { //good word = new WordObject("O", "text", "feminine", "dual", "any", "polarity", "verb", "unknown", new string[] { "ה" }, "none", "", "", "", "", true, "lemma"); Assert.IsTrue(word.isA(WordObject.WordType.verbWord)); //bad word = new WordObject("O", "text", "feminine", "dual", "any", "polarity", "sddsdsds", "unknown", new string[] { "ה" }, "none", "", "", "", "", true, "lemma"); Assert.IsTrue(word.isA(WordObject.WordType.unknownWord)); //evil word = new WordObject("O", "text", "feminine", "dual", "any", "polarity", null, "unknown", new string[] { "ה" }, "none", "", "", "", "", true, "lemma"); Assert.IsTrue(word.isA(WordObject.WordType.unknownWord)); }
public void Select(WordObject wordObject) { if (firstSelected) { Swap(firstSelected.index, wordObject.index); firstSelected.Select(); wordObject.Select(); } else { firstSelected = wordObject; } }
//Updates the word list to match the saved word database private void UpdateWordPanel() { foreach (string key in DatabaseManager.ActiveDatabase.Keys) { if (!activeWordObjects.ContainsKey(key)) { //We create and initialize word objects WordObject wordObjectCache = Instantiate(wordPrefab, wordsRect).GetComponent <WordObject>(); wordObjectCache.name = key; activeWordObjects.Add(key, wordObjectCache); } } results = DatabaseManager.ActiveDatabase.Keys.ToList(); SizeWordsRect(results.Count); }
public void haveTypeOfTest() { word = new WordObject("O", "dsfds", "feminine", "dfd", "any", "sdds", "noun", "unknown", new string[] { "ה" }, "גדגד", "", "", "", "", true, "lemma"); var word2 = new WordObject("O", "text", "masculine", "dual", "sdds", "polarity", "noun", "dfdf", new string[] { "ת" }, "none", "", "", "", "", true, "lemגדגדma"); //good Assert.IsTrue(word.haveTypeOf(word2)); //bad word2 = new WordObject("O", "text", "masculine", "dual", "sdds", "polarity", "verb", "dfdf", new string[] { "ת" }, "none", "", "", "", "", true, "lemגדגדma"); Assert.IsFalse(word.haveTypeOf(word2)); //ugly word2 = new WordObject("O", "text", "masculine", "dual", "sdds", "polarity", null, "dfdf", new string[] { "ת" }, "none", "", "", "", "", true, "lemגדגדma"); Assert.IsFalse(word.haveTypeOf(word2)); }
private void WordObjectFromEntity(List <WordObject> sentence, List <WordObject> newSentence, IentityBase ent) { var newWord = sentence[ent.entityID].clone(); newWord.WordT = WordObject.typeFromString(ent.entityType); if (ent.entityType == "organizationWord") { newWord.Amount = amountType.plural; newWord.Gender = genderType.masculine; } else if (ent.entityType == "locationWord") { newWord.Amount = amountType.singular; newWord.Gender = genderType.feminine; } else if (ent.entityType == "eventWord") { newWord.Amount = amountType.singular; } IMultyEntity mEnt; if (ent.entityValue.Split(' ').Count() > 0) { newWord.Text = ent.entityValue; if ((mEnt = ent as IMultyEntity) != null) { newWord.Lemma = mEnt.parts.Split(';')[0]; } else { newWord.Lemma = newWord.Text; } } else { newWord.Lemma = ent.entityValue; } newWord.WordT = WordObject.typeFromString(ent.entityType); newSentence.Add(newWord); }
public void findGufContextTest() { listTemplate.AddRange(new ITemplate[] { moqWordObject1.Object, moqWordObject2.Object, moqWordObject3.Object, moqWordObject4.Object }); var guftemplate = new WordObject[] { moqWordGufObjectShe.Object, moqWordGufObjectHe.Object, moqWordGufObjectIt.Object, moqWordGufObjectThey.Object }; string log = ""; var listListObject = new List <List <WordObject> >(); listListObject.Add(guftemplate.ToList()); var res = sAnal.findGufContext(listListObject, listTemplate); var single = res.Single().Cast <WordObject>(); //good Assert.IsTrue(single.Where(x => x == moqWordObject1.Object).Count() == 1); Assert.IsTrue(single.Where(x => x == moqWordObject2.Object).Count() == 1); Assert.IsTrue(single.Where(x => x == moqWordObject3.Object).Count() == 1); Assert.IsTrue(single.Where(x => x == moqWordObject4.Object).Count() == 1); Assert.IsTrue(single.Count() == 4); listTemplate.Clear(); //bad res = sAnal.findGufContext(listListObject, listTemplate); single = res.Single().Cast <WordObject>(); Assert.IsFalse(single.Where(x => x == moqWordObject1.Object).Count() == 1); Assert.IsFalse(single.Where(x => x == moqWordObject2.Object).Count() == 1); Assert.IsFalse(single.Where(x => x == moqWordObject3.Object).Count() == 1); Assert.IsFalse(single.Where(x => x == moqWordObject4.Object).Count() == 1); Assert.IsTrue(single.Count() == 4); //ugly res = sAnal.findGufContext(listListObject, null); single = res.Single().Cast <WordObject>(); Assert.IsFalse(single.Where(x => x == moqWordObject1.Object).Count() == 1); Assert.IsFalse(single.Where(x => x == moqWordObject2.Object).Count() == 1); Assert.IsFalse(single.Where(x => x == moqWordObject3.Object).Count() == 1); Assert.IsFalse(single.Where(x => x == moqWordObject4.Object).Count() == 1); Assert.IsTrue(single.Count() == 4); }
public void WordObjectTest3() { word = new WordObject("O", "text", "feminine", "dual", "any", "polarity", "verb", "unknown", new string[] { "ה" }, "none", "", "", "", "", true, "lemma"); Assert.AreNotEqual(word, null); Assert.AreEqual(word.Amount, personObject.amountType.dual); Assert.AreEqual(word.Gender, personObject.genderType.feminine); Assert.AreEqual(word.IsDefinite, true); Assert.AreEqual(word.Lemma, "lemma"); Assert.AreEqual(word.Ner, "O"); Assert.AreEqual(word.Pos, "verb"); Assert.AreEqual(word.WordT, WordObject.WordType.verbWord); Assert.AreEqual(word.WorldObject, new VerbObject("text")); Assert.AreEqual(word.Time, personObject.timeType.none); Assert.AreEqual(word.Text, "text"); Assert.IsTrue(word.Prefixes.Single() == "ה"); Assert.AreEqual(word.Person, personObject.personType.any); Assert.AreEqual(word.Text, "text"); }
// Display something when player is wrong. void displayCorrection(WordObject word) { // If the word was incorrect. if (word.word != word.correction) { correction.gameObject.transform.Find("Title").GetComponentInChildren <TextMesh>().text = "Le mot était mauvais !"; correction.gameObject.transform.Find("IncorrectWord").GetComponentInChildren <TextMesh>().text = word.word; correction.gameObject.transform.Find("CorrectWord").GetComponentInChildren <TextMesh>().text = word.correction; // If the word was correct. } else { correction.gameObject.transform.Find("Title").GetComponentInChildren <TextMesh>().text = "Le mot était bon !"; correction.gameObject.transform.Find("IncorrectWord").GetComponentInChildren <TextMesh>().text = ""; correction.gameObject.transform.Find("CorrectWord").GetComponentInChildren <TextMesh>().text = word.word; } // Display the text. correction.SetActive(true); }
/// <summary> /// Returns true if the wordObject meets the criteria to be a tag. /// </summary> /// <param name="wordObject"></param> /// <returns></returns> private static bool WordQualifiesAsTag(WordObject wordObject) { const double NOUN_RATIO_THRESHOLD = 0.45; const int MINIMUM_LENGTH = 3; if (wordObject.Word.Length < MINIMUM_LENGTH) { return(false); } int nounCount = 0; foreach (var definition in wordObject.Definitions) { if (definition.PartOfSpeech == "noun") { nounCount++; } } return(((double)nounCount / wordObject.Definitions.Count) > NOUN_RATIO_THRESHOLD); }
// Spawn a random word at a random position and save the word inside the object. void SpawnWord() { // Randoms. int randomPosition = Random.Range(0, 4); int randomRange = Random.Range(0, words.Length); // Objects. GameObject newWord = Instantiate(word); WordObject randomWord = words[randomRange]; Word wordContent = newWord.GetComponent <Word>(); // Position the new word. newWord.transform.position = new Vector3(wordPositions[randomPosition], 5.5f, 0); // Save the wordObject inside the object. wordContent.word = randomWord; // Display text. newWord.GetComponentInChildren <TextMesh>().text = randomWord.word; numberOfWords -= 1; }
// Load list word from file word data public void InitWord() { List <List <string> > words = FileLoader.LoadLineFromFile(WORD_PATH, false); WordObject wordObj; foreach (var word in words) { if (word != null && word[0] != "") { wordObj = new WordObject { m_id = int.Parse(word[0]), m_categoryId = int.Parse(word[1]), m_word = word[2].Trim(), m_image = word[3].Trim(), m_sound = word[4].Trim(), m_wordCount = int.Parse(word[5]), m_win = int.Parse(word[6]), m_lose = int.Parse(word[7]) }; m_wordList.Add(wordObj); } } }
///<summary> /// Set the active word object and invoke onChangeWordObject which updates the definitions panel ui. ///</summary> public static void SetActiveWord(WordObject wordObject) { ActiveWordObject = (wordObject == ActiveWordObject) ? null : wordObject; OnChangeWordObject.Invoke(); }
public async void AddWord(WordObject word) { await Context.WordObjects.AddAsync(word); await Context.SaveChangesAsync(); }
//add a new word to the language public void addWord() { WordObject _wordToAdd = new WordObject(keyToSet, wordToSet); words.Add(_wordToAdd); }
public WordModel(WordObject model) : base() { Model = new WordObject(model.Value, model.Index); }
public WordModel(string model) : base() { Model = new WordObject(model); }