示例#1
0
        protected override List <Meaning> ValidateMeanings(Acronym acronym)
        {
            string acronymCaption = _setAcronymToLowerCase
                                        ? acronym.Caption.ToLowerInvariant()
                                        : acronym.Caption;

            acronymCaption = HttpUtility.UrlEncode(StringTreatment.RemoveDiacritics(acronymCaption)
                                                   .Replace(".", string.Empty)
                                                   .Replace("/", string.Empty));

            List <string> meanings = getMeanings(acronymCaption);

            if (meanings != null && meanings.Count == 0 && acronymCaption.Contains("-"))
            {
                meanings = getMeanings(acronymCaption.Replace("-", string.Empty));
            }

            List <Meaning> validatedMeanings = null;

            if (meanings != null)
            {
                validatedMeanings = acronym.Meanings.Where(x => meanings.Any(y => y.IndexOf(x.Caption.ToUpperInvariant()) >= 0 ||
                                                                             x.Caption.ToUpperInvariant().IndexOf(y) >= 0)).ToList();
            }

            return(validatedMeanings);
        }
示例#2
0
    public void OnCheckInput(string text)
    {
        // Check user string

        // Store user action in GameStats


        string lexicomixWord = mediaController.GetClues(testOrder[nextTestIndex]).ToLower();

        text = text.ToLower();

        if (text == lexicomixWord)
        {
            StartCoroutine(ComputeNextTest());
            return;
        }

        text          = StringTreatment.RemoveDiacritics(text);
        lexicomixWord = StringTreatment.RemoveDiacritics(mediaController.GetClues(testOrder[nextTestIndex]));
        lexicomixWord = lexicomixWord.Replace("-", "").Replace(" ", "");

        if (text == lexicomixWord)
        {
            StartCoroutine(ComputeNextTest());
        }
    }
        private TextSplitted getTextSplitted(FoundAcronym acronym, string text)
        {
            TextSplitted ret = new TextSplitted();

            string          leftText = StringTreatment.NormalizeText(text.Substring(0, acronym.Index));
            MatchCollection newLines = Regex.Matches(leftText, Environment.NewLine, RegexOptions.RightToLeft);

            if (newLines.Count == 0)
            {
                ret.MainParagraph = leftText.Trim();
            }
            else
            {
                ret.MainParagraph = leftText.Substring(newLines[0].Index).Trim();
                leftText          = leftText.Substring(0, newLines[0].Index);
                for (int i = 1; i <= _paragraphsAround && i <= newLines.Count; i++)
                {
                    string nextParagraph = leftText.Substring(i < newLines.Count ? newLines[i].Index : 0);
                    if (!string.IsNullOrWhiteSpace(nextParagraph))
                    {
                        ret.LeftParagraphs.Add(nextParagraph.Trim());
                    }
                    if (i < newLines.Count)
                    {
                        leftText = leftText.Substring(0, newLines[i].Index);
                    }
                }
            }

            ret.MainParagraph += " "; // +acronym.Caption + " ";

            string rightText = StringTreatment.NormalizeText(text.Substring(acronym.Index + acronym.Caption.Length));

            newLines = Regex.Matches(rightText, Environment.NewLine);
            if (newLines.Count == 0)
            {
                ret.MainParagraph += rightText.Trim();
            }
            else
            {
                ret.MainParagraph += rightText.Substring(0, newLines[0].Index).Trim();
                int indexOfLastLineBreak = newLines[0].Index;
                for (int i = 1; i <= _paragraphsAround && i <= newLines.Count; i++)
                {
                    string nextParagraph = rightText.Substring(indexOfLastLineBreak, i < newLines.Count ? (newLines[i].Index - indexOfLastLineBreak)
                                                                                                        : rightText.Length - indexOfLastLineBreak);
                    if (!string.IsNullOrWhiteSpace(nextParagraph))
                    {
                        ret.RightParagraphs.Add(nextParagraph.Trim());
                    }
                    if (i < newLines.Count)
                    {
                        indexOfLastLineBreak = newLines[i].Index;
                    }
                }
            }

            return(ret);
        }
示例#4
0
        public void FindComments_StrWithCommInMultyLine_returnStrWithoutComms(string str, string expected)
        {
            //act
            string actual = StringTreatment.FindComments(str);

            //assert
            Assert.Equal(actual, expected);
        }
示例#5
0
        private string cleanMatch(string match)
        {
            StringBuilder cleanMatch = new StringBuilder(StringTreatment.RemoveDiacritics(match));

            cleanMatch.Replace("-", string.Empty);
            cleanMatch.Replace("/", string.Empty);

            return(cleanMatch.ToString());
        }
示例#6
0
    public void BuildingSyllable(CharPack pack)
    {
        Debug.Log("Input Syllable:  " + thisSyllable.Text);
        Debug.Log("Pack: " + pack);

        bool hit = true;

        char[] syllArray = thisSyllable.Text.ToCharArray();
        for (int i = 0; i < syllArray.Length; i++)
        {
            // String treatments (Remove Diacritics locked by default, for now)
            string input     = myCharInputs[i].text.ToLower().Trim();
            string reference = StringTreatment.RemoveDiacritics(syllArray[i].ToString().ToLower().Trim());

            Debug.Log(input + "=" + reference);

            if (!input.Equals(reference))
            {
                Debug.Log(myCharInputs[i].text + "=" + syllArray[i]);
                hit = false;
                break;
            }

            myCharInputs[i].transform.parent.GetComponent <Image>().color = Color.green;
        }

        if (pack.enter)
        {
            myInputZoneParent.SendWholeInputText();
            return;
        }


        if (hit)
        {
            SyllableHit(pack.charIndex);

            //LockInputs();

            return;
        }

        // Move forward/backward according to key pressed
        if (pack.backspace || pack.leftArrow)
        {
            if (pack.charIndex > 0)
            {
                myInputZoneParent.SelectPreviousCharInput(pack.charIndex);
            }
        }
        else
        {
            myInputZoneParent.SelectNextCharInput(pack.charIndex);
        }
    }
示例#7
0
        private bool cutDefinitionExplicit(string match, ref string definition)
        {
            bool ret = false;

            MatchCollection upperCaseLetters = Regex.Matches(StringTreatment.RemoveDiacritics(definition),
                                                             @"\p{Lu}",
                                                             _cutBeginOfDefinition
                                                                ? RegexOptions.RightToLeft
                                                                : RegexOptions.None);
            List <char> matchParts = new List <char>(cleanMatch(match).ToUpperInvariant().ToCharArray());

            foreach (Match upperCaseLetter in upperCaseLetters)
            {
                matchParts.Remove(upperCaseLetter.Value.ToCharArray()[0]);
                if (matchParts.Count == 0)
                {
                    ret = true;
                    if (_cutBeginOfDefinition)
                    {
                        string leftOfUpperCaseLetter = definition.Substring(0, upperCaseLetter.Index);

                        Match restOfAcronym = Regex.Match(leftOfUpperCaseLetter, "(^|\\s)(?<restOfAcronym>(?:[A-Z]\\.?\\-?\\/?)+)$", RegexOptions.RightToLeft);
                        if (restOfAcronym.Success)
                        {
                            if (restOfAcronym.Groups["restOfAcronym"].Value.StartsWith(upperCaseLetter.Value))
                            {
                                definition = definition.Substring(restOfAcronym.Index).TrimStart();
                            }
                            else
                            {
                                ret = false;
                            }
                        }
                        else
                        {
                            Match beginOfWord = Regex.Match(leftOfUpperCaseLetter, "(^|\\s)", RegexOptions.RightToLeft);
                            definition = definition.Substring(beginOfWord.Success
                                                                ? beginOfWord.Index + (beginOfWord.Value.Length > 0 ? 1 : 0)
                                                                : upperCaseLetter.Index);
                        }
                    }
                    else if (_cutEndOfDefinition)
                    {
                        string rightOfUpperCaseLetter = definition.Substring(upperCaseLetter.Index);
                        Match  endOfWord = Regex.Match(rightOfUpperCaseLetter, "($|\\s)");

                        definition = definition.Substring(0, upperCaseLetter.Index + (endOfWord.Success ? endOfWord.Index : 0));
                    }
                    break;
                }
            }

            return(ret);
        }
示例#8
0
        public override IEnumerable <FoundMatchBase> FindMatches(ResourceInformation information)
        {
            information.Content = StringTreatment.NormalizeText(information.Content);

            return(FindMatches(information.Content));
        }
示例#9
0
        private bool cutDefinitionImplicit(string match, ref string definition)
        {
            int                  numberOfCharacters = 0;
            int                  numberOfSeparatorsSinceLastIncludedWord = 0;
            List <char>          matchParts                    = new List <char>(cleanMatch(match).ToUpperInvariant().ToCharArray());
            List <char>          removedMatchParts             = new List <char>(matchParts.Count);
            List <string>        shorterMatchedDefinitionParts = new List <string>();
            IEnumerable <string> definitionParts               = StringTreatment.RemoveDiacritics(definition).ToUpperInvariant().Split(_wordSeparators);

            if (_cutBeginOfDefinition)
            {
                definitionParts = definitionParts.Reverse();
            }

            foreach (string definitionPart in definitionParts)
            {
                if (definitionPart.Length == 0 &&
                    matchParts.Count == 0)
                {
                    numberOfSeparatorsSinceLastIncludedWord++;
                }
                if (definitionPart.Length > 0)
                {
                    char definitionPartFirstLetter = definitionPart.Substring(0, 1).ToCharArray()[0];
                    if (matchParts.Count == 0)
                    {
                        if (!removedMatchParts.Contains(definitionPartFirstLetter) ||
                            definitionPart.Length <= 3 ||
                            shorterMatchedDefinitionParts.Where(x => x.StartsWith(definitionPart.Substring(0, 1))).All(x => x.Length > 3))
                        {
                            break;
                        }
                        else
                        {
                            numberOfCharacters = numberOfCharacters + 1 + numberOfSeparatorsSinceLastIncludedWord;
                            numberOfSeparatorsSinceLastIncludedWord = 0;
                        }
                    }
                    numberOfCharacters += definitionPart.Length;

                    if (matchParts.Remove(definitionPartFirstLetter))
                    {
                        removedMatchParts.Add(definitionPartFirstLetter);
                        shorterMatchedDefinitionParts.Add(definitionPart);
                    }
                    else if (removedMatchParts.Contains(definitionPartFirstLetter))
                    {
                        string longerMatchedDefinitionPart = shorterMatchedDefinitionParts.OrderBy(x => x.Length)
                                                             .FirstOrDefault(x => x.Length < definitionPart.Length &&
                                                                             x.StartsWith(definitionPart.Substring(0, 1)));

                        if (longerMatchedDefinitionPart != null)
                        {
                            shorterMatchedDefinitionParts.Remove(longerMatchedDefinitionPart);
                            shorterMatchedDefinitionParts.Add(definitionPart);
                        }
                    }
                }
                if (matchParts.Count > 0)
                {
                    numberOfCharacters++;
                }
            }
            bool ret = matchParts.Count == 0;

            if (ret)
            {
                if (_cutBeginOfDefinition)
                {
                    definition = definition.Substring(definition.Length - numberOfCharacters);
                }
                else if (_cutEndOfDefinition)
                {
                    definition = definition.Substring(0, numberOfCharacters);
                }
            }
            return(ret);
        }
示例#10
0
    public void BuildingSyllable2(CharPack pack)
    {
        Debug.Log("Full Syllable:  " + thisSyllable.Text);
        Debug.Log("Pack: " + pack);

        if (pack.enter)
        {
            myInputZoneParent.SendWholeInputText();
            return;
        }

        int hits = thisSyllable.Text.Length;

        char[] syllArray = thisSyllable.Text.ToCharArray();
        for (int i = 0; i < syllArray.Length; i++)
        {
            // String treatments (Remove Diacritics locked by default, for now)
            string input     = myCharInputs[i].text.ToLower().Trim();
            string reference = StringTreatment.RemoveDiacritics(char.ToLower(syllArray[i]).ToString());

            Debug.Log(input + " should be equal to " + reference);

            if (!input.Equals(reference))
            {
                Debug.Log(myCharInputs[i].text + "!=" + syllArray[i]);

                if (input.Length == 0 && !thisSyllable.Text.Contains(input))
                {
                    myCharInputs[i].transform.parent.GetComponent <Image>().color = Color.red;
                }

                if (input.Length == 0 && thisSyllable.Text.Contains(input))
                {
                    myCharInputs[i].transform.parent.GetComponent <Image>().color = Color.yellow;
                }
            }
            else
            {
                hits--;
                myCharInputs[i].transform.parent.GetComponent <Image>().color = Color.green;
                //LockInput(i);
            }

            if (hits <= 0)
            {
                SyllableHit(pack.charIndex);
                return;
            }
        }

        foreach (LXInputField g in myCharInputs)
        {
            if (g.text.Length == 0)
            {
                g.transform.parent.GetComponent <Image>().color = originalColor;
            }
        }

        if (pack.backspace && pack.charString.Length != 0)
        {
            myCharInputs[pack.charIndex].text = string.Empty;
            return;
        }


        // Move forward/backward according to key pressed
        if (pack.backspace || pack.leftArrow)
        {
            //myCharInputs[pack.charIndex].text = string.Empty;

            if (pack.charIndex > 0)
            {
                myInputZoneParent.SelectPreviousCharInput(pack.charIndex);
            }
        }
        else
        {
            myInputZoneParent.SelectNextCharInput(pack.charIndex);
        }
    }
示例#11
0
        static void Main(string[] args)
        {
            string[]      buff         = { "it", "is", "not", "empty" };
            NotificationS notification = new NotificationS(true, buff);

            buff = new string[] { "hey", "why", "do", "you", "read", "this" };
            MessagesS  messages   = new MessagesS(true, buff);
            Programmer programmer = new Programmer(notification, messages);

            //Programmer programmer2 = new Programmer();
            programmer.showAll();
            programmer.OnDelete += programmer.GetNotific.IfCount;
            programmer.OnMute   += programmer.GetMessage.Mute;
            programmer.OnDelete += programmer.GetMessage.IfCount;

            //programmer.OnDelete += notification.IFCOUNT;
            //programmer.OnDelete += messages.IFCOUNT;
            //programmer.OnMute += messages.Mute;
            //programmer.OnMute += notification.Mute;
            //programmer.OnDelete += notification.IFCOUNT;
            //programmer.OnDelete += messages.IFCOUNT;
            //programmer.OnMute += messages.Mute;
            //programmer.OnMute += notification.Mute;

            //programmer2.OnMute += messages.Mute;
            //programmer2.OnMute += notification.Mute;
            //programmer2.OnDelete += messages.IFCOUNT;
            //programmer2.OnDelete += notification.IFCOUNT;


            programmer.Do();
            programmer.showAll();
            //programmer2.Do();

            Console.WriteLine("\n String Treatment \n");

            StringTreatment stringTreatment = new StringTreatment();

            startconf = "This,         : Is!       Example.";
            newstr1   = startconf;
            Console.WriteLine(newstr1 + "\n Start configuration");

            //Console.WriteLine("\t+\t To Lower Case");
            //stringTreatment.func1 = stringTreatment.toLowerCase;

            //newstr1 = stringTreatment.func1(newstr1);
            //Console.WriteLine(newstr1.Append('\n'));

            //Console.WriteLine("\t-\t To Lower Case");
            //stringTreatment.func1 -= stringTreatment.toLowerCase;
            //Console.WriteLine("\t+\t To Upper Case");
            //stringTreatment.func1 += stringTreatment.toUpperCase;

            //newstr1 =  stringTreatment.func1(newstr1);
            //Console.WriteLine(newstr1);

            //Console.WriteLine("\t-\t To Upper Case");
            //stringTreatment.func1 -= stringTreatment.toUpperCase;
            Console.WriteLine("\t+\t To Delete Signs");
            stringTreatment.func1 = stringTreatment.delSigns;
            Console.WriteLine("\t+\t To Delete Space");
            stringTreatment.func1 += stringTreatment.delSpace;
            newstr1 = startconf;

            newstr1 = stringTreatment.func1(newstr1);
            Console.WriteLine(newstr1);

            stringTreatment.func2 = stringTreatment.addSymbol;
            newstr1 = stringTreatment.func2(4, 'q', newstr1);
            Console.WriteLine(newstr1);


            Console.ReadKey();
        }