public void TestGenerateGrammar() { ProjectSerializationManager projectSerializationManager = new ProjectSerializationManager(); Project sampleProject = projectSerializationManager.LoadProject(@"..\..\..\Projects\Figure8.eXo"); PSMSchema psmSchema = sampleProject.SingleVersion.PSMSchemas[0]; GrammarGenerator grammarGenerator = new GrammarGenerator(); Exolutio.Model.PSM.Grammar.Grammar g = grammarGenerator.GenerateGrammar(psmSchema); System.Diagnostics.Debug.WriteLine("Not normalized grammar: "); foreach (ProductionRule productionRule in g.ProductionRules) { System.Diagnostics.Debug.WriteLine(productionRule.ToString()); } System.Diagnostics.Debug.WriteLine(string.Empty); Normalizer normalizer = new Normalizer(); normalizer.Controller = new Controller.Controller(sampleProject); normalizer.NormalizeSchema(psmSchema); g = grammarGenerator.GenerateGrammar(psmSchema); System.Diagnostics.Debug.WriteLine("Normalized grammar: "); foreach (ProductionRule productionRule in g.ProductionRules) { System.Diagnostics.Debug.WriteLine(productionRule.ToString()); } System.Diagnostics.Debug.WriteLine(string.Empty); }
private IEnumerator DestroyLevel() { yield return(new WaitForEndOfFrame()); CaveGenerator caveGen = FindObjectOfType <CaveGenerator>(); GrammarGenerator grammarGen = FindObjectOfType <GrammarGenerator>(); caveGen.ClearAll(); grammarGen.ClearAll(); }
public override void Execute(object parameter = null) { if (Current.ActiveDiagram != null && Current.ActiveDiagram is PSMDiagram) { GrammarGenerator generator = new GrammarGenerator(); Exolutio.Model.PSM.Grammar.Grammar grammar = generator.GenerateGrammar((PSMSchema)Current.ActiveDiagram.Schema); GrammarWindow w = new GrammarWindow(); w.DisplayedGrammar = grammar; w.ShowDialog(); } }
private IEnumerator PerformRegen() { yield return(new WaitForEndOfFrame()); CaveGenerator caveGen = FindObjectOfType <CaveGenerator>(); GrammarGenerator grammarGen = FindObjectOfType <GrammarGenerator>(); caveGen.Generate(); grammarGen.Generate(); earnedLevelLife = false; Respawn(); loadSplash.SetActive(false); gameState = GameState.PLAYING; regenQueued = false; }
public void UpdateGrammarInput() { if (CurrentSelection != null) { if (grammarInputDict.ContainsKey(CurrentSelection.gameObject.name)) { GrammarInput = grammarInputDict[CurrentSelection.gameObject.name]; } else { GrammarInput = ""; } GrammarGenerator.PopulateScript(GrammarInput); } }
public void DisplayScript() { GrammarGenerator.ClearScript(); foreach (var tgroup in toggleGroups) { tgroup.GetComponent <ToggleMenu>().UpdateGrammarInput(); } scriptDisplay.text = "initialise \n"; foreach (var elem in GrammarGenerator._GameScriptElements) { scriptDisplay.text += elem; scriptDisplay.text += "\n"; } scriptDisplay.text += "finalise"; SubmitScript(); }
void Update() { if (SceneManager.GetActiveScene().name != "Setup") { if (Input.GetKeyDown(KeyCode.Q)) { GrammarGenerator.ClearString(); GameObject.Find("LoadingText").GetComponent <Text>().text = "Quitting"; GameObject.Find("LoadingCam").GetComponent <Camera>().enabled = true; ScoreMgmt.ClearScores(); ScoreMgmt.ClearDeaths(); ScoreMgmt.ClearLevel(); SceneManager.LoadScene("Setup"); } } if (finishedPlayers == totalPlayers && totalPlayers != 0) { NextLevel(); } }
public ContinuousRandomTesting( int maxNonterminals, int maxTerminals, int maxProductions, int maxProductionLength, int maxInputLength, int numRandomSentences, int seed ) { _maxNonterminals = maxNonterminals; _maxTerminals = maxTerminals; _maxProductions = maxProductions; _maxProductionLength = maxProductionLength; _maxInputLength = maxInputLength; _numRandomSentences = numRandomSentences; _r = new Random(seed); _gramGen = new GrammarGenerator(_r); _parseErrorFile = new System.IO.StreamWriter(@"parseErrors.txt"); }
private static int WriteGrammarFile(string inputFile, string outputLocation) { try { var grammarText = GrammarGenerator.Run(ReadTree(inputFile).Types); var outputMainFile = Path.Combine(outputLocation.Trim('"'), $"CSharp.Generated.g4"); using var outFile = new StreamWriter(File.Open(outputMainFile, FileMode.Create), Encoding.UTF8); outFile.Write(grammarText); } catch (Exception ex) { Console.WriteLine("Generating grammar failed."); Console.WriteLine(ex); // purposefully fall out here and don't return an error code. We don't want to fail // the build in this case. Instead, we want to have the program fixed up if // necessary. } return(0); }
public void SubmitScript() { //GrammarGenerator.SetString("initialise " + GeneratePath(maxIterations) + " " + scriptDisplay.text.Replace("\n", " ")); GrammarGenerator.SetString("initialise " + scriptDisplay.text.Replace("\n", " ") + "finalise"); }
public static void Do() { // S -> aSa | bSb | ε var productions = new List <Production> { // construct productions by passing arguments... new Production( lhs: Nonterminal.Of("S"), rhs: new Sentence { Terminal.Of("a"), Nonterminal.Of("S"), Terminal.Of("a") }, weight: 20 ), // or from a string... CFGParser.Production(@"<S> -> 'b' <S> 'b' [10]"), CFGParser.Production(@"<S> -> ε [5]"), }; var cfg = new Grammar(productions, Nonterminal.Of("S")); // var cnf = cfg.ToCNF(); //var probs = cfg.EstimateProbabilities(1000000); //foreach (var entry in probs) { // var key = entry.Key; // var value = entry.Value; // if (key.Length <= 4) { // Console.WriteLine("{0}: {1}", key, value); // } //} // Print out the new CNF grammar // Console.WriteLine(cnf); var ep = new EarleyParser(cfg); // var cp = new CykParser(cnf); // Does this grammar accept the string "aabb"? Console.WriteLine("aabb: {0}", ep.ParseGetProbability(Sentence.FromLetters("aabb"))); // How about "abba"? Console.WriteLine("abba: {0}", ep.ParseGetProbability(Sentence.FromLetters("abba"))); Console.WriteLine(ep.ParseGetForest(Sentence.FromLetters("abba"))); for (int i = 0; i < 5; i++) { Console.WriteLine(cfg.ProduceRandom().AsTerminals()); } var sentences = cfg.ProduceToDepth(3); foreach (var sentence in sentences) { Console.WriteLine(sentence.Value.AsTerminals()); } var gg = new GrammarGenerator(1); var terminals = new List <Terminal> { Terminal.Of("a"), Terminal.Of("b") }; var randGram = gg.NextCFG( numNonterminals: 4, numProductions: 10, maxProductionLength: 4, terminals: terminals ); Console.WriteLine(randGram); }
// Token: 0x0600101C RID: 4124 RVA: 0x0005E0C8 File Offset: 0x0005C2C8 public override AssistantTaskContext InitialStep(AssistantTaskContext context) { Utilities.DebugTrace(DirectoryProcessorAssistant.Tracer, "Entering DirectoryProcessorAssistant.InitialStep", new object[0]); DirectoryProcessorMailboxData directoryProcessorMailboxData = context.MailboxData as DirectoryProcessorMailboxData; AssistantTaskContext result; try { Queue <TaskQueueItem> queue = new Queue <TaskQueueItem>(); RunData runData = this.CreateRunData(directoryProcessorMailboxData); GrammarGenerator.CleanUpOldGrammarRuns(runData, DirectoryProcessorAssistant.Tracer); UmGlobals.ExEvent.LogEvent(UMEventLogConstants.Tuple_DirectoryProcessorStarted, null, new object[] { runData.TenantId, runData.MailboxGuid, runData.RunId }); List <DirectoryProcessorBaseTask> generators = this.GetGenerators(runData); List <DirectoryProcessorBaseTask> list = this.FilterGenerators(generators, runData, RecipientType.User); List <DirectoryProcessorBaseTask> list2 = this.FilterGenerators(generators, runData, RecipientType.Group); if (list.Count > 0) { queue.Enqueue(new TaskQueueItem(ADCrawler.Create(runData, RecipientType.User), RecipientType.User)); } foreach (DirectoryProcessorBaseTask task in list) { queue.Enqueue(new TaskQueueItem(task, RecipientType.User)); } if (list2.Count > 0) { queue.Enqueue(new TaskQueueItem(ADCrawler.Create(runData, RecipientType.Group), RecipientType.Group)); } foreach (DirectoryProcessorBaseTask task2 in list2) { queue.Enqueue(new TaskQueueItem(task2, RecipientType.Group)); } DirectoryProcessorBaseTaskContext directoryProcessorBaseTaskContext = new DirectoryProcessorBaseTaskContext(context.MailboxData, context.Job, queue, new AssistantStep(this.DoTask), TaskStatus.NoError, runData, new List <DirectoryProcessorBaseTask>()); result = directoryProcessorBaseTaskContext; } catch (Exception ex) { string tenantIdentifiableDN = RunData.GetTenantIdentifiableDN(directoryProcessorMailboxData.OrgId); Utilities.ErrorTrace(DirectoryProcessorAssistant.Tracer, "DirectoryProcessorAssistant.InitialStep, Exception='{0}' for '{1}' in database '{2}'", new object[] { ex, tenantIdentifiableDN, directoryProcessorMailboxData.DatabaseGuid }); UmGlobals.ExEvent.LogEvent(UMEventLogConstants.Tuple_DirectoryProcessorInitialStepEncounteredException, null, new object[] { tenantIdentifiableDN, directoryProcessorMailboxData.DatabaseGuid, CommonUtil.ToEventLogString(ex) }); if (ex is IOException) { throw new SkipException(ex); } throw; } return(result); }
public void RandomParsingTest( int _numGrammars = 10000, int _numNonterminals = 10, int _numTerminals = 5, int _numProductions = 30, int _maxProductionLength = 8, int _maxInputLength = 6, int seed = 0 ) { var printStatus = true; var range = Enumerable.Range(0, _numTerminals); var terminals = new List <Terminal>(range.Select((x) => Terminal.Of("x" + x))); Console.WriteLine("Preparing sentences"); var preparedSentences = new List <Sentence>(); for (int length = 0; length <= _maxInputLength; length++) { var combinations = CFGLibTest.Helpers.CombinationsWithRepetition(terminals, length); foreach (var target in combinations) { var sentence = new Sentence(target); preparedSentences.Add(sentence); } } var randg = new GrammarGenerator(seed); var preparedGrammars = new List <Grammar>(_numGrammars); var preparedGrammarsCNF = new List <CNFGrammar>(_numGrammars); Console.WriteLine("Preparing grammars"); for (int i = 0; i < _numGrammars; i++) { Grammar g = null; while (g == null) { // g = randg.NextCNF(_numNonterminals, _numProductions, terminals); g = randg.NextCFG(_numNonterminals, _numProductions, _maxProductionLength, terminals, true); if (g.Productions.Count() == 0) { g = null; } } // Console.WriteLine("---------------{0}/{1}---------------", i.ToString("D5"), _numGrammars.ToString("D5")); // Console.WriteLine(g.ToCodeString()); var h = g.ToCNF(); //return; // Console.WriteLine(g); // g.PrintProbabilities(2, 3); preparedGrammars.Add(g); preparedGrammarsCNF.Add(h); } Console.WriteLine("starting"); var sw = Stopwatch.StartNew(); int count = 0; for (int grammarIndex = 0; grammarIndex < _numGrammars; grammarIndex++) { if (printStatus) { Console.WriteLine("---------------{0}/{1}---------------", grammarIndex.ToString("D5"), _numGrammars.ToString("D5")); } var g = preparedGrammars[grammarIndex]; var h = preparedGrammarsCNF[grammarIndex]; var earley = new EarleyParser(g); var cyk = new CykParser(h); // Console.WriteLine(g.ToCodeString()); // Console.Write("{0}, ", count); count++; var accepts = 0; foreach (var sentence in preparedSentences) { try { var p1 = earley.ParseGetProbability(sentence); var p2 = cyk.ParseGetProbability(sentence); if (!Helpers.IsNear(p2, p1)) { throw new Exception(); } var accepts1 = p1 > 0; var accepts2 = p2 > 0; if (accepts2) { accepts++; } } catch (Exception) { Report(g, sentence); throw; } } if (printStatus) { Console.WriteLine("Accepted {0} / {1}", accepts, preparedSentences.Count); } } sw.Stop(); Console.WriteLine(); Console.WriteLine("inner Elapsed: {0}s", sw.Elapsed.TotalMilliseconds / 1000.0); // Console.WriteLine("Per CYK: {0}ms", sw.Elapsed.TotalMilliseconds / (_numGrammars * preparedSentences.Count)); }