NCBI C++ ToolKit
eutils_updater.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: eutils_updater.hpp 101446 2023-12-14 14:44:29Z stakhovv $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Vitaly Stakhovsky, NCBI
27  *
28  * File Description:
29  * Pubmed Updater based on EUtils
30  *
31  * ===========================================================================
32  */
33 
34 #ifndef _EUTILS_UPDATER_HPP_
35 #define _EUTILS_UPDATER_HPP_
36 
38 #include <corelib/ncbiobj.hpp>
39 
42 class CPub;
43 class CCit_art;
44 class CPubmed_entry;
46 
47 enum class EPubmedError {
48  ok,
49  not_found,
55 };
56 
59 
61  string Journal;
62  string Volume;
63  string Page;
64  string Year;
65  string Author;
66  string Issue;
67  string Title;
68  bool InPress = false;
69  bool Option1 = false;
70 
71  void FillFromArticle(const CCit_art&);
72 };
73 
74 using TPubInterceptor = std::function<void(CRef<CPub>&)>;
75 
77 {
78 public:
79  enum class ENormalize { Off, On };
80 
81 public:
82  CEUtilsUpdater(ENormalize = ENormalize::Off);
83  virtual ~CEUtilsUpdater() {}
84 
85  virtual bool Init() { return true; }
86  virtual void Fini() {}
87  virtual TEntrezId CitMatch(const CPub&, EPubmedError* = nullptr);
88  virtual TEntrezId CitMatch(const SCitMatch&, EPubmedError* = nullptr);
89  virtual CRef<CPub> GetPubmedEntry(TEntrezId pmid, EPubmedError* = nullptr);
90  CRef<CPub> GetPub(TEntrezId pmid, EPubmedError* = nullptr);
91 
93  {
94  TPubInterceptor old = m_pub_interceptor;
95  m_pub_interceptor = f;
96  return old;
97  }
98 
99  // Hydra replacement using citmatch api; RW-1918,RW-1999
100  static bool DoPubSearch(const std::vector<string>& query, std::vector<TEntrezId>& pmids);
101 
102 protected:
103  CRef<CPubmed_entry> x_GetPubmedEntry(TEntrezId pmid, EPubmedError*);
104  CRef<CPub> x_GetPub(TEntrezId pmid, EPubmedError*);
105 
106 protected:
109  TPubInterceptor m_pub_interceptor = nullptr;
110 };
111 
113 
115 {
116 public:
117  CEUtilsUpdaterWithCache(ENormalize norm = ENormalize::Off) :
118  CEUtilsUpdater(norm) {}
119 
120  CRef<CPub> GetPubmedEntry(TEntrezId pmid, EPubmedError* = nullptr) override;
121 
122  void ReportStats(std::ostream&);
123  void ClearCache();
124 
125 private:
127 
128  size_t m_num_requests = 0;
129  size_t m_cache_hits = 0;
130 };
131 
135 
136 #endif // _EUTILS_UPDATER_HPP_
CEUtilsUpdaterWithCache(ENormalize norm=ENormalize::Off)
map< TEntrezId, CConstRef< CPub > > m_cache
CRef< CEUtils_ConnContext > m_Ctx
TPubInterceptor SetPubInterceptor(TPubInterceptor f)
virtual ~CEUtilsUpdater()
virtual bool Init()
virtual void Fini()
Definition: Pub.hpp:56
CPubmed_entry –.
Definition: map.hpp:338
EPubmedError
@ cannot_connect_searchbackend_pmdb
std::function< void(CRef< CPub > &)> TPubInterceptor
CNcbiOstream & operator<<(CNcbiOstream &, EPubmedError)
SStrictId_Entrez::TId TEntrezId
TEntrezId type for entrez ids which require the same strictness as TGi.
Definition: ncbimisc.hpp:1041
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NCBI_XOBJEDIT_EXPORT
Definition: ncbi_export.h:1291
Definition: fix_pub.hpp:45
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
string Journal
static string query
Modified on Wed Feb 21 09:56:23 2024 by modify_doxy.py rev. 669887