public void Emoji() { var table = RantDictionaryTable.FromStream("emoji.table", File.Open("Tables/emoji.table", FileMode.Open)); Assert.AreEqual("emoji", table.Name); Assert.AreEqual(1, table.TermsPerEntry); }
private static void Pack(RantPackage package, string contentPath) { foreach (var path in Directory.EnumerateFiles(contentPath, "*.*", SearchOption.AllDirectories) .Where(p => p.EndsWith(".rant", StringComparison.OrdinalIgnoreCase) || p.EndsWith(".rants", StringComparison.OrdinalIgnoreCase) || p.EndsWith(".rantpgm", StringComparison.OrdinalIgnoreCase))) { RantProgram pattern; switch (Path.GetExtension(path).ToLower()) { case ".rantpgm": pattern = RantProgram.LoadFile(path); break; default: pattern = RantProgram.CompileFile(path); break; } string relativePath; TryGetRelativePath(contentPath, path, out relativePath, true); pattern.Name = relativePath; package.AddResource(pattern); Console.WriteLine("+ " + pattern.Name); } foreach (string path in Directory.GetFiles(contentPath, "*.table", SearchOption.AllDirectories)) { Console.WriteLine("+ " + path); var table = RantDictionaryTable.FromStream(Path.GetFileNameWithoutExtension(path), File.Open(path, FileMode.Open)); package.AddResource(table); } }
public void VerbTableWithPhrasals() { var table = RantDictionaryTable.FromStream("verbs.table", File.Open("Tables/verbs.table", FileMode.Open)); Assert.AreEqual("verb", table.Name); Assert.AreEqual(8, table.TermsPerEntry); }
public void SimpleNounTable() { var table = RantDictionaryTable.FromStream("nouns.table", File.Open("Tables/nouns.table", FileMode.Open)); Assert.AreEqual("noun", table.Name); Assert.AreEqual(2, table.TermsPerEntry); Assert.AreEqual(0, table.GetSubtypeIndex("singular")); Assert.AreEqual(0, table.GetSubtypeIndex("singular")); Assert.AreEqual(1, table.GetSubtypeIndex("plural")); Assert.AreEqual(1, table.GetSubtypeIndex("p")); Assert.AreEqual(-1, table.GetSubtypeIndex("nonexistent")); }
public static RantEngine StartEngine() { RantDictionary dictionary = new RantDictionary(); foreach (string fileName in fileNames) { string filePath = folderPath + fileName + ".table"; FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read); RantDictionaryTable table = RantDictionaryTable.FromStream(filePath, stream); dictionary.AddTable(table); stream.Close(); } return(new RantEngine(dictionary)); }
protected override void OnRun() { var cmdPaths = CmdLine.GetPaths(); var workingDir = cmdPaths.Length > 0 ? cmdPaths[0] : Environment.CurrentDirectory; var outputPath = CmdLine.Property("out", Path.Combine(workingDir, "dictionary.md")); var tables = Directory.GetFiles(workingDir, "*.table", SearchOption.AllDirectories) .Select(dir => RantDictionaryTable.FromStream(dir, File.Open(dir, FileMode.Open))) .OrderBy(table => table.Name) .ToList(); if (tables.Count == 0) { Console.WriteLine("No tables found."); return; } using (var writer = new StreamWriter(outputPath)) { foreach (var table in tables) { writer.WriteLine($"## {table.Name}"); writer.WriteLine($"**Entries:** {table.EntryCount}\n"); if (table.HiddenClasses.Any()) { writer.WriteLine($"**Hidden classes:** {table.HiddenClasses.Select(cl => $"`{cl}`").Aggregate((c, n) => $"{c}, {n}")}\n"); } // Write subtype list writer.WriteLine($"### Subtypes\n"); for (int i = 0; i < table.TermsPerEntry; i++) { writer.WriteLine($"{i + 1}. {table.GetSubtypesForIndex(i).Select(st => $"`{st}`").Aggregate((c, n) => $"{c}, {n}")}"); } writer.WriteLine(); // Write classes writer.WriteLine($"### Classes\n"); foreach (var cl in table.GetClasses().OrderBy(cl => cl)) { writer.WriteLine($"- `{cl}` ({table.GetEntries().Count(e => e.ContainsClass(cl))})"); } writer.WriteLine(); } } }
private static void Pack(RantPackage package, string contentPath) { foreach (string path in Directory.EnumerateFiles(contentPath, "*.*", SearchOption.AllDirectories) .Where(p => p.EndsWith(".rant") || p.EndsWith(".rants"))) { var pattern = RantProgram.CompileFile(path); string relativePath; TryGetRelativePath(contentPath, path, out relativePath, true); pattern.Name = relativePath; package.AddResource(pattern); Console.WriteLine("+ " + pattern.Name); } foreach (string path in Directory.GetFiles(contentPath, "*.table", SearchOption.AllDirectories)) { Console.WriteLine("+ " + path); var table = RantDictionaryTable.FromStream(Path.GetFileNameWithoutExtension(path), File.Open(path, FileMode.Open)); package.AddResource(table); } }
public void SaveLoadRun() { var package = new RantPackage { ID = "TestPackage", Description = "This is a test.", Title = "Test Package?!", Version = new RantPackageVersion(1, 1, 0) }; package.AddResource(RantDictionaryTable.FromStream("nouns", File.Open("Tables/nouns.table", FileMode.Open))); package.AddResource(RantProgram.CompileString("TestProgram", @"[case:title]<noun-food-fruit-yellow> [rs:5;,\s]{[rn]}")); package.Save("TestPackage.rantpkg"); package = RantPackage.Load("TestPackage.rantpkg"); rant.LoadPackage(package); Assert.AreEqual("Banana 1, 2, 3, 4, 5", rant.DoName("TestProgram").Main); Assert.AreEqual("TestPackage", package.ID); Assert.AreEqual("This is a test.", package.Description); Assert.AreEqual("Test Package?!", package.Title); Assert.AreEqual("1.1.0", package.Version.ToString()); }
public Queries() { rant.Dictionary.AddTable(RantDictionaryTable.FromStream("verbs", File.Open("Tables/verbs.table", FileMode.Open))); rant.Dictionary.AddTable(RantDictionaryTable.FromStream("nouns", File.Open("Tables/nouns.table", FileMode.Open))); rant.Dictionary.AddTable(RantDictionaryTable.FromStream("nsfw", File.Open("Tables/nsfw.table", FileMode.Open))); }