public void LoadSpecialCharactersDatabase() { var data = File.ReadAllText(@"Sample Files\b4w.bib", Encoding.GetEncoding(1252)); var parser = new BibTexParser(new BibTexLexer(data)); specialCharactersDatabase = parser.Parse(); }
public static BibTexDatabase LoadBibTexDatabase(string filename) { LastTemplateParseException = null; try { var text = LoadFile(filename); var parser = new BibTexParser(new BibTexLexer(text)); var result = parser.Parse(); var fileInfo = new FileInfo(filename); result.Filename = fileInfo.FullName; result.Timestamp = fileInfo.LastWriteTime; return(result); } catch (Exception ex) { LastTemplateParseException = ex as TemplateParseException; Helper.LogUnexpectedException("Failed loading Bibtex database from '" + filename + "'", ex); return(null); } }
private void RefreshJavaScriptEditor() { List <BibTexItem> bibtex_items_list = BibTexParser.Parse(ObjBibTexEditor.Text).Items; Dictionary <string, CSLProcessorBibTeXFinder.MatchingBibTeXRecord> bitex_items = new Dictionary <string, CSLProcessorBibTeXFinder.MatchingBibTeXRecord>(); bibtex_items_list.ForEach(o => bitex_items[o.Key] = new CSLProcessorBibTeXFinder.MatchingBibTeXRecord { bibtex_item = o }); // Sample citation clusters List <CitationCluster> citation_clusters = new List <CitationCluster>(); bibtex_items_list.ForEach(o => citation_clusters.Add(new CitationCluster(new CitationItem(o.Key, "")))); CitationCluster mega_citation_cluster = new CitationCluster(); bibtex_items_list.ForEach(o => mega_citation_cluster.citation_items.Add(new CitationItem(o.Key, ""))); citation_clusters.Add(mega_citation_cluster); Dictionary <string, string> abbreviations = new Dictionary <string, string>(); string citation_uses = CSLProcessorTranslator_CitationClustersToJavaScript.Translate(citation_clusters); string citation_init = CSLProcessorTranslator_BibTeXToJavaScript.Translate_INIT(bitex_items); string citation_database = CSLProcessorTranslator_BibTeXToJavaScript.Translate_DATABASE(bitex_items, abbreviations); string final_text = "" + citation_uses + "\n" + citation_init + "\n" + citation_database ; ObjJavaScriptEditor.Text = final_text; }
internal static string Process(string source) { // If it is empty if (String.IsNullOrEmpty(source)) { return(source); } // See if it is valid BibTeX - if so, use it... try { List <BibTexItem> bibtexes = BibTexParser.Parse(source).Items; if (0 == bibtexes[0].Exceptions.Count) { return(source); } } catch (Exception ex) { ExceptionLog(ex, "BibTeX"); } // See if it is valid PubMed XML try { string bibtex; List <string> messages; if (PubMedXMLToBibTex.TryConvert(source, out bibtex, out messages)) { return(bibtex); } } catch (Exception ex) { ExceptionLog(ex, "PubMed"); } // See if it is valid EndNote try { List <EndNoteToBibTex.EndNoteRecord> endnotes = EndNoteToBibTex.Parse(source); if (endnotes.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (var endnote in endnotes) { sb.Append(endnote.ToBibTeX().ToBibTex()); sb.Append("\n\n"); } return(sb.ToString()); } } catch (Exception ex) { ExceptionLog(ex, "EndNote"); } // If we get here, we don't have a clue what is going on... return(source); }
public void TempParser() { var data = File.ReadAllText(@"Sample Files\Temp.bib"); var parser = new BibTexParser(new BibTexLexer(data)); var db = parser.Parse(); Console.WriteLine("{0} abbreviations; {1} entries", db.AbbreviationCount, db.EntryCount); }
protected BibTeXImporter(Library library, string filename) : base(library, filename) { string bibTex = File.ReadAllText(ExportFileName, System.Text.Encoding.UTF8); BibTexParseResult = BibTexParser.Parse(bibTex); BibTexParseResult.Items.ForEach(x => Entries.Add(new BibTeXEntry { Item = x, BibTeX = x.ToBibTex() })); }
public void Mendeley2Parser() { var data = File.ReadAllText(@"Sample Files\Mendeley 2.bib"); var parser = new BibTexParser(new BibTexLexer(data)); var db = parser.Parse(); Console.WriteLine("{0} abbreviations; {1} entries", db.AbbreviationCount, db.EntryCount); Assert.AreEqual(0, db.AbbreviationCount); Assert.AreEqual(1231, db.EntryCount); Assert.AreEqual(14673, parser.Current.Line); Assert.AreEqual(1, parser.Current.Column); Assert.AreEqual(713525, parser.Current.Position); }
public void DocearParser() { var data = File.ReadAllText(@"Sample Files\Docear.bib"); var parser = new BibTexParser(new BibTexLexer(data)); var db = parser.Parse(); Console.WriteLine("{0} abbreviations; {1} entries", db.AbbreviationCount, db.EntryCount); Assert.AreEqual(8, db.AbbreviationCount); Assert.AreEqual(1064, db.EntryCount); Assert.AreEqual(17638, parser.Current.Line); Assert.AreEqual(1, parser.Current.Column); Assert.AreEqual(682497, parser.Current.Position); }
public void BigFileParser() { var data = File.ReadAllText(@"Sample Files\BigFile.bib"); var parser = new BibTexParser(new BibTexLexer(data)); var db = parser.Parse(); Console.WriteLine("{0} abbreviations; {1} entries", db.AbbreviationCount, db.EntryCount); Assert.AreEqual(232, db.AbbreviationCount); Assert.AreEqual(1457, db.EntryCount); Assert.AreEqual(11264, parser.Current.Line); Assert.AreEqual(1, parser.Current.Column); Assert.AreEqual(359616, parser.Current.Position); }
public void BibTex_Parse_Successful() { // Set up BibTexParser. var customFieldCheckers = new Dictionary <Item.FieldType, IFieldChecker> { [Item.FieldType.ISSN] = new IssnFieldChecker(), [Item.FieldType.ISBN] = new IsbnFieldChecker(), [Item.FieldType.Author] = new AuthorFieldChecker(), [Item.FieldType.Year] = new YearFieldChecker(), [Item.FieldType.URL] = new UrlFieldChecker() }; var itemChecker = new DefaultItemChecker(new FieldValidator(new DefaultFieldChecker(), customFieldCheckers)); var parser = new BibTexParser(new ItemValidator(itemChecker)); var bib = parser.Parse(Encoding.Default.GetString(Properties.Resources.bibtex)); Assert.AreEqual(100, bib.Count); }
public void SimpleParser() { const string Data = @" @article{mrx05, auTHor = ""Mr. X"", Title = {Something Great}, publisher = ""nob"" # ""ody"", YEAR = 2005, } "; var lexer = new BibTexLexer(Data); var parser = new BibTexParser(lexer); var db = parser.Parse(); Console.WriteLine("{0} abbreviations; {1} entries", db.AbbreviationCount, db.EntryCount); }
protected BibTeXImporter(Library library, string filename) : base(library, filename) { string bibTex = null; using (Stream fs = new FileStream(ExportFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (StreamReader sr = new StreamReader(fs)) { bibTex = sr.ReadToEnd(); } } BibTexParseResult = BibTexParser.Parse(bibTex); BibTexParseResult.Items.ForEach(x => Entries.Add(new BibTeXEntry { Item = x, BibTeX = x.ToBibTex() })); }
public static BibTexDatabase CreateBibTexDatabase(string text) { var parser = new BibTexParser(new BibTexLexer(text)); return(parser.Parse()); }
public static void Main() { // Set up BibTexParser. var customFieldCheckers = new Dictionary <Item.FieldType, IFieldChecker> { [Item.FieldType.ISSN] = new IssnFieldChecker(), [Item.FieldType.ISBN] = new IsbnFieldChecker(), [Item.FieldType.Author] = new AuthorFieldChecker(), [Item.FieldType.Year] = new YearFieldChecker(), [Item.FieldType.URL] = new UrlFieldChecker() }; var itemChecker = new DefaultItemChecker(new FieldValidator(new DefaultFieldChecker(), customFieldCheckers)); var parser = new BibTexParser(new ItemValidator(itemChecker)); // Populate repository with parsed BibTex data. var repo = new InMemoryItemRepo(); try { repo.AddRange(parser.Parse(Encoding.Default.GetString(Properties.Resources.bibtex))); } catch (InvalidDataException) { Console.WriteLine("Not all loaded BibTeX data is valid. Ensure the field checkers are implemented properly."); Console.ReadLine(); return; } // Show interface to search. Console.WriteLine($"Hi, and welcome to the BibTeX search engine!"); Console.WriteLine($"Enter a word or sentence to search in the repo (searches on all fields):\n"); while (true) { // Search for specified search string. Console.Write($">"); var s = Console.ReadLine(); var result = repo.Search(s); List <Item> items = result.ToList(); // Print results. Console.Write($"\nThere are {items.Count} items containing \"{s}\".\n"); int curItem = 0; const int pageSize = 10; bool continuePrinting = true; while (continuePrinting && curItem < items.Count) { Item item = items[curItem]; Console.WriteLine($"\t{item.Fields[Item.FieldType.Title]}"); if ((curItem + 1) % pageSize == 0) { Console.Write($"\nEnter enter to get more. Write end to escape > "); if (Console.ReadLine()?.ToLower() == "end") { continuePrinting = false; break; } } curItem++; } if (items.Count > 0 && continuePrinting) { Console.WriteLine($"No more items."); } } }