예제 #1
0
        /// <summary>
        /// Helper method that adds the current noun to a list. Follows the following rules:
        /// 1. If gender length is 0: doesn't add, since not a useful word
        /// 2. If the word length is 0: take the same word as last time. Reasoning behind this: words with double gender are present as WORD {m} {f}
        /// 3. All values get trimmed
        /// </summary>
        /// <param name="word"></param>
        /// <param name="gender"></param>
        /// <param name="list"></param>
        private void AddNoun(StringBuilder word, StringBuilder gender, List <Lemma> list)
        {
            if (gender.Length > 0)
            {
                Noun item = new Noun();
                item.Gender = NounGenderConvert.ToGender(ToTrimmedString(gender));
                item.Word   = ToTrimmedString(word);
                if (item.Word.Length == 0)
                {
                    // take same word as last time
                    if (list.Count > 0)
                    {
                        item.Word = list.Last().Word;
                    }
                    else
                    {
                        return;
                    }
                }
                list.Add(item);
            }

            sbType.Clear();
            sbWord.Clear();
        }
예제 #2
0
 void Awake()
 {
     if (m_instance == null)
     {
         m_instance = this;
     }
     else if (m_instance != this)
     {
         Destroy(gameObject);
         return;
     }
     foreach (System.Type type in
              Assembly.GetAssembly(typeof(Verb)).GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(Verb))))
     {
         Verb v = (Verb)Activator.CreateInstance(type);
         m_Verbs.Add(v.GetType().ToString(), v);
     }
     foreach (System.Type type in
              Assembly.GetAssembly(typeof(Noun)).GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(Noun))))
     {
         Noun n = (Noun)Activator.CreateInstance(type);
         Debug.Log(n.GetType().ToString());
         m_Nouns.Add(n.GetType().ToString(), n);
     }
 }
예제 #3
0
    public float GetImpressionModifiers(Noun imp)
    {
        Noun targetI;

        if (!m_typeLookup.ContainsKey(imp.GetType()))
        {
            foreach (Noun i in m_impressionEvaluation.Keys)
            {
                if (LogicManager.IsA(i, imp, m_observer))
                {
                    targetI = i;
                    continue;
                }
            }
            return(0.0f);
        }
        else
        {
            targetI = m_typeLookup[imp.GetType()];
        }
        updateImpressionModifiers();
        float value = 0;

        if (!m_impressionEvaluation.ContainsKey(targetI))
        {
            return(0f);
        }
        foreach (ImpressionModifier dm in m_impressionEvaluation[targetI])
        {
            value += dm.getModValue();
        }
        return(value);
    }
예제 #4
0
    public void ClearModifier(Noun i, ImpressionModifier newDM)
    {
        if (!m_typeLookup.ContainsKey(i.GetType()))
        {
            return;
        }
        Debug.Log("Attempting to remove: " + i.GetType());
        if (m_typeLookup[i.GetType()] == null)
        {
            m_typeLookup[i.GetType()] = i;
        }
        i = m_typeLookup[i.GetType()];

        Debug.Log("Found: " + i);
        updateImpressionModifiers();

        List <ImpressionModifier> newL = new List <ImpressionModifier>();

        if (!m_impressionEvaluation.ContainsKey(i))
        {
            m_impressionEvaluation[i] = newL;
            return;
        }

        foreach (ImpressionModifier dm in m_impressionEvaluation[i])
        {
            if (dm.ID != newDM.ID)
            {
                newL.Add(dm);
            }
        }
        m_isDirty = true;
        m_impressionEvaluation[i] = newL;
    }
예제 #5
0
        public List <Noun> ProccessRange(List <string> nominatives)
        {
            List <Noun> result = new List <Noun>();

            foreach (var nominative in nominatives)
            {
                Noun current = _repository.GetByNominative(nominative);

                if (current == null)
                {
                    current = new Noun()
                    {
                        Nominative   = nominative,
                        Genitive     = _nounHelper.GetGenitive(nominative),
                        Dative       = _nounHelper.GetDativeOrLocative(nominative),
                        Accusative   = _nounHelper.GetAccussative(nominative),
                        Vocative     = _nounHelper.GetVocative(nominative),
                        Instrumental = _nounHelper.GetInstrumental(nominative),
                        Locative     = _nounHelper.GetDativeOrLocative(nominative),
                        IsGuaranteed = false
                    };

                    Add(current);
                }

                // Notify admin by email.
                _emailService.SendNewNounEmail(nominative);

                result.Add(current);
            }

            return(result);
        }
예제 #6
0
        private static void LoadGenderNouns()
        {
            _genderNouns   = new Dictionary <string, string>();
            string[,] data = StringUtils.ReadTable(FileUtils.ReadResource("dict/gender_nouns.csv"));
            for (int i = 0; i < data.GetLength(0); i++)
            {
                _genderNouns.Add(data[i, 0], data[i, 1]);
                Noun nm = DbContext.GetNoun(data[i, 0]);
                if (nm == null)
                {
                    nm = new Noun(data[i, 0], GetNounPlural(data[i, 0]));
                    DbContext.Add(nm);
                    DbContext.SaveChanges();
                }

                Noun nf = DbContext.GetNoun(data[i, 1]);
                if (nf != null)
                {
                    DbContext.Remove(nf);
                }
                nm.SetFemale(data[i, 1], GetNounPlural(data[i, 1]));
                DbContext.Update(nm);
            }

            DbContext.SaveChanges();
        }
예제 #7
0
        /// <summary>
        /// This method finds a  'Noun' object.
        /// This method uses the 'Noun_Find' procedure.
        /// </summary>
        /// <returns>A 'Noun' object.</returns>
        /// </summary>
        public Noun FindNoun(FindNounStoredProcedure findNounProc, DataConnector databaseConnector)
        {
            // Initial Value
            Noun noun = null;

            // Verify database connection is connected
            if ((databaseConnector != null) && (databaseConnector.Connected))
            {
                // First Get Dataset
                DataSet nounDataSet = this.DataHelper.LoadDataSet(findNounProc, databaseConnector);

                // Verify DataSet Exists
                if (nounDataSet != null)
                {
                    // Get DataTable From DataSet
                    DataRow row = this.DataHelper.ReturnFirstRow(nounDataSet);

                    // if row exists
                    if (row != null)
                    {
                        // Load Noun
                        noun = NounReader.Load(row);
                    }
                }
            }

            // return value
            return(noun);
        }
예제 #8
0
		private void Add(Noun _noun)
		{
			if (_noun == this)
			{
				return;
			}

			if (AlsoKnownAs != null)
			{
				AlsoKnownAs.Add(_noun);
			}
			else
			{
				AlsoKnownAs = _noun;
				if (_noun.Adjective == null)
				{
					_noun.Adjective = Adjective;
				}
				if (_noun.Immutable == null)
				{
					_noun.Immutable = Immutable;
				}
				if (_noun.OfSomething == null)
				{
					_noun.OfSomething = OfSomething;
				}
			}
		}
예제 #9
0
        private void SetEdited(Panel targetPanel, Noun noun)
        {
            foreach (Control ctrl in targetPanel.Controls)
            {
                if (!(ctrl is ControlNounCaseEdit))
                {
                    continue;
                }

                ControlNounCaseEdit edit = ctrl as ControlNounCaseEdit;
                if (noun == null)
                {
                    edit.Value = "";
                }
                else
                {
                    string form = NounDecliner.Decliner.MakeWord(
                        noun, edit.InflectionCase, edit.DecliantionNumber);
                    edit.Value     = form;
                    edit.PostFixes = NounDecliner.Decliner.GetPostFix(noun.Genre, noun.DeclinationType,
                                                                      edit.InflectionCase, DecliantionNumber.Singular).Split(' ');
                    edit.PostFixIndex = NounGrammar.GetPostFixIndex(noun, DecliantionNumber.Singular, edit.InflectionCase);
                }
            }
        }
예제 #10
0
        public async Task <IHttpActionResult <NounDto> > Post([FromBody] NounDto nounDto)
        {
            try
            {
                Noun noun = new Noun
                {
                    Value            = nounDto.Value,
                    ModificationDate = DateTime.Now
                };
                if (await _nounService.ExistsAsync(noun))
                {
                    return(BadRequest <NounDto>("Entry already exists"));
                }
                else
                {
                    noun = await _nounService.CreateAsync(noun);

                    return(Ok(noun.ToNounDto()));
                }
            }
            catch
            {
                return(InternalServerError <NounDto>(new NounDto()));
            }
        }
예제 #11
0
    public static string AsSubject(this Noun noun)
    {
        switch (noun)
        {
        case Noun.Potion:
        case Noun.MemoryLoss:
            return("the potion that");

        case Noun.ExWife:
            return("the victim's " + bold("ex-wife"));

        case Noun.Daughter:
            return("the victim's " + bold("daughter"));

        case Noun.Mistress:
            return("the victim's " + bold("mistress"));

        case Noun.Artist:
            return("an " + bold(noun.ToString().ToLower()));

        case Noun.Scientist:
        case Noun.Writer:
        case Noun.Philanthropist:
            return("a " + bold(noun.ToString().ToLower()));

        case Noun.OwesDebt:
            return("the debt");

        default:
            // This will happen for names
            return(bold(noun.ToString()));
        }
    }
예제 #12
0
        public void PartTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("a cat is a kind of person",
                            "a persian is a kind of cat",
                            "a tabby is a kind of cat",
                            "a siamese is a kind of cat",
                            "a cat can be haughty",
                            "a cat can be cuddly",
                            "a cat can be crazy",
                            "a persian can be matted",
                            "red, blue, and green are kinds of color",
                            "a cat has a color called its favorite color");
            var cat   = (CommonNoun)Noun.Find("cat");
            var color = (CommonNoun)Noun.Find("color");
            var g     = new Generator(cat);

            for (var n = 0; n < 100; n++)
            {
                var i = g.Solve();
                Assert.IsTrue(i.IsA(i.Individuals[0], cat));
                Assert.IsTrue(i.IsA(i.Individuals[0], "persian") ||
                              i.IsA(i.Individuals[0], "tabby") ||
                              i.IsA(i.Individuals[0], "siamese"));
                Assert.AreEqual(i.Individuals[0], i.Individuals[1].Container);
                Assert.IsTrue(i.IsA(i.Individuals[1], color));
                Console.WriteLine(i.Model.Model);
                Console.WriteLine(i.Description(i.Individuals[0]));
            }
        }
예제 #13
0
파일: Map.cs 프로젝트: sycomix/Sentient
        public static Word SignalToEntity(SL.Word impulse)
        {
            Word word = null;

            if (typeof(Noun).Name.ToLowerInvariant() == impulse.Type.ToLowerInvariant())
            {
                word = new Noun
                {
                    Name       = impulse.Name,
                    Definition = impulse.Description,
                };
            }

            if (typeof(Adjective).Name.ToLowerInvariant() == impulse.Type.ToLowerInvariant())
            {
                word = new Adjective
                {
                    Name       = impulse.Name,
                    Definition = impulse.Description,
                };
            }

            if (typeof(Verb).Name.ToLowerInvariant() == impulse.Type.ToLowerInvariant())
            {
                word = new Verb
                {
                    Name       = impulse.Name,
                    Definition = impulse.Description,
                };
            }

            return(word);
        }
예제 #14
0
        public async Task <IHttpActionResult <OpNameDto> > Get()
        {
            try
            {
                Adjective adj = await _adjService.ReadRandomAsync();

                Noun noun = await _nounService.ReadRandomAsync();

                if (adj == null || noun == null)
                {
                    return(Ok <OpNameDto>(new OpNameDto()));
                }

                OpNameDto opNameDto = new OpNameDto
                {
                    Adjective = adj.Value,
                    Noun      = noun.Value
                };
                return(Ok <OpNameDto>(opNameDto));
            }
            catch
            {
                return(InternalServerError <OpNameDto>(new OpNameDto()));
            }
        }
예제 #15
0
        public static int GetPostFixIndex(Noun noun, DecliantionNumber amount, InflectionCase aCase)
        {
            switch (amount)
            {
            case DecliantionNumber.Plural:
            {
                if (noun.PluralPostfixSelector.ContainsKey(aCase))
                {
                    return(noun.PluralPostfixSelector[aCase]);
                }
                break;
            }

            case DecliantionNumber.Singular:
            {
                if (noun.SingularPostfixSelector.ContainsKey(aCase))
                {
                    return(noun.SingularPostfixSelector[aCase]);
                }
                break;
            }
            }

            return(0);
        }
예제 #16
0
 public void InterningNounTest()
 {
     Ontology.EraseConcepts();
     ParseAndExecute("Tabby, Persian, and Maine Coon are kinds of cat");
     Assert.IsNotNull(Noun.Find("Persian"));
     Assert.IsNotNull(Noun.Find("Persians"));
 }
예제 #17
0
 public OfSomething(Noun noun)
     : base(noun.Text, noun.Sex, noun.IsCreature)
 {
     Adjective   = noun.Adjective;
     CoName      = noun.CoName;
     AlsoKnownAs = noun.AlsoKnownAs;
 }
예제 #18
0
    public int GetItemCount(Noun itemType, InventorySlotType slotType, Observer perspective)
    {
        int stack = 0;

        if (slotType == InventorySlotType.NORMAL)
        {
            foreach (InventoryItemData iid in items.Values)
            {
                if (itemType.IsA(iid.EquipmentInstance.gameObject, perspective) > 0f)
                {
                    stack += iid.EquipmentInstance.CurrentStack;
                }
            }
            return(stack);
        }
        foreach (EquipmentSlot es in slotData)
        {
            if (es.SlotType == slotType)
            {
                InventoryItemData iid = GetItem(es.coordinate);
                if (itemType.IsA(iid.EquipmentInstance.gameObject, perspective) > 0f)
                {
                    stack += iid.EquipmentInstance.CurrentStack;
                }
            }
        }
        return(stack);
    }
예제 #19
0
    void Start()
    {
        string[] lines = new string[0];
        lines = File.ToString().Split('\n');
        Debug.Log("There are " + lines.Length + " words to be added");
        if (lines.Length > 500)
        {
            throw new System.Exception("Theres waaay to many ostriches. More then 500 items.");
        }
        for (int i = 1; i < lines.Length; i++)
        {
            string[] parts = lines[i].Split(',');

            Word word = new Word(parts);

            switch (parts[1])
            {
            case "Verb":
                Verb.Add(word);
                word.WordClass = WordClass.Verb;
                break;

            case "Adjective":
                Adjective.Add(word);
                word.WordClass = WordClass.Adjective;
                break;

            case "Noun":
                Noun.Add(word);
                word.WordClass = WordClass.Noun;
                break;
            }
        }
        set = true;
    }
예제 #20
0
        public async Task <IHttpActionResult <string> > Import([FromBody] DataDto data)
        {
            try
            {
                int importedAdj  = 0;
                int importedNoun = 0;
                foreach (AdjectiveReadDto adjDto in data.Adjectives)
                {
                    Adjective adj = new Adjective {
                        Value = adjDto.Value, CreationDate = DateTime.Now, ModificationDate = DateTime.Now
                    };
                    await _adjService.CreateAsync(adj);

                    importedAdj++;
                }

                foreach (NounReadDto nounDto in data.Nouns)
                {
                    Noun noun = new Noun {
                        Value = nounDto.Value, CreationDate = DateTime.Now, ModificationDate = DateTime.Now
                    };
                    await _nounService.CreateAsync(noun);

                    importedNoun++;
                }
                return(Ok <string>("Imported " + importedAdj + " adjective(s) and " + importedNoun + " noun(s)."));
            }
            catch
            {
                return(InternalServerError <string>("Could not import."));
            }
        }
예제 #21
0
        /// Called when this Actor has been killed by [attackNoun].
        public override void OnDied(Noun attackNoun)
        {
            // Try to keep dropped items from overlapping.
            var flow = new Flow(Game.CurrentStage, Position, null, false, true);

            Func <VectorBase, bool> predicateNearestWhere = delegate(VectorBase position)
            {
                if (Rng.Instance.OneIn(5))
                {
                    return(true);
                }
                return(Game.CurrentStage.ItemAt(position) == null);
            };

            // A "Delefate" with no return type
            Action <Item> myBreedDrop = delegate(Item item)
            {
                var itemPos = Position;
                if (Game.CurrentStage.ItemAt(Position) != null)
                {
                    itemPos = flow.NearestWhere(predicateNearestWhere);
                }

                item.Position = itemPos;
                Game.CurrentStage.Items.Add(item);
                Log("{1} drop[s] {2}.", this, item);
            };

            Breed.Drop.SpawnDrop(new AddItem(myBreedDrop));

            Game.CurrentStage.removeActor(this);
            Debugger.Instance.removeMonster(this);
        }
예제 #22
0
        public void NounSetProcessNounSet()
        {
            Assert.AreEqual(this.SentenceGraph.Vertices.Count(), 1);
            Assert.AreEqual(this.SentenceGraph.Edges.Count(), 1);
            var noun    = new Noun(2, "noun2", "_", this.EdgeFactory, this.ElementFactory, this.ImageManager, WIDTH, HEIGHT);
            var nounSet = new NounSet(this.ElementFactory, this.EdgeFactory, this.SentenceGraph, noun);

            this.Noun.Process(nounSet, this.SentenceGraph);

            Assert.AreEqual(this.SentenceGraph.Vertices.Count(), 6);
            Assert.AreEqual(this.SentenceGraph.Edges.Count(), 7);
            Assert.AreEqual(this.SentenceGraph.Vertices.ToList()[1], nounSet);
            Assert.AreEqual(this.SentenceGraph[this.Noun].ToList()[0].Right, nounSet);

            this.SentenceGraph = new SentenceGraph();
            Assert.AreEqual(this.SentenceGraph.Vertices.Count(), 0);
            Assert.AreEqual(this.SentenceGraph.Edges.Count(), 0);
            nounSet = new NounSet(this.ElementFactory, this.EdgeFactory, this.SentenceGraph, noun)
            {
                DependencyType = "nsubj"
            };
            noun.Image = null;

            this.Noun.Process(nounSet, this.SentenceGraph);
            Assert.AreEqual(this.SentenceGraph.Vertices.Count(), 5);
            Assert.AreEqual(this.SentenceGraph.Edges.Count(), 6);
            Assert.AreEqual(this.SentenceGraph.Vertices.ToList()[0], nounSet);
            Assert.AreEqual(this.SentenceGraph[nounSet].ToList().Find(e => e.Right == this.Noun).Right, this.Noun);
        }
예제 #23
0
        private void InspectInsideContainer(Noun target, Noun container)
        {
            // Check to see if there is an item
            var containerItem = _parserService.GetItemFromCurrentLocation(container);

            if (containerItem != null)
            {
                if (!containerItem.IsContainer)
                {
                    ItemStrings.ITEM_NOT_CONTAINER.OutputResponse(container);
                    return;
                }

                var targetItem = _parserService.GetItemFromContainer(target, container);

                if (!containerItem.HasItem(targetItem))
                {
                    ItemStrings.ITEM_NOT_IN_CONTAINER.OutputResponse(target, containerItem);
                    return;
                }

                this.Command.InspectItemInContainer(targetItem, containerItem);
                return;
            }

            ItemStrings.ITEM_DOES_NOT_EXIST.OutputResponse(container);
        }
예제 #24
0
		public OfSomething(Noun noun)
			: base(noun.Text, noun.Sex, noun.IsCreature)
		{
			Adjective = noun.Adjective;
			CoName = noun.CoName;
			AlsoKnownAs = noun.AlsoKnownAs;
		}
예제 #25
0
        private void Add(Noun _noun)
        {
            if (_noun == this)
            {
                return;
            }

            if (AlsoKnownAs != null)
            {
                AlsoKnownAs.Add(_noun);
            }
            else
            {
                AlsoKnownAs = _noun;
                if (_noun.Adjective == null)
                {
                    _noun.Adjective = Adjective;
                }
                if (_noun.Immutable == null)
                {
                    _noun.Immutable = Immutable;
                }
                if (_noun.OfSomething == null)
                {
                    _noun.OfSomething = OfSomething;
                }
            }
        }
        /// <summary>
        /// Saves a 'Noun' object into the database.
        /// This method calls the 'Insert' or 'Update' method.
        /// </summary>
        /// <param name='noun'>The 'Noun' object to save.</param>
        /// <returns>True if successful or false if not.</returns>
        public bool Save(ref Noun noun)
        {
            // Initial value
            bool saved = false;

            // If the noun exists.
            if (noun != null)
            {
                // Is this a new Noun
                if (noun.IsNew)
                {
                    // Insert new Noun
                    int newIdentity = this.Insert(noun);

                    // if insert was successful
                    if (newIdentity > 0)
                    {
                        // Update Identity
                        noun.UpdateIdentity(newIdentity);

                        // Set return value
                        saved = true;
                    }
                }
                else
                {
                    // Update Noun
                    saved = this.Update(noun);
                }
            }

            // return value
            return(saved);
        }
예제 #27
0
        public void VerbFinalize()
        {
            var noun = new Noun(0, "noun", "_", this.EdgeFactory, this.ElementFactory, this.ImageManager, WIDTH, HEIGHT);

            this.Verb.Process(noun, this.SentenceGraph);
            var elem = this.Verb.FinalizeProcessing(this.SentenceGraph);

            Assert.IsInstanceOfType(elem, typeof(Noun));
            Assert.AreEqual(noun.Actions.Count, 1);
            Assert.AreEqual(noun.Actions[0], this.Verb);
            noun.Actions.Clear();
            this.Verb.DependingDrawables.Clear();

            noun.DependencyType = "dobj";
            this.Verb.Process(noun, this.SentenceGraph);
            elem = this.Verb.FinalizeProcessing(this.SentenceGraph);
            Assert.IsInstanceOfType(elem, typeof(Noun));
            Assert.AreEqual(noun.Actions.Count, 1);
            Assert.AreEqual(noun.Actions[0], this.Verb);
            noun.Actions.Clear();
            this.Verb.Object = null;

            elem = this.Verb.FinalizeProcessing(this.SentenceGraph);
            Assert.IsInstanceOfType(elem, typeof(Verb));
            Assert.AreEqual(elem, this.Verb);
        }
예제 #28
0
        /// <summary>
        /// This method creates the sql Parameters[] needed for
        /// inserting a new noun.
        /// </summary>
        /// <param name="noun">The 'Noun' to insert.</param>
        /// <returns></returns>
        internal static SqlParameter[] CreateInsertParameters(Noun noun)
        {
            // Initial Values
            SqlParameter[] parameters = new SqlParameter[2];
            SqlParameter   param      = null;

            // verify nounexists
            if (noun != null)
            {
                // Create [Syllables] parameter
                param = new SqlParameter("@Syllables", noun.Syllables);

                // set parameters[0]
                parameters[0] = param;

                // Create [WordText] parameter
                param = new SqlParameter("@WordText", noun.WordText);

                // set parameters[1]
                parameters[1] = param;
            }

            // return value
            return(parameters);
        }
예제 #29
0
        public void ProperNameTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("a cat is a kind of person",
                            "a persian is a kind of cat",
                            "a tabby is a kind of cat",
                            "a siamese is a kind of cat",
                            "a cat can be haughty",
                            "a cat can be cuddly",
                            "a cat can be crazy",
                            "a persian can be matted",
                            "thaumaturgy is a form of magic",
                            "necromancy is a form of magic",
                            "a magic user must practice one form of magic");
            var cat         = (CommonNoun)Noun.Find("cat");
            var magicUser   = (CommonNoun)Noun.Find("magic", "user");
            var thaumaturgy = Individual.AllPermanentIndividuals["thaumaturgy"];
            var necromancy  = Individual.AllPermanentIndividuals["necromancy"];
            var g           = new Generator(cat, magicUser);

            for (var n = 0; n < 100; n++)
            {
                var i = g.Solve();
                Assert.IsTrue(i.Holds("practices", i.Individuals[0], thaumaturgy) ||
                              i.Holds("practices", i.Individuals[0], necromancy));
                Console.WriteLine(i.Model.Model);
                Console.WriteLine(i.Description(i.Individuals[0]));
            }
        }
예제 #30
0
        /// <summary>
        /// This method creates the sql Parameters[] needed for
        /// update an existing noun.
        /// </summary>
        /// <param name="noun">The 'Noun' to update.</param>
        /// <returns></returns>
        internal static SqlParameter[] CreateUpdateParameters(Noun noun)
        {
            // Initial Values
            SqlParameter[] parameters = new SqlParameter[3];
            SqlParameter   param      = null;

            // verify nounexists
            if (noun != null)
            {
                // Create parameter for [Syllables]
                param = new SqlParameter("@Syllables", noun.Syllables);

                // set parameters[0]
                parameters[0] = param;

                // Create parameter for [WordText]
                param = new SqlParameter("@WordText", noun.WordText);

                // set parameters[1]
                parameters[1] = param;

                // Create parameter for [Id]
                param         = new SqlParameter("@Id", noun.Id);
                parameters[2] = param;
            }

            // return value
            return(parameters);
        }
예제 #31
0
        public void  CompoundNounTest()
        {
            Ontology.EraseConcepts();
            ParseAndExecute("a cat is a kind of person",
                            "a persian is a kind of cat",
                            "a tabby is a kind of cat",
                            "a siamese is a kind of cat",
                            "a cat can be haughty",
                            "a cat can be cuddly",
                            "a cat can be crazy",
                            "a persian can be matted",
                            "thaumaturge and necromancer are kinds of magic user");
            var cat       = (CommonNoun)Noun.Find("cat");
            var magicUser = (CommonNoun)Noun.Find("magic", "user");
            var g         = new Generator(cat, magicUser);

            for (var n = 0; n < 100; n++)
            {
                var i = g.Solve();
                Assert.IsTrue(i.IsA(i.Individuals[0], cat));
                Assert.IsTrue(i.IsA(i.Individuals[0], "persian") ||
                              i.IsA(i.Individuals[0], "tabby") ||
                              i.IsA(i.Individuals[0], "siamese"));
                Console.WriteLine(i.Model.Model);
                Console.WriteLine(i.Description(i.Individuals[0]));
            }
        }
예제 #32
0
 public static NounReadDto ToNounReadDto(this Noun noun)
 {
     return(new NounReadDto
     {
         Value = noun.Value
     });
 }
예제 #33
0
 public bool HasItem(Noun noun)
 {
     foreach (var n in items) {
         if (n == noun)
             return true;
     }
     return false;
 }
예제 #34
0
        public static string GetForm(Noun noun, InflectionCase aCase, DecliantionNumber amount)
        {
            WordToken token = new WordToken(null, aCase, amount);
            foreach (WordToken tok in noun.Irregulars)
                if (tok.Is(token))
                    return tok.Text;

            return null;
        }
예제 #35
0
        public static void UpdateIrregular(Noun noun, WordToken aToken)
        {
            // find and update existing one
            foreach (WordToken token in noun.Irregulars)
                if (token.DecliantionNumber == aToken.DecliantionNumber &&
                    token.InflectionCase == aToken.InflectionCase)
                {
                    token.Text = aToken.Text;
                    return;
                }

            // not found - add new
            noun.Irregulars.Add(aToken);
        }
예제 #36
0
        public static int GetPostFixIndex(Noun noun, DecliantionNumber amount, InflectionCase aCase)
        {
            switch (amount)
            {
                case DecliantionNumber.Plural:
                {
                    if (noun.PluralPostfixSelector.ContainsKey(aCase))
                        return noun.PluralPostfixSelector[aCase];
                    break;
                }

                case DecliantionNumber.Singular:
                {
                    if (noun.SingularPostfixSelector.ContainsKey(aCase))
                        return noun.SingularPostfixSelector[aCase];
                    break;
                }
            }

            return 0;
        }
예제 #37
0
        public static void SetPostIndex(Noun noun, InflectionCase aCase, DecliantionNumber amount, int postFixIndex)
        {
            switch (amount)
            {
                case DecliantionNumber.Plural:
                {
                    if (postFixIndex > 0)
                    {
                        if (noun.PluralPostfixSelector.ContainsKey(aCase))
                            noun.PluralPostfixSelector[aCase] = postFixIndex;
                        else
                            noun.PluralPostfixSelector.Add(aCase, postFixIndex);
                    }
                    else if (noun.PluralPostfixSelector.ContainsKey(aCase))
                        noun.PluralPostfixSelector.Remove(aCase);

                    break;
                }

                case DecliantionNumber.Singular:
                {
                    if (postFixIndex > 0)
                    {
                        if (noun.SingularPostfixSelector.ContainsKey(aCase))
                            noun.SingularPostfixSelector[aCase] = postFixIndex;
                        else
                            noun.SingularPostfixSelector.Add(aCase, postFixIndex);
                    }
                    else if (noun.SingularPostfixSelector.ContainsKey(aCase))
                        noun.SingularPostfixSelector.Remove(aCase);

                    break;
                }
            }

        }
예제 #38
0
        public string MakeWord(Noun word, InflectionCase aCase, DecliantionNumber amount)
        {
            if (aCase == InflectionCase._Unknown || amount == DecliantionNumber._Unknown)
                return null;

            if ((amount == DecliantionNumber.Singular && !word.CanBeSingular) ||
                (amount == DecliantionNumber.Plural && !word.CanBePlural))
                return null;

            if (word.IsConstant)
                return word.Root;

            if (word.IsException)
            {
                string except = NounGrammar.GetForm(word, aCase, amount);
                if (except != null)
                    return except; // else - calculate own...
            }

            string prefix = "";
            string postfix = "";
            string root = ((aCase != InflectionCase.Nominative || amount != DecliantionNumber.Singular) &&
                !string.IsNullOrEmpty(word.RootOther))
                ? word.RootOther : word.Root;

            #region Switching

            postfix = SelectPostfix(word, aCase, amount, root);
            if (postfix == "*")
                postfix = "";

#if SW
            switch (word.Genre)
            {
            #region MasculineLife
                
                case GrammaticalGender.MasculineLife:
                    {                       
                        switch (aCase)
                        {
                            case InflectionCase.Nominative: // Mianownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Genitive: //Dopełniacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Dative: // Celownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Accusative: // Biernik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Ablative: // Narzędnik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Locative: // Miejscownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Vocative: //Wołacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }

                        break;
                    }

                #endregion

            #region MasculinePerson

                case GrammaticalGender.MasculinePerson:
                    {
                        switch (aCase)
                        {
                            case InflectionCase.Nominative: // Mianownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Genitive: //Dopełniacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Dative: // Celownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Accusative: // Biernik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Ablative: // Narzędnik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Locative: // Miejscownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Vocative: //Wołacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }
                        break;
                    }

                #endregion

            #region MasculineThing

                case GrammaticalGender.MasculineThing:
                    {
                        switch (aCase)
                        {
                            case InflectionCase.Nominative: // Mianownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break; // Nothing
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                root = Soften(word, root);
                                                postfix = "y";
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Genitive: //Dopełniacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                root = Soften(word, root);
                                                //postfix = SelectPostfix(word, root, "a", "u");
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                root = Soften(word, root);
                                                //postfix = SelectPostfix(word, root, "y", "ów");
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Dative: // Celownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Accusative: // Biernik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Ablative: // Narzędnik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Locative: // Miejscownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Vocative: //Wołacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }
                        break;
                    }

                #endregion

            #region Feminine

                case GrammaticalGender.Feminine:
                    {
                        switch (aCase)
                        {
                            case InflectionCase.Nominative: // Mianownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Genitive: //Dopełniacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Dative: // Celownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Accusative: // Biernik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Ablative: // Narzędnik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Locative: // Miejscownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Vocative: //Wołacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }
                        break;
                    }

                #endregion

            #region Neuter

                case GrammaticalGender.Neuter:
                    {
                        switch (aCase)
                        {
                            case InflectionCase.Nominative: // Mianownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Genitive: //Dopełniacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Dative: // Celownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Accusative: // Biernik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Ablative: // Narzędnik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Locative: // Miejscownik
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                            case InflectionCase.Vocative: //Wołacz
                                {
                                    switch (amount)
                                    {
                                        case DecliantionNumber.Singular:
                                            {
                                                break;
                                            }
                                        case DecliantionNumber.Plural:
                                            {
                                                break;
                                            }
                                    }
                                    break;
                                }
                        }
                        break;
                    }

                #endregion

            }
#endif

            #endregion

            return string.Format("{0}{1}{2}", prefix, root, postfix);
        }
예제 #39
0
 private string Soften(Noun word, string root)
 {
     return root;
 }
예제 #40
0
        private string SelectPostfix(Noun word, InflectionCase aCase, DecliantionNumber amount,
    string root, params string[] postfixes)
        {
            foreach (NounPostfixToken token in this.endings)
            {
                if (token.Declination == word.DeclinationType &&
                    token.Genre == word.Genre && token.DecliantionNumber == amount
                    && token.InflectionCase == aCase)
                {
                    if (token.Postfixes.Length > 1)
                    {
                        int indx = NounGrammar.GetPostFixIndex(word, amount, aCase);

                        if (indx < token.Postfixes.Length)
                            return token.Postfixes[indx];
                        else
                            return "";
                    }
                    else
                    {
                        return token.Postfixes[0];
                    }
                }
            }

            return "";           //postfixes[0];
        }
예제 #41
0
 private void dgvData_CellValuePushed(object sender, DataGridViewCellValueEventArgs e)
 {
     if(!updateDatabase) {
         return;
     }
     dbHasChanges = true;
     if(e.RowIndex >= nounRepo.Count) {
         Noun l = new Noun();
         SetLemmaColumnValue(l, e.ColumnIndex, e.Value);
         nounRepo.Add(l);
     } else {
         Noun l = memoryCache.RetrieveElement(e.RowIndex);
         SetLemmaColumnValue(l, e.ColumnIndex, e.Value);
         nounRepo.Update(l);
     }
     dbHasChanges = true;
 }
 public string MakeWord(Adjective word, Noun noun, InflectionCase aCase, DecliantionNumber amount,
     AdjectiveLevel level)
 {
     return MakeWord(word, (noun.HasIrregularGenre) ? noun.IrregularGenre : noun.Genre,
         aCase, amount, level);
 }
예제 #43
0
        /// <summary>
        /// Helper method that adds the current noun to a list. Follows the following rules:
        /// 1. If gender length is 0: doesn't add, since not a useful word
        /// 2. If the word length is 0: take the same word as last time. Reasoning behind this: words with double gender are present as WORD {m} {f}
        /// 3. All values get trimmed
        /// </summary>
        /// <param name="word"></param>
        /// <param name="gender"></param>
        /// <param name="list"></param>
        private void AddNoun(StringBuilder word, StringBuilder gender, List<Lemma> list)
        {
            if (gender.Length > 0)
            {
                Noun item = new Noun();
                item.Gender = NounGenderConvert.ToGender(ToTrimmedString(gender));
                item.Word = ToTrimmedString(word);
                if (item.Word.Length == 0)
                {
                    // take same word as last time
                    if (list.Count > 0)
                    {
                        item.Word = list.Last().Word;
                    }
                    else
                    {
                        return;
                    }
                }
                list.Add(item);
            }

            sbType.Clear();
            sbWord.Clear();
        }
예제 #44
0
 public void Add(Noun noun)
 {
     items.Add (noun);
 }
예제 #45
0
 private void SetLemmaColumnValue(Noun l, int columnIndex, object value)
 {
     switch(columnIndex) {
         case 1: l.Word = Convert.ToString(value); break;
         case 2: l.Gender = (Noun.NounGender)value; break;
         default: throw new ArgumentException(string.Format("Cannot set column {0} to value {1}", columnIndex, value));
     }
 }
예제 #46
0
 public void Remove(Noun noun)
 {
     items.Remove (noun);
 }