private BibtexFile convertParseNode(ParseNode node) { Nodes.BibtexFile parseFile = (Nodes.BibtexFile)node; BibtexFile bibtex = new BibtexFile(); foreach (Entry entry in parseFile.Entries) { if (entry.Type == "String") { bibtex.StringDefinitions.Add(entry.Tags.First().Key, entry.Tags.First().Value); } else { BibtexEntry bibtexEntry = new BibtexEntry { Key = entry.Key, Type = entry.Type }; entry.Tags.ToList().ForEach(x => bibtexEntry.Tags.Add(x.Key, x.Value)); bibtex.Entries.Add(bibtexEntry); } } return(bibtex); }
public void MultipleEntriesTest() { Tokenizer tokenizer = new Tokenizer(new ExpressionDictionary(), @"@book{ aaker:1912, author = {David A. Aaker}, title = {Multivariate statistics} } @book{ baker:1912, author = {David A. Baker}, title = {Multivariate statistics 2} }"); BibtexParser parser = new BibtexParser(tokenizer); BibtexFile file = parser.Parse(); Assert.AreEqual(2, file.Entries.Count); Assert.AreEqual("aaker:1912", file.Entries.First().Key); Assert.AreEqual("book", file.Entries.First().Type); Assert.AreEqual(2, file.Entries.First().Tags.Count); Assert.AreEqual("author", file.Entries.First().Tags.First().Key); Assert.AreEqual("David A. Aaker", file.Entries.First().Tags.First().Value); Assert.AreEqual("title", file.Entries.First().Tags.ToList()[1].Key); Assert.AreEqual("Multivariate statistics", file.Entries.First().Tags.ToList()[1].Value); Assert.AreEqual("baker:1912", file.Entries.ToList()[1].Key); Assert.AreEqual("book", file.Entries.ToList()[1].Type); Assert.AreEqual(2, file.Entries.ToList()[1].Tags.Count); Assert.AreEqual("author", file.Entries.ToList()[1].Tags.First().Key); Assert.AreEqual("David A. Baker", file.Entries.ToList()[1].Tags.First().Value); Assert.AreEqual("title", file.Entries.ToList()[1].Tags.ToList()[1].Key); Assert.AreEqual("Multivariate statistics 2", file.Entries.ToList()[1].Tags.ToList()[1].Value); }
public BibtexFile Parse() { ParseNode node = ParseInput(_tokenizer); BibtexFile fileObject = convertParseNode(node); return(fileObject); }
public void FuzzyMiningTestFileTest() { using (StreamReader reader = new StreamReader("Test Files\\Fuzzy Mining.bib")) { Tokenizer tokenizer = new Tokenizer(new ExpressionDictionary(), reader.ReadToEnd()); BibtexParser parser = new BibtexParser(tokenizer); BibtexFile file = parser.Parse(); Assert.AreEqual(3, file.Entries.Count); } }
public void BracesInValueTest() { Tokenizer tokenizer = new Tokenizer(new ExpressionDictionary(), @"@book{ aaker:1912, author = {David A. ()ker}, }"); BibtexParser parser = new BibtexParser(tokenizer); BibtexFile file = parser.Parse(); Assert.AreEqual(1, file.Entries.Count); Assert.AreEqual("aaker:1912", file.Entries.First().Key); Assert.AreEqual("book", file.Entries.First().Type); Assert.AreEqual(1, file.Entries.First().Tags.Count); Assert.AreEqual("author", file.Entries.First().Tags.First().Key); Assert.AreEqual("David A. ()ker", file.Entries.First().Tags.First().Value); }
public void SimpleParserWithDoubleQuoteTest() { Tokenizer tokenizer = new Tokenizer(new ExpressionDictionary(), @"@book{ aaker:1912, author = ""David A. Aaker"" }"); BibtexParser parser = new BibtexParser(tokenizer); BibtexFile file = parser.Parse(); Assert.AreEqual(1, file.Entries.Count); Assert.AreEqual("aaker:1912", file.Entries.First().Key); Assert.AreEqual("book", file.Entries.First().Type); Assert.AreEqual(1, file.Entries.First().Tags.Count); Assert.AreEqual("author", file.Entries.First().Tags.First().Key); Assert.AreEqual("David A. Aaker", file.Entries.First().Tags.First().Value); }
public void CommaInTagValueParseTest() { Tokenizer tokenizer = new Tokenizer(new ExpressionDictionary(), @"@book{ aaker:1912, author = {Günther, C.W. and Van Der Aalst, W.M.P.} }"); BibtexParser parser = new BibtexParser(tokenizer); BibtexFile file = parser.Parse(); Assert.AreEqual(1, file.Entries.Count); Assert.AreEqual("aaker:1912", file.Entries.First().Key); Assert.AreEqual("book", file.Entries.First().Type); Assert.AreEqual(1, file.Entries.First().Tags.Count); Assert.AreEqual("author", file.Entries.First().Tags.First().Key); Assert.AreEqual("Günther, C.W. and Van Der Aalst, W.M.P.", file.Entries.First().Tags.First().Value); }
public void ParseStringDefinitionsTest() { Tokenizer tokenizer = new Tokenizer(new ExpressionDictionary(), @" @String{pub-ACM = ""ACM Press""} @book{ aaker:1912, author = { tes(;)est } }"); BibtexParser parser = new BibtexParser(tokenizer); BibtexFile file = parser.Parse(); Assert.IsTrue(file.StringDefinitions.ContainsKey("pub-ACM")); Assert.AreEqual("ACM Press", file.StringDefinitions["pub-ACM"]); Assert.AreEqual(1, file.Entries.Count); Assert.AreEqual("aaker:1912", file.Entries.First().Key); Assert.AreEqual("book", file.Entries.First().Type); }
public static void Initialize(IServiceProvider serviceProvider) { using var context = new SEERContext( serviceProvider.GetRequiredService <DbContextOptions <SEERContext> >()); // Look for any bibliographic references. if (!context.BibliographicReference.Any()) { try { using StreamReader sr = new StreamReader("input.txt", Encoding.Default); BibtexFile file = BibtexImporter.FromString(sr.ReadToEnd().Replace("'", "", StringComparison.Ordinal)); foreach (BibtexEntry entry in file.Entries) { string?title = null, author = null, journal = null, doi = null; int? year = null; foreach (KeyValuePair <string, string> pair in entry.Tags) { string replaced = pair.Value.Replace("{", "", StringComparison.Ordinal).Replace("}", "", StringComparison.Ordinal).Replace("\\", "", StringComparison.Ordinal); switch (pair.Key) { case "title": title = replaced; break; case "author": author = replaced; break; case "journal": case "publisher": journal = replaced; break; case "doi": doi = replaced; break; case "year": year = int.Parse(replaced); break; default: Console.Error.WriteLine($"Unknown key {pair.Key} with value {pair.Value} in bibtex entry."); break; } } context.BibliographicReference.Add( new BibliographicReference { // TODO: Make these not show up on user side when unknown? Probably not able to do that here lol Title = title == null ? "Unknown" : title, Author = author == null ? "Unknown" : author, Source = journal == null ? "Unknown" : journal, DOI = doi == null ? "Unknown" : doi, Year = year.GetValueOrDefault() } ); } context.SaveChanges(); } catch (Exception ex) { // THROW THOSE STINKY EXCEPTIONS AWAY throw; } if (!context.AcceptedArticle.Any()) { try { context.AcceptedArticle.Add( new AcceptedArticle { Title = "Template", Author = "Template", Source = "Template", Year = 2020, DOI = "Template", SEMethod = "Template", Practice = "Template", Method = "Template", Participant = "Template", Result = "Template" }); context.SaveChanges(); } catch (Exception e) { throw; } } } }