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 Basic_Import_Test(string pubmed_filepath) { // See http://www.nlm.nih.gov/bsd/licensee/elements_descriptions.html for the low-down string path = GetNormalizedPathToPubMedXMLTestFile(pubmed_filepath); ASSERT.FileExists(path); string pubmed_xml = GetTestFileContent(path); Result rv = new Result(); rv.success = PubMedXMLToBibTex.TryConvert(pubmed_xml, out rv.bibtex, out rv.messages); // Serialize the result to JSON for easier comparison via ApprovalTests->BeyondCompare (that's what I use for *decades* now) string json_out = JsonConvert.SerializeObject(rv, Newtonsoft.Json.Formatting.Indented).Replace("\r\n", "\n"); //ApprovalTests.Approvals.VerifyJson(json_out); --> becomes the code below: ApprovalTests.Approvals.Verify( new QiqqaApprover(json_out, pubmed_filepath), ApprovalTests.Approvals.GetReporter() ); }
private void ReflectLatestBrowserContent() { try { // Neaten the text in the browser string text = ObjWebBrowser.CurrentPageText; if (null == text) { return; } // Process text = text.Trim(); // If this is valid BibTeX, offer it { if (IsValidBibTex(text)) { FeatureTrackingManager.Instance.UseFeature(Features.MetadataSniffer_ValidBibTeX); UseAsBibTeX(text); return; } } // If this is valid PubMed XML, offer it { string converted_bibtex; List <string> messages; bool success = PubMedXMLToBibTex.TryConvert(text, out converted_bibtex, out messages); if (success) { FeatureTrackingManager.Instance.UseFeature(Features.MetadataSniffer_ValidPubMed); UseAsBibTeX(converted_bibtex); return; } else { if (0 < messages.Count) { foreach (string message in messages) { Logging.Info(message); } } } } // Otherwise lets try parse the page cos it might be a google scholar page and if so we are going to want to try to get the first link to BibTeX if (ConfigurationManager.Instance.ConfigurationRecord.Metadata_UseBibTeXSnifferWizard) { // Only do this automatically if there is not already bibtex in the record if (null != pdf_document && String.IsNullOrEmpty(pdf_document.BibTex)) { string url = ObjWebBrowser.CurrentUri.ToString(); string html = ObjWebBrowser.CurrentPageHTML; List <GoogleScholarScrapePaper> gssps = GoogleScholarScraper.ScrapeHtml(html, url); try { // Try to process the first bibtex record if (0 < gssps.Count) { GoogleScholarScrapePaper gssp = gssps[0]; if (!String.IsNullOrEmpty(gssp.bibtex_url)) { if (last_autonavigated_url != gssp.bibtex_url) { last_autonavigated_url = gssp.bibtex_url; gssp.bibtex_url = gssp.bibtex_url.Replace("&", "&"); ObjWebBrowser.OpenUrl(gssp.bibtex_url); } } } } catch (Exception ex) { Logging.Warn(ex, "Sniffer was not able to parse the results that came back from GS."); } } } } catch (Exception ex) { Logging.Error(ex, "There was an exception while trying to parse the html back from Google Scholar"); } }