示例#1
0
        public static bool IsWord(this Word _word)
        {
            WordNature nature = _word.Nature();

            if (nature == WordNature.Ponctuation || nature == WordNature.Expression || nature == WordNature.Negation || nature == WordNature.Number)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public static Word Random(this WordNature _nature)
        {
            Word result = Word.none;

            do
            {
                result = (Word)UnityEngine.Random.Range(1, 121);
            } while (result.Nature() != _nature);

            return(result);
        }
示例#3
0
        public static SentenceConstruction Construction(this Sentence _sentence)
        {
            WordNature[] structure = new WordNature[_sentence.size];
            Dictionary <WordNature, int> counts = new Dictionary <WordNature, int>();

            int verbIndex = -1;

            for (int i = 0; i < 7; i++)
            {
                counts.Add((WordNature)i, 0);
            }

            for (int i = 0; i < _sentence.size; i++)
            {
                WordNature nature = _sentence.words[i].Nature();

                structure[i] = nature;
                counts[nature]++;
                if (_sentence.words[i].Nature(WordNature.Verb) && verbIndex == -1)
                {
                    verbIndex = i;
                }
            }

            if (counts[WordNature.Noun] == 0 && counts[WordNature.Adjective] == 0)
            {
                if (counts[WordNature.Expression] > 0)
                {
                    return(SentenceConstruction.E);
                }
                else
                {
                    return(SentenceConstruction.none);
                }
            }
            else if (counts[WordNature.Verb] > 0)
            {
                return(_sentence.words[verbIndex].Type());
            }
            else
            {
                return(SentenceConstruction.O);
            }
        }
示例#4
0
        public static float SentenceEsteem(this Sentence _sentence, Alien _alien)
        {
            float result   = 0;
            float verb     = 0;
            bool  negative = false;

            const float gaussianFactorA = 2.5f;
            const float gaussianFactorC = 1.12f;

            for (int i = 0; i < _sentence.size; i++)
            {
                WordNature nature = _sentence.words[i].Nature();

                if (nature == WordNature.Noun)
                {
                    Alien.GlossaryValues word = _alien.glossary[_sentence.words[i]];

                    //float weight = -Mathf.Pow(word.iterations, 2) * .05f * word.value + word.value > 0 ? Mathf.Clamp(-Mathf.Pow(word.iterations, 2) * .05f * word.value + word.value, 0, 2) : Mathf.Clamp(-Mathf.Pow(word.iterations, 2) * .05f * word.value + word.value, -2, 0);
                    float weight = Mathf.Pow(gaussianFactorA, -(Mathf.Pow(word.iterations, 2) / (2 * Mathf.Pow(gaussianFactorC, 2)))) * word.value;
                    if (i == 0)
                    {
                        result += weight / 10;
                    }
                    else if (verb == 0 && _sentence.Construction() != SentenceConstruction.O)
                    {
                        if (_sentence.words[i - 1].Nature(WordNature.Adjective))
                        {
                            result += weight / 10 * _sentence.words[i - 1].Value();
                        }
                        else
                        {
                            result += weight / 10;
                        }
                    }
                    else
                    {
                        if (_sentence.words[i - 1].Nature(WordNature.Adjective))
                        {
                            result += weight * _sentence.words[i - 1].Value();
                        }
                        else
                        {
                            result += weight;
                        }
                    }

                    word.iterations++;
                }
                else if (nature == WordNature.Verb && verb == 0)
                {
                    verb = _sentence.words[i].Value();
                }
                else if (nature == WordNature.Verb)
                {
                    result += _sentence.words[i].Value() > 0 ? _sentence.words[i].Value() + 1 : -1 + _sentence.words[i].Value();
                }
                else if (_sentence.words[i] == Word.Not)
                {
                    negative = true;
                }
            }

            if (verb == 0)
            {
                verb = 1;
            }

            result *= verb * (negative ? -1 : 1);

            result = result * 8 / _sentence.size;

            return(result);
        }
示例#5
0
 public static bool Nature(this Word _word, WordNature _nature)
 {
     return(_word.Nature() == _nature);
 }