// Determines the type of set and calls the appropriately instantiated // s_GetLabel bool CPub_set::GetLabel(string* label, TLabelFlags flags, ELabelVersion version) const { // Ensure label exists if (!label) { return false; } switch (Which()) { case e_Pub: return s_GetLabel<CPub>(label, GetPub(), flags, version); case e_Medline: return s_GetLabel<CMedline_entry>(label, GetMedline(), flags, version); case e_Article: return s_GetLabel<CCit_art>(label, GetArticle(), flags, version); case e_Journal: return s_GetLabel<CCit_jour>(label, GetJournal(), flags, version); case e_Book: return s_GetLabel<CCit_book>(label, GetBook(), flags, version); case e_Proc: return s_GetLabel<CCit_proc>(label, GetProc(), flags, version); case e_Patent: return s_GetLabel<CCit_pat>(label, GetPatent(), flags, version); default: return false; } }
Interpreter::Functor Interpreter::GetFunctor(Dictinary::SimpleCommands command) { auto art = std::shared_ptr<Article>(GetArticle(command)); auto stack = m_stack; auto tokens = m_tokens; if (art == nullptr) { throw std::runtime_error("No operations found"); } return [stack, tokens, art]() { art->RunArticle(stack, tokens); }; }
const CAuth_list& CPub::GetAuthors (void) const { switch (Which()) { case CPub::e_Gen : return (GetGen().GetAuthors()); case CPub::e_Sub : return (GetSub().GetAuthors()); case CPub::e_Article : return (GetArticle().GetAuthors()); case CPub::e_Book : return (GetBook().GetAuthors()); case CPub::e_Proc : return (GetProc().GetBook().GetAuthors()); case CPub::e_Patent : return (GetPatent().GetAuthors()); case CPub::e_Man : return (GetMan().GetCit().GetAuthors()); default : NCBI_THROW(CSerialException, eNotImplemented, "CPub::GetAuthors: unsupported entry type " + SelectionName(Which())); } }
bool CPub::IsSetAuthors(void) const { switch (Which()) { case CPub::e_Gen : return (GetGen().IsSetAuthors()); case CPub::e_Sub : return (GetSub().IsSetAuthors()); case CPub::e_Article : return (GetArticle().IsSetAuthors()); case CPub::e_Book : return (GetBook().IsSetAuthors()); case CPub::e_Proc : return (GetProc().IsSetBook() && GetProc().GetBook().IsSetAuthors()); case CPub::e_Patent : return (GetPatent().IsSetAuthors()); case CPub::e_Man : return (GetMan().IsSetCit() && GetMan().GetCit().IsSetAuthors()); default : break; } return false; }
std::string en::GetNounString(Noun* NounObj, bool ObjCase) { if (NounObj->ID==0) return ""; //Create the final string that will be returned. (Empty for now). std::string NounString = ""; //Create the string that will be inserted before the articles (so that we can correctly turn 'a' into 'an' if this begins with a vowel) std::string NounResult; //Prepend all the adjectives to the NounResult, if the adjectives exist. for (int i = 0; i < 16; ++i) { std::string Adjective = GetAdjective(NounObj->Adjectives[i]); if (Adjective.compare("")!=0) NounResult += Adjective + " "; } //Prepend the Noun to NounResult. NounResult += GetNoun(NounObj,ObjCase); //Get the string of the article, telling it to turn 'a' into 'an' if NounResult begins with a vowel. std::string Article = GetArticle(NounObj,IsVowel(NounResult[0])); //Get the numberal std::string Numeral = GetNumeral(NounObj,false); //Get the preposition std::string Prepos = GetPrepos(NounObj->PreposNum); //Start the NounString with the preposition if necessary if (Prepos.compare("")!=0) NounString+=Prepos + " "; //Add the article if (Article.compare("")!=0) NounString+=Article + " "; //Add the Numeral. This is not currently added to noun result, and shouldn't matter as you shouldn't be adding a numeral when you use a/an if (Numeral.compare("")!=0) NounString+=Numeral + " "; //Add the noun result to the noun string (adjectives, and noun) NounString+=NounResult; //If there is a genitive object, add it. if (NounObj->ShouldUseGenitive) { NounString += " " + GenitiveMarker + " "; NounString += GetNounString(NounObj->GenitiveNoun,true); } //If there is a relative clause, add it. if (NounObj->ShouldUseRelativeClause) { NounObj->RelativeClause->IsClause = true; //If the relative clause is about a persion, use "who" int NounType = GetNounType(NounObj->ID); if (NounType == 'm' || NounType == 'f' || NounType == 'p' || NounType == 'd') { NounString += " " + RClausePersonalMarker; } //Otherwise if the relative clause is essential use "that" else if (NounObj->IsRelativeClauseEssential) NounString += " " + RClauseEssentialMarker; //Otherwise (non essential) use "which" else NounString += " " + RClauseNonEssentialMarker; //Append the clause NounString += " " + NounObj->RelativeClause->createSentence(); } //Return the result. return NounString; }
// Appends a label to "label" bool CPub::GetLabel(string* label, ELabelType type, TLabelFlags flags, ELabelVersion version) const { static const char* s_PubTypes[14] = { "Unknown", "Generic", "Submit", "Medline", "MUID", "Article", "Journal", "Book", "Proceedings", "Patent", "PatID", "Manuscript", "Equiv", "PMID" }; // Check that label exists if (!label) { return false; } // Get the index into the s_PubTypes array corresponding to pub type int idx = static_cast<int>(Which()); idx = idx >= 0 && idx < 14 ? idx : 0; if (type == eType) { // Append pub type to label and return *label += s_PubTypes[idx]; return true; } if (type == eBoth) { // Append pub type to label *label += string(s_PubTypes[idx]) + ": "; } switch (Which()) { case e_Muid: *label += "NLM" + NStr::IntToString(GetMuid()); return true; case e_Pmid: *label += "PM" + NStr::IntToString(GetPmid().Get()); return true; case e_Equiv: return GetEquiv().GetLabel(label, flags, version); case e_Medline: return GetMedline().GetLabel(label, flags, version); case e_Article: return GetArticle().GetLabel(label, flags, version); case e_Journal: return GetJournal().GetLabel(label, flags, version); case e_Book: return GetBook().GetLabel(label, flags, version); case e_Proc: return GetProc().GetLabel(label, flags, version); case e_Man: return GetMan().GetLabel(label, flags, version); case e_Sub: return GetSub().GetLabel(label, flags, version); case e_Patent: return GetPatent().GetLabel(label, flags, version); case e_Pat_id: return GetPat_id().GetLabel(label, flags, version); case e_Gen: return GetGen().GetLabel(label, flags, version); default: return false; } }
void CPub::GetTitles( TOneTitleRefVec & out_title, size_t iMaxToGet ) const { // this "if" lets us assume below this point that // we have room for at least one if( iMaxToGet <= 0 ) { return; } switch( Which() ) { case CPub::e_not_set: case CPub::e_Medline: case CPub::e_Pmid: case CPub::e_Pat_id: // these types don't have titles, so nothing to do break; case CPub::e_Gen: if( GetGen().IsSetTitle() ) { out_title.push_back( xs_GetTitleFromPlainString( GetGen().GetTitle()) ); } break; case CPub::e_Sub: if( GetSub().IsSetDescr() ) { out_title.push_back( xs_GetTitleFromPlainString( GetSub().GetDescr()) ); } break; case CPub::e_Article: if( GetArticle().IsSetTitle() && GetArticle().GetTitle().IsSet() ) { xs_AppendTitles( out_title, iMaxToGet, GetArticle().GetTitle() ); } break; case CPub::e_Journal: if( GetJournal().IsSetTitle() ) { xs_AppendTitles( out_title, iMaxToGet, GetJournal().GetTitle() ); } break; case CPub::e_Book: if( GetBook().IsSetTitle() ) { xs_AppendTitles( out_title, iMaxToGet, GetBook().GetTitle() ); } break; case CPub::e_Proc: // what to do here? It has a book and meeting // It's not entirely clear if this is the best course of action if( FIELD_CHAIN_OF_2_IS_SET(GetProc(), Book, Title) ) { xs_AppendTitles( out_title, iMaxToGet, GetProc().GetBook().GetTitle() ); } break; case CPub::e_Patent: if( GetPatent().IsSetTitle() ) { out_title.push_back( xs_GetTitleFromPlainString( GetPatent().GetTitle()) ); } break; case CPub::e_Man: if( FIELD_CHAIN_OF_2_IS_SET(GetMan(), Cit, Title) ) { xs_AppendTitles( out_title, iMaxToGet, GetMan().GetCit().GetTitle() ); } break; case CPub::e_Equiv: { size_t iMaxTitleSizeAllowed = ( out_title.size() + iMaxToGet ); if( iMaxTitleSizeAllowed < out_title.size() ) { // integer overflowed iMaxTitleSizeAllowed = std::numeric_limits<std::size_t>::max(); } FOR_EACH_PUB_ON_PUBEQUIV(pub_it, GetEquiv()) { if( out_title.size() >= iMaxTitleSizeAllowed ) { break; } // dig down recursively (*pub_it)->GetTitles(out_title, (iMaxTitleSizeAllowed - out_title.size()) ); } } break; default: NCBI_THROW(CException, eUnknown, "unhandled pub type"); } }