public void testTransitiveComplement_UpperTriangleRelation() { var relation = new Dictionary <int, ISet <int> > (); // 0 > 1, 1 > 2, 2 > 3, 3 > 4 for (int i = 0; i < 4; ++i) { relation.Add(i, new HashSet <int> { i + 1 }); } relation.Add(4, new HashSet <int> ()); GrammarUtils <StringSymbol> .ComputeTransitiveComplement(relation); Assert.AreEqual(5, relation.Keys.Count); for (int i = 0; i < 5; ++i) { var s = new HashSet <int> (); for (int j = i + 1; j < 5; ++j) { s.Add(j); } Assert.IsTrue(relation [i].SetEquals(s)); } }
public void testTransitiveComplement_MixedRelation() { var relation = new Dictionary <int, ISet <int> > (); relation.Add(0, new HashSet <int> { 1, 3, 4 }); relation.Add(1, new HashSet <int> ()); relation.Add(2, new HashSet <int> { 0 }); relation.Add(3, new HashSet <int> ()); relation.Add(4, new HashSet <int> { 2 }); GrammarUtils <StringSymbol> .ComputeTransitiveComplement(relation); Assert.AreEqual(5, relation.Keys.Count); Assert.IsTrue(relation [0].SetEquals(new HashSet <int> { 0, 1, 2, 3, 4 })); Assert.IsTrue(relation [1].SetEquals(new HashSet <int> ())); Assert.IsTrue(relation [2].SetEquals(new HashSet <int> { 0, 1, 2, 3, 4 })); Assert.IsTrue(relation [3].SetEquals(new HashSet <int> ())); Assert.IsTrue(relation [4].SetEquals(new HashSet <int> { 0, 1, 2, 3, 4 })); }
public void testTransitiveComplement_3ClassesRelation() { var relation = new Dictionary <int, ISet <int> > (); // first class { 0, 1 } relation.Add(0, new HashSet <int> { 1 }); relation.Add(1, new HashSet <int> { 0 }); // second class { 2, 3, 4, 5 } relation.Add(2, new HashSet <int> { 5 }); relation.Add(3, new HashSet <int> { 4 }); relation.Add(4, new HashSet <int> { 2 }); relation.Add(5, new HashSet <int> { 3 }); // third class { 6 } relation.Add(6, new HashSet <int> { 6 }); GrammarUtils <StringSymbol> .ComputeTransitiveComplement(relation); Assert.AreEqual(7, relation.Keys.Count); Assert.IsTrue(relation [0].SetEquals(new HashSet <int> { 0, 1 })); Assert.IsTrue(relation [1].SetEquals(new HashSet <int> { 0, 1 })); Assert.IsTrue(relation [2].SetEquals(new HashSet <int> { 2, 3, 4, 5 })); Assert.IsTrue(relation [3].SetEquals(new HashSet <int> { 2, 3, 4, 5 })); Assert.IsTrue(relation [4].SetEquals(new HashSet <int> { 2, 3, 4, 5 })); Assert.IsTrue(relation [5].SetEquals(new HashSet <int> { 2, 3, 4, 5 })); Assert.IsTrue(relation [6].SetEquals(new HashSet <int> { 6 })); }
public void testNullable() { var computedNullable = GrammarUtils <StringSymbol> .ComputeNullable(automatons); foreach (var symbol in computedNullable) { Console.Write(((StringSymbol)symbol).S); } Assert.IsTrue(nullable.SetEquals(computedNullable)); }
public void testFollow() { var computedFollow = GrammarUtils <StringSymbol> .ComputeFollow(automatons, nullable, firstSet); Assert.AreEqual(follow.Keys.Count, computedFollow.Keys.Count); foreach (var key in follow.Keys) { Assert.IsTrue(computedFollow.ContainsKey(key)); var set1 = follow [key]; var set2 = computedFollow [key]; Assert.IsTrue(set1.SetEquals(set2)); } }
public void testFirst() { var computedFirst = GrammarUtils <StringSymbol> .ComputeFirst(automatons, nullable); //Assert.AreEqual (first.Keys.Count, computedFirst.Keys.Count); foreach (var key in first.Keys) { //Assert.IsTrue (computedFirst.ContainsKey (key)); var set1 = first [key]; var set2 = computedFirst [key]; Assert.IsTrue(set1.SetEquals(set2)); } }
public void testTransitiveComplement_EmptyRelation() { var relation = new Dictionary <int, ISet <int> > (); for (int i = 0; i < 5; ++i) { relation.Add(i, new HashSet <int> ()); } GrammarUtils <StringSymbol> .ComputeTransitiveComplement(relation); Assert.AreEqual(5, relation.Keys.Count); for (int i = 0; i < 5; ++i) { Assert.IsTrue(relation [i].SetEquals(new HashSet <int> ())); } }
public void LoadMechanicGraph(int inputSeed = -1) { List <NodeGrammar> grammars = new List <NodeGrammar>(); foreach (var grammar in _nodeGrammars) { grammars.AddRange(NodeGrammar.ImportGrammars(Application.streamingAssetsPath + "/Grammar/Node/" + grammar + ".json")); } // generate a simple left hand side for now var inputGraph = new NodeGraph(); inputGraph.AddNode(new Node() { Node_text = "S" }); var seed = _randomString ? UnityEngine.Random.Range(0, 1000) : _seed; if (inputSeed != -1) { seed = inputSeed; } var stringgrams = GrammarUtils.ImportGrammars(Application.streamingAssetsPath + "/Grammar/String/" + _stringGrammar + ".json"); var inputString = GrammarUtils.ApplyGrammars(ref stringgrams, _inputString, seed); Debug.Log("mechanic generated with input string " + inputString); Debug.Log("Seed: " + seed); FindObjectOfType <SeedDisplay>()?.DisplaySeed(seed); _mechanicGraph = GrammarUtils.ApplyNodeGrammars(inputString, ref grammars, inputGraph, seed); AnalyseMechanicNodes(); AdjustBalance(); AnalyseMechanicNodes(); ApplySignifiers(); NodeBehaviour.Callbacks = new Stack <NodeActivationCallBack>(); NodeBehaviour.PlayerAttacks = GetComponent <PlayerAttackControl>(); NodeBehaviour.PlayerMovement = GetComponent <PlayerMovement>(); }
public void testTransitiveComplement_FullRelation() { var relation = new Dictionary <int, ISet <int> > (); // 0 > 1, 1 > 2, 2 > 3, 3 > 4, 4 > 0 for (int i = 0; i < 5; ++i) { relation.Add(i, new HashSet <int> { (i + 1) % 5 }); } GrammarUtils <StringSymbol> .ComputeTransitiveComplement(relation); Assert.AreEqual(5, relation.Keys.Count); var s = new HashSet <int> { 0, 1, 2, 3, 4 }; for (int i = 0; i < 5; ++i) { Assert.IsTrue(relation [i].SetEquals(s)); } }
/// <summary> /// Count all the words (Nouns only) from the subjects and rank them /// (case-sensitive) /// Must have WordNet installed and configured in Config.ini /// </summary> /// <param name="wordnet_path"></param> /// <param name="noCommon100"></param> /// <returns></returns> public OrderedList GetPopularSubjectNouns(String wordnet_path, bool noCommon100) { OrderedList MyOrderedList = new OrderedList(); if (Directory.Exists(wordnet_path)) { Wnlib.WNCommon.path = wordnet_path; if (GrammarUtils.AdjDataList.Count == 0) { GrammarUtils.LoadDataFiles(); } List <string> wordList = new List <string>(); OrderedDictionary od = new OrderedDictionary(); System.Collections.SortedList sl = new System.Collections.SortedList(); //IsANoun CHECK foreach (String subjectline in this.GetAllSubjects()) { foreach (string subjword in subjectline.Split(' ')) { if (GrammarUtils.IsNoun(subjword)) { if (noCommon100) { //no common 100 words if (!GrammarUtils.CommonWords100.Contains(subjword)) { wordList.Add(subjword); } } else { wordList.Add(subjword); //noCommon100 = false } } } } foreach (String word in wordList) { if (od.Contains(word)) { MyOrderedList.Add(new KeyValuePair <string, int>(word, Convert.ToInt16(od[word]) + 1)); //This word is already in dictionary, increase count value od[word] = Convert.ToInt16(od[word]) + 1; } else { //first time word MyOrderedList.Add(new KeyValuePair <string, int>(word, 1)); od[word] = 1; } } MyOrderedList.Sort(false); } else { //no WordNet path Exception ex = new Exception("Bad WordNet Path: " + wordnet_path); File.AppendAllText(Common.gLogFile, DateTime.Now.ToString() + ", " + ex.Message + "\r\n");//Log it! Console.WriteLine(ex.Message); } return(MyOrderedList); }
public void hasLeftRecursionOnNullableEdgesTest() { Assert.IsNotNull(GrammarUtils <StringSymbol> .HasLeftRecursion(automatons_lr_nullable, nullable_lr_nullable)); }
public void hasLeftRecursionHasRecursionTest() { Assert.IsNotNull(GrammarUtils <StringSymbol> .HasLeftRecursion(automatons_lr, nullable_lr)); }
public void hasLeftRecursionNoRecursionTest() { Assert.IsNull(GrammarUtils <StringSymbol> .HasLeftRecursion(automatons, nullable)); }