1 /* $Id: Pub.cpp 607097 2020-04-30 12:32:13Z grichenk $
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: .......
27 *
28 * File Description:
29 * .......
30 *
31 * Remark:
32 * This code was originally generated by application DATATOOL
33 * using specifications from the ASN data definition file
34 * 'pub.asn'.
35 */
36
37 #include <ncbi_pch.hpp>
38
39 #include <objects/pub/Pub.hpp>
40 #include <objects/pub/Pub_equiv.hpp>
41
42 #include <objects/biblio/Author.hpp>
43 #include <objects/biblio/Auth_list.hpp>
44 #include <objects/biblio/PubMedId.hpp>
45 #include <objects/biblio/Cit_art.hpp>
46 #include <objects/biblio/Cit_jour.hpp>
47 #include <objects/biblio/Cit_book.hpp>
48 #include <objects/biblio/Cit_proc.hpp>
49 #include <objects/biblio/Cit_let.hpp>
50 #include <objects/biblio/Cit_sub.hpp>
51 #include <objects/biblio/Cit_pat.hpp>
52 #include <objects/biblio/Cit_let.hpp>
53 #include <objects/biblio/Id_pat.hpp>
54 #include <objects/biblio/Cit_gen.hpp>
55 #include <objects/biblio/Imprint.hpp>
56 #include <objects/general/Date_std.hpp>
57 #include <objects/general/Name_std.hpp>
58 #include <objects/general/Person_id.hpp>
59 #include <objects/medline/Medline_entry.hpp>
60
61 #include <objects/pub/pub_macros.hpp>
62
63 // generated classes
64
65 BEGIN_NCBI_SCOPE
66
67 BEGIN_objects_SCOPE // namespace ncbi::objects::
68
69 // destructor
~CPub(void)70 CPub::~CPub(void)
71 {
72 }
73
74
75 // Appends a label to "label"
GetLabel(string * label,ELabelType type,TLabelFlags flags,ELabelVersion version) const76 bool CPub::GetLabel(string* label,
77 ELabelType type,
78 TLabelFlags flags,
79 ELabelVersion version) const
80 {
81 static const char* s_PubTypes[14] = {
82 "Unknown",
83 "Generic",
84 "Submit",
85 "Medline",
86 "MUID",
87 "Article",
88 "Journal",
89 "Book",
90 "Proceedings",
91 "Patent",
92 "PatID",
93 "Manuscript",
94 "Equiv",
95 "PMID" };
96
97 // Check that label exists
98 if (!label) {
99 return false;
100 }
101
102 // Get the index into the s_PubTypes array corresponding to pub type
103 int idx = static_cast<int>(Which());
104 idx = idx >= 0 && idx < 14 ? idx : 0;
105
106 if (type == eType) {
107 // Append pub type to label and return
108 *label += s_PubTypes[idx];
109 return true;
110 }
111
112 if (type == eBoth) {
113 // Append pub type to label
114 *label += string(s_PubTypes[idx]) + ": ";
115 }
116
117 switch (Which()) {
118 case e_Muid:
119 *label += "NLM" + NStr::NumericToString(GetMuid());
120 return true;
121 case e_Pmid:
122 *label += "PM" + NStr::NumericToString(GetPmid().Get());
123 return true;
124 case e_Equiv:
125 return GetEquiv().GetLabel(label, flags, version);
126 case e_Medline:
127 return GetMedline().GetLabel(label, flags, version);
128 case e_Article:
129 return GetArticle().GetLabel(label, flags, version);
130 case e_Journal:
131 return GetJournal().GetLabel(label, flags, version);
132 case e_Book:
133 return GetBook().GetLabel(label, flags, version);
134 case e_Proc:
135 return GetProc().GetLabel(label, flags, version);
136 case e_Man:
137 return GetMan().GetLabel(label, flags, version);
138 case e_Sub:
139 return GetSub().GetLabel(label, flags, version);
140 case e_Patent:
141 return GetPatent().GetLabel(label, flags, version);
142 case e_Pat_id:
143 return GetPat_id().GetLabel(label, flags, version);
144 case e_Gen:
145 return GetGen().GetLabel(label, flags, version);
146 default:
147 return false;
148 }
149 }
150
151
IsSetAuthors(void) const152 bool CPub::IsSetAuthors(void) const
153 {
154 switch (Which()) {
155 case CPub::e_Gen :
156 return (GetGen().IsSetAuthors());
157 case CPub::e_Sub :
158 return (GetSub().IsSetAuthors());
159 case CPub::e_Article :
160 return (GetArticle().IsSetAuthors());
161 case CPub::e_Book :
162 return (GetBook().IsSetAuthors());
163 case CPub::e_Proc :
164 return (GetProc().IsSetBook() && GetProc().GetBook().IsSetAuthors());
165 case CPub::e_Patent :
166 return (GetPatent().IsSetAuthors());
167 case CPub::e_Man :
168 return (GetMan().IsSetCit() && GetMan().GetCit().IsSetAuthors());
169 default :
170 break;
171 }
172
173 return false;
174 }
175
GetAuthors(void) const176 const CAuth_list& CPub::GetAuthors (void) const
177 {
178 switch (Which()) {
179 case CPub::e_Gen :
180 return (GetGen().GetAuthors());
181 case CPub::e_Sub :
182 return (GetSub().GetAuthors());
183 case CPub::e_Article :
184 return (GetArticle().GetAuthors());
185 case CPub::e_Book :
186 return (GetBook().GetAuthors());
187 case CPub::e_Proc :
188 return (GetProc().GetBook().GetAuthors());
189 case CPub::e_Patent :
190 return (GetPatent().GetAuthors());
191 case CPub::e_Man :
192 return (GetMan().GetCit().GetAuthors());
193 default :
194 NCBI_THROW(CSerialException, eNotImplemented,
195 "CPub::GetAuthors: unsupported entry type "
196 + SelectionName(Which()));
197 }
198 }
199
SetAuthors(void)200 CAuth_list& CPub::SetAuthors (void)
201 {
202 switch (Which()) {
203 case CPub::e_Gen :
204 return (SetGen().SetAuthors());
205 case CPub::e_Sub :
206 return (SetSub().SetAuthors());
207 case CPub::e_Article :
208 return (SetArticle().SetAuthors());
209 case CPub::e_Book :
210 return (SetBook().SetAuthors());
211 case CPub::e_Proc :
212 return (SetProc().SetBook().SetAuthors());
213 case CPub::e_Patent :
214 return (SetPatent().SetAuthors());
215 case CPub::e_Man :
216 return (SetMan().SetCit().SetAuthors());
217 default :
218 NCBI_THROW(CSerialException, eNotImplemented,
219 "CPub::SetAuthors: unsupported entry type "
220 + SelectionName(Which()));
221 }
222 }
223
GetTitles(TOneTitleRefVec & out_title,size_t iMaxToGet) const224 void CPub::GetTitles(
225 TOneTitleRefVec & out_title,
226 size_t iMaxToGet ) const
227 {
228 // this "if" lets us assume below this point that
229 // we have room for at least one
230 if( iMaxToGet <= 0 ) {
231 return;
232 }
233
234 switch( Which() ) {
235 case CPub::e_not_set:
236 case CPub::e_Medline:
237 case CPub::e_Pmid:
238 case CPub::e_Pat_id:
239 // these types don't have titles, so nothing to do
240 break;
241 case CPub::e_Gen:
242 if( GetGen().IsSetTitle() ) {
243 out_title.push_back(
244 xs_GetTitleFromPlainString(
245 GetGen().GetTitle()) );
246 }
247 break;
248 case CPub::e_Sub:
249 if( GetSub().IsSetDescr() ) {
250 out_title.push_back(
251 xs_GetTitleFromPlainString(
252 GetSub().GetDescr()) );
253 }
254 break;
255 case CPub::e_Article:
256 if( GetArticle().IsSetTitle() && GetArticle().GetTitle().IsSet() ) {
257 xs_AppendTitles( out_title, iMaxToGet, GetArticle().GetTitle() );
258 }
259 break;
260 case CPub::e_Journal:
261 if( GetJournal().IsSetTitle() ) {
262 xs_AppendTitles( out_title, iMaxToGet, GetJournal().GetTitle() );
263 }
264 break;
265 case CPub::e_Book:
266 if( GetBook().IsSetTitle() ) {
267 xs_AppendTitles( out_title, iMaxToGet, GetBook().GetTitle() );
268 }
269 break;
270 case CPub::e_Proc:
271 // what to do here? It has a book and meeting
272 // It's not entirely clear if this is the best course of action
273 if( FIELD_CHAIN_OF_2_IS_SET(GetProc(), Book, Title) ) {
274 xs_AppendTitles( out_title, iMaxToGet,
275 GetProc().GetBook().GetTitle() );
276 }
277 break;
278 case CPub::e_Patent:
279 if( GetPatent().IsSetTitle() ) {
280 out_title.push_back(
281 xs_GetTitleFromPlainString(
282 GetPatent().GetTitle()) );
283 }
284 break;
285 case CPub::e_Man:
286 if( FIELD_CHAIN_OF_2_IS_SET(GetMan(), Cit, Title) ) {
287 xs_AppendTitles( out_title, iMaxToGet,
288 GetMan().GetCit().GetTitle() );
289 }
290 break;
291 case CPub::e_Equiv:
292 {
293 size_t iMaxTitleSizeAllowed = ( out_title.size() + iMaxToGet );
294 if( iMaxTitleSizeAllowed < out_title.size() ) {
295 // integer overflowed
296 iMaxTitleSizeAllowed =
297 std::numeric_limits<std::size_t>::max();
298 }
299 FOR_EACH_PUB_ON_PUBEQUIV(pub_it, GetEquiv()) {
300 if( out_title.size() >= iMaxTitleSizeAllowed ) {
301 break;
302 }
303
304 // dig down recursively
305 (*pub_it)->GetTitles(out_title,
306 (iMaxTitleSizeAllowed - out_title.size()) );
307 }
308 }
309 break;
310 default:
311 NCBI_THROW(CException, eUnknown, "unhandled pub type");
312 }
313 }
314
315 // static
316 CPub::TOneTitleRef
xs_GetTitleFromPlainString(const string & sTitle)317 CPub::xs_GetTitleFromPlainString(const string & sTitle)
318 {
319 CRef<CTitle::C_E> pRval( new CTitle::C_E );
320 pRval->SetName( sTitle );
321 return pRval;
322 }
323
324 // static
xs_AppendTitles(TOneTitleRefVec & out_title,size_t iMaxToGet,const CTitle & in_title)325 void CPub::xs_AppendTitles( TOneTitleRefVec & out_title,
326 size_t iMaxToGet,
327 const CTitle & in_title )
328 {
329 if( iMaxToGet <= 0 ) {
330 return;
331 }
332
333 if( ! in_title.IsSet() ) {
334 return;
335 }
336
337 size_t iNumCopiedSoFar = 0;
338 CTitle::Tdata::const_iterator src_it = in_title.Get().begin();
339 CTitle::Tdata::const_iterator src_it_end = in_title.Get().end();
340 for( ; src_it != src_it_end && iNumCopiedSoFar < iMaxToGet;
341 ++src_it, ++iNumCopiedSoFar)
342 {
343 out_title.push_back( *src_it );
344 }
345 }
346
347
348 typedef struct {
349 string country;
350 string number;
351 string app_number;
352 TEntrezId muid;
353 TEntrezId pmid;
354 CRef<CCit_art> art;
355 } SPubMatchInfo;
356
357
s_GetTitleString(const CTitle::C_E & title)358 string s_GetTitleString(const CTitle::C_E& title)
359 {
360 string str = "";
361
362 switch (title.Which()) {
363 case CTitle::C_E::e_Name:
364 str = title.GetName();
365 break;
366 case CTitle::C_E::e_Abr:
367 str = title.GetAbr();
368 break;
369 case CTitle::C_E::e_Coden:
370 str = title.GetCoden();
371 break;
372 case CTitle::C_E::e_Isbn:
373 str = title.GetIsbn();
374 break;
375 case CTitle::C_E::e_Iso_jta:
376 str = title.GetIso_jta();
377 break;
378 case CTitle::C_E::e_Issn:
379 str = title.GetIssn();
380 break;
381 case CTitle::C_E::e_Jta:
382 str = title.GetJta();
383 break;
384 case CTitle::C_E::e_Ml_jta:
385 str = title.GetMl_jta();
386 break;
387 case CTitle::C_E::e_Trans:
388 str = title.GetTrans();
389 break;
390 case CTitle::C_E::e_Tsub:
391 str = title.GetTsub();
392 break;
393 case CTitle::C_E::e_not_set:
394 break;
395 }
396 return str;
397 }
398
399
s_TitleMatch(const CTitle & title1,const CTitle & title2,CTitle::C_E::E_Choice title_type)400 bool s_TitleMatch(const CTitle& title1, const CTitle& title2, CTitle::C_E::E_Choice title_type)
401 {
402 string compare1 = "";
403 string compare2 = "";
404
405 ITERATE(CTitle::Tdata, it, title1.Get()) {
406 if ((*it)->Which() == title_type) {
407 compare1 = s_GetTitleString(**it);
408 break;
409 }
410 }
411 ITERATE(CTitle::Tdata, it, title2.Get()) {
412 if ((*it)->Which() == title_type) {
413 compare2 = s_GetTitleString(**it);
414 break;
415 }
416 }
417 if (!NStr::IsBlank(compare1) && NStr::EqualNocase(compare1, compare2)) {
418 return true;
419 } else {
420 return false;
421 }
422 }
423
424
425 #define FIELD(Obj,Field) (Obj.IsSet##Field() ? Obj.Get##Field() : "")
426 #define FIELD_MATCH(Obj1,Obj2,Field) (NStr::EqualNocase(FIELD(Obj1,Field), FIELD(Obj2,Field)))
427 #define INT_FIELD_MATCH(Obj1,Obj2,Field) ((Obj1.IsSet##Field() && Obj2.IsSet##Field() && Obj1.Get##Field() == Obj2.Get##Field()) || (!Obj1.IsSet##Field() && !Obj2.IsSet##Field()))
428
429 #define S_MATCH(Obj1,Obj2,Field) ((!Obj1.IsSet##Field() && !Obj2.IsSet##Field()) || (Obj1.IsSet##Field() && Obj2.IsSet##Field() && s_Match##Field(Obj1.Get##Field(),Obj2.Get##Field())))
430 #define S_MATCH_A(Obj1,Obj2,Field) ((!Obj1.IsSet##Field() && !Obj2.IsSet##Field()) || (Obj1.IsSet##Field() && Obj2.IsSet##Field() && Obj1.Get##Field().SameCitation(Obj2.Get##Field())))
431
s_MatchDate(const CDate & date1,const CDate & date2)432 bool s_MatchDate(const CDate& date1, const CDate& date2)
433 {
434 return date1.Equals(date2);
435 }
436
437
s_MatchImp(const CImprint & imp1,const CImprint & imp2)438 bool s_MatchImp(const CImprint& imp1, const CImprint& imp2)
439 {
440 if (!S_MATCH(imp1, imp2, Date)) {
441 return false;
442 }
443
444 if (!FIELD_MATCH(imp1, imp2, Volume) ||
445 !FIELD_MATCH(imp1, imp2, Issue) ||
446 !FIELD_MATCH(imp1, imp2, Pages) ||
447 !FIELD_MATCH(imp1, imp2, Section) ||
448 !FIELD_MATCH(imp1, imp2, Part_sup) ||
449 !FIELD_MATCH(imp1, imp2, Language)) {
450 return false;
451 }
452
453 if (imp1.IsSetCprt() && imp2.IsSetCprt() && !imp1.GetCprt().Equals(imp2.GetCprt())) {
454 return false;
455 }
456 return true;
457 }
458
459
460 // try to match one of these title types
461 static const CTitle::C_E::E_Choice s_MatchJournalTypes[] = {
462 CTitle::C_E::e_Iso_jta,
463 CTitle::C_E::e_Ml_jta,
464 CTitle::C_E::e_Coden,
465 CTitle::C_E::e_Issn,
466 CTitle::C_E::e_Name,
467 CTitle::C_E::e_Jta,
468 CTitle::C_E::e_not_set
469 };
470
471
s_MatchTitle(const CTitle & title1,const CTitle & title2)472 bool s_MatchTitle(const CTitle& title1, const CTitle& title2)
473 {
474 bool match_title = false;
475
476 for (size_t i = 0; !match_title && s_MatchJournalTypes[i] != CTitle::C_E::e_not_set; i++) {
477 match_title = s_TitleMatch(title1, title2, s_MatchJournalTypes[i]);
478 }
479
480 return match_title;
481 }
482
483
s_JournalMatch(const CCit_jour & jour1,const CCit_jour & jour2)484 bool s_JournalMatch(const CCit_jour& jour1, const CCit_jour& jour2)
485 {
486 // look for matching title
487 if (!S_MATCH(jour1, jour2, Title)) {
488 return false;
489 }
490
491 return S_MATCH(jour1, jour2, Imp);
492 }
493
494
s_MatchBook(const CCit_book & book1,const CCit_book & book2)495 bool s_MatchBook(const CCit_book& book1, const CCit_book& book2)
496 {
497 if (!S_MATCH_A(book1, book2, Authors)) {
498 return false;
499 }
500
501 if (!S_MATCH(book1, book2, Imp)) {
502 return false;
503 }
504
505 if ((!book1.IsSetTitle() && book2.IsSetTitle()) ||
506 (book1.IsSetTitle() && !book2.IsSetTitle()) ||
507 !s_TitleMatch(book1.GetTitle(), book2.GetTitle(), CTitle::C_E::e_Name)) {
508 return false;
509 }
510
511 return true;
512 }
513
514
s_ProcMatch(const CCit_proc & book1,const CCit_proc & book2)515 bool s_ProcMatch(const CCit_proc& book1, const CCit_proc& book2)
516 {
517 return S_MATCH(book1, book2, Book);
518 }
519
520
s_ManMatch(const CCit_let & book1,const CCit_let & book2)521 bool s_ManMatch(const CCit_let& book1, const CCit_let& book2)
522 {
523 return ((!book1.IsSetCit() && !book2.IsSetCit()) ||
524 (book1.IsSetCit() && book2.IsSetCit() && s_MatchBook(book1.GetCit(), book2.GetCit())));
525 }
526
527
s_CitArtMatch(const CCit_art & art1,const CCit_art & art2)528 bool s_CitArtMatch(const CCit_art& art1, const CCit_art& art2)
529 {
530 if (!art1.IsSetFrom() || !art2.IsSetFrom()) {
531 return false;
532 }
533 if (art1.GetFrom().Which() != art2.GetFrom().Which()) {
534 return false;
535 }
536
537 if (art1.GetFrom().IsJournal()) {
538 // make sure journals match
539 if (!s_JournalMatch(art1.GetFrom().GetJournal(), art2.GetFrom().GetJournal())) {
540 return false;
541 }
542 } else if (art1.GetFrom().IsBook()) {
543 // make sure books match
544 if (!s_MatchBook(art1.GetFrom().GetBook(), art2.GetFrom().GetBook())) {
545 return false;
546 }
547 } else if (art1.GetFrom().IsProc()) {
548 // make sure proceedings match
549 if (!s_ProcMatch(art1.GetFrom().GetProc(), art2.GetFrom().GetProc())) {
550 return false;
551 }
552 }
553
554 if (!S_MATCH_A(art1, art2, Authors)) {
555 return false;
556 }
557
558 if (!art1.IsSetTitle() && !art2.IsSetTitle()) {
559 // ok, no title for either
560 } else if (!art1.IsSetTitle() || !art2.IsSetTitle()) {
561 return false;
562 } else if (!s_TitleMatch(art1.GetTitle(), art2.GetTitle(), CTitle::C_E::e_Name)) {
563 return false;
564 }
565
566 return true;
567 }
568
569
s_CitGenMatch(const CCit_gen & gen1,const CCit_gen & gen2)570 bool s_CitGenMatch(const CCit_gen& gen1, const CCit_gen& gen2)
571 {
572 if (!FIELD_MATCH(gen1, gen2, Volume) ||
573 !FIELD_MATCH(gen1, gen2, Issue) ||
574 !FIELD_MATCH(gen1, gen2, Pages) ||
575 !FIELD_MATCH(gen1, gen2, Title) ||
576 !FIELD_MATCH(gen1, gen2, Cit)) {
577 return false;
578 }
579 if (!S_MATCH_A(gen1, gen2, Authors)) {
580 return false;
581 }
582
583 if (!INT_FIELD_MATCH(gen1, gen2, Muid) ||
584 !INT_FIELD_MATCH(gen1, gen2, Serial_number)) {
585 return false;
586 }
587
588 if (!gen1.IsSetJournal() && !gen2.IsSetJournal()) {
589 // both empty, ok
590 } else if (!gen1.IsSetJournal() || !gen2.IsSetJournal()) {
591 return false;
592 } else if (!s_MatchTitle(gen1.GetJournal(), gen2.GetJournal())) {
593 return false;
594 }
595
596 if (!S_MATCH(gen1, gen2, Date)) {
597 return false;
598 }
599
600 return true;
601
602 }
603
604
s_CitSubMatch(const CCit_sub & sub1,const CCit_sub & sub2)605 bool s_CitSubMatch(const CCit_sub& sub1, const CCit_sub& sub2)
606 {
607 if (!S_MATCH_A(sub1, sub2, Authors)) {
608 return false;
609 }
610
611 bool rval = false;
612
613 if (sub1.IsSetImp() && sub2.IsSetImp()) {
614 rval = s_MatchImp(sub1.GetImp(), sub2.GetImp());
615 } else {
616 // compare date from imprint or in sub
617 CConstRef<CDate> date1(NULL);
618 CConstRef<CDate> date2(NULL);
619 if (sub1.IsSetImp() && sub1.GetImp().IsSetDate()) {
620 date1.Reset(&(sub1.GetImp().GetDate()));
621 } else if (sub1.IsSetDate()) {
622 date1.Reset(&(sub1.GetDate()));
623 }
624 if (sub2.IsSetImp() && sub2.GetImp().IsSetDate()) {
625 date2.Reset(&(sub2.GetImp().GetDate()));
626 } else if (sub2.IsSetDate()) {
627 date2.Reset(&(sub2.GetDate()));
628 }
629 if (!date1 && !date2) {
630 rval = true;
631 } else if (!date1 || !date2) {
632 rval = false;
633 } else {
634 rval = date1->Equals(*date2);
635 }
636 }
637 return rval;
638 }
639
640
s_MatchInfoMatches(const SPubMatchInfo & match1,const SPubMatchInfo & match2)641 bool s_MatchInfoMatches(const SPubMatchInfo& match1, const SPubMatchInfo& match2)
642 {
643 if (match1.muid > ZERO_ENTREZ_ID && match2.muid > ZERO_ENTREZ_ID) {
644 if (match1.muid == match2.muid) {
645 return true;
646 }
647 }
648
649 if (match1.pmid > ZERO_ENTREZ_ID && match2.pmid > ZERO_ENTREZ_ID) {
650 if (match1.pmid == match2.pmid) {
651 return true;
652 }
653 }
654
655 if (!NStr::IsBlank(match1.country) && !NStr::IsBlank(match2.country)) {
656 if (NStr::EqualNocase(match1.country, match2.country) &&
657 NStr::EqualNocase(match1.number, match2.number) &&
658 NStr::EqualNocase(match1.app_number, match2.app_number)) {
659 return true;
660 }
661 }
662
663 if (match1.art && match2.art) {
664 if (s_CitArtMatch(*(match1.art), *(match2.art))) {
665 return true;
666 }
667 }
668
669 return false;
670 }
671
672
s_GetPubMatchInfo(const CCit_pat & patent,SPubMatchInfo & match)673 void s_GetPubMatchInfo(const CCit_pat& patent, SPubMatchInfo& match)
674 {
675 if (patent.IsSetCountry()) {
676 match.country = patent.GetCountry();
677 }
678 if (patent.IsSetNumber()) {
679 match.number = patent.GetNumber();
680 }
681 if (patent.IsSetApp_number()) {
682 match.app_number = patent.GetApp_number();
683 }
684 }
685
686
s_GetPubMatchInfo(const CId_pat & patent,SPubMatchInfo & match)687 void s_GetPubMatchInfo(const CId_pat& patent, SPubMatchInfo& match)
688 {
689 if (patent.IsSetCountry()) {
690 match.country = patent.GetCountry();
691 }
692 if (patent.IsSetId()) {
693 if (patent.GetId().IsNumber()) {
694 match.number = patent.GetId().GetNumber();
695 } else if (patent.GetId().IsApp_number()) {
696 match.app_number = patent.GetId().GetApp_number();
697 }
698 }
699 }
700
701
s_GetPubMatchInfo(const CPub & pub,SPubMatchInfo & match)702 void s_GetPubMatchInfo(const CPub& pub, SPubMatchInfo& match)
703 {
704 match.muid = ZERO_ENTREZ_ID;
705 match.pmid = ZERO_ENTREZ_ID;
706 match.country = "";
707 match.number = "";
708 match.app_number = "";
709
710 switch (pub.Which()) {
711 case CPub::e_Pmid:
712 match.pmid = pub.GetPmid();
713 break;
714 case CPub::e_Muid:
715 match.muid = pub.GetMuid();
716 break;
717 case CPub::e_Patent:
718 s_GetPubMatchInfo(pub.GetPatent(), match);
719 break;
720 case CPub::e_Pat_id:
721 s_GetPubMatchInfo(pub.GetPat_id(), match);
722 break;
723 case CPub::e_Article:
724 match.art = new CCit_art();
725 match.art->Assign(pub.GetArticle());
726 break;
727 default:
728 break;
729 }
730 }
731
732
SameCitation(const CPub & other) const733 bool CPub::SameCitation(const CPub& other) const
734 {
735 if (Which() == CPub::e_Equiv) {
736 if (other.Which() == CPub::e_Equiv) {
737 return GetEquiv().SameCitation(other.GetEquiv());
738 } else {
739 return GetEquiv().SameCitation(other);
740 }
741 }
742 SPubMatchInfo match1, match2;
743
744 s_GetPubMatchInfo(*this, match1);
745 s_GetPubMatchInfo(other, match2);
746 if (s_MatchInfoMatches(match1, match2)) {
747 return true;
748 }
749 // false if different pub types
750 if (Which() != other.Which()) {
751 return false;
752 }
753
754 bool rval = false;
755
756 switch (Which()) {
757 case CPub::e_Gen:
758 rval = s_CitGenMatch(GetGen(), other.GetGen());
759 break;
760 case CPub::e_Sub:
761 rval = s_CitSubMatch(GetSub(), other.GetSub());
762 break;
763 case CPub::e_Journal:
764 rval = s_JournalMatch(GetJournal(), other.GetJournal());
765 break;
766 case CPub::e_Book:
767 rval = s_MatchBook(GetBook(), other.GetBook());
768 break;
769 case CPub::e_Proc:
770 rval = s_ProcMatch(GetProc(), other.GetProc());
771 break;
772 case CPub::e_Man:
773 rval = s_ManMatch(GetMan(), other.GetMan());
774 break;
775 default:
776 break;
777 }
778 return rval;
779 }
780
781
782 END_objects_SCOPE // namespace ncbi::objects::
783
784 END_NCBI_SCOPE
785
786 /* Original file checksum: lines: 61, chars: 1862, CRC32: d27bbf43 */
787