Skip to content

Commit

Permalink
modified select() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kosloot committed Dec 4, 2024
1 parent 6841bb2 commit 59c2d6a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
30 changes: 15 additions & 15 deletions include/libfolia/folia_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ namespace folia {
// Selections

template <typename F>
std::vector<F*> select( const std::string& st,
const std::set<ElementType>& exclude,
bool recurse = true ) const {
std::vector<F*> select( const std::string& st,
const std::set<ElementType>& exclude,
SELECT_FLAGS flag = SELECT_FLAGS::RECURSE ) const {
std::vector<FoliaElement*> tmp = select( F::PROPS.ELEMENT_ID,
st,
exclude,
(recurse?SELECT_FLAGS::RECURSE : SELECT_FLAGS::LOCAL) );
flag );
std::vector<F*> res;
for ( size_t i = 0; i < tmp.size(); ++i ){
res.push_back( dynamic_cast<F*>( tmp[i]) );
Expand All @@ -201,11 +201,11 @@ namespace folia {
}

template <typename F>
std::vector<F*> select( const std::string& st,
bool recurse = true ) const {
std::vector<F*> select( const std::string& st,
SELECT_FLAGS flag = SELECT_FLAGS::RECURSE ) const {
std::vector<FoliaElement*> tmp = select( F::PROPS.ELEMENT_ID,
st,
(recurse?SELECT_FLAGS::RECURSE : SELECT_FLAGS::LOCAL) );
flag );
std::vector<F*> res;
for ( size_t i = 0; i < tmp.size(); ++i ){
res.push_back( dynamic_cast<F*>( tmp[i]) );
Expand All @@ -214,11 +214,11 @@ namespace folia {
}

template <typename F>
std::vector<F*> select( const char *st,
bool recurse = true ) const {
std::vector<F*> select( const char *st,
SELECT_FLAGS flag = SELECT_FLAGS::RECURSE ) const {
std::vector<FoliaElement*> tmp = select( F::PROPS.ELEMENT_ID,
std::string(st),
(recurse?SELECT_FLAGS::RECURSE : SELECT_FLAGS::LOCAL) );
flag );
std::vector<F*> res;
for ( size_t i = 0; i < tmp.size(); ++i ){
res.push_back( dynamic_cast<F*>( tmp[i]) );
Expand All @@ -227,11 +227,11 @@ namespace folia {
}

template <typename F>
std::vector<F*> select( const std::set<ElementType>& exclude,
bool recurse = true ) const {
std::vector<F*> select( const std::set<ElementType>& exclude,
SELECT_FLAGS flag = SELECT_FLAGS::RECURSE ) const {
std::vector<FoliaElement*> tmp = select( F::PROPS.ELEMENT_ID,
exclude,
(recurse?SELECT_FLAGS::RECURSE : SELECT_FLAGS::LOCAL) );
flag );
std::vector<F*> res;
for ( size_t i = 0; i < tmp.size(); ++i ){
res.push_back( dynamic_cast<F*>( tmp[i]) );
Expand All @@ -240,9 +240,9 @@ namespace folia {
}

template <typename F>
std::vector<F*> select( bool recurse = true ) const {
std::vector<F*> select( SELECT_FLAGS flag = SELECT_FLAGS::RECURSE ) const {
std::vector<FoliaElement*> tmp = select( F::PROPS.ELEMENT_ID,
(recurse?SELECT_FLAGS::RECURSE : SELECT_FLAGS::LOCAL) );
flag );
std::vector<F*> res;
for ( size_t i = 0; i < tmp.size(); ++i ){
res.push_back( dynamic_cast<F*>( tmp[i]) );
Expand Down
11 changes: 7 additions & 4 deletions src/folia_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ namespace folia {
* search for Description nodes in this object.
* When 1 or more are found, return the value of the first one
*/
vector<Description*> v = select<Description>( false );
vector<Description*> v = select<Description>( SELECT_FLAGS::LOCAL );
if ( v.size() == 0 ) {
return "";
}
Expand Down Expand Up @@ -2155,7 +2155,9 @@ namespace folia {
* Might return "" when no match is found
*/
set<ElementType> exclude;
vector<LangAnnotation*> v = select<LangAnnotation>( st, exclude, false );
vector<LangAnnotation*> v = select<LangAnnotation>( st,
exclude,
SELECT_FLAGS::LOCAL );
if ( v.size() > 0 ){
return v[0]->cls();
}
Expand Down Expand Up @@ -3199,7 +3201,7 @@ namespace folia {
* is empty
* \return all targets found
*/
auto PIS = select<ProcessingInstruction>(false);
auto PIS = select<ProcessingInstruction>(SELECT_FLAGS::LOCAL);
if ( target.empty() ){
return PIS;
}
Expand Down Expand Up @@ -3324,7 +3326,8 @@ namespace folia {
if ( isinstance<TextContent>() ){
string my_cls = cls();
string st = sett();
vector<TextContent*> tmp = parent->select<TextContent>( st, false );
vector<TextContent*> tmp = parent->select<TextContent>( st,
SELECT_FLAGS::LOCAL );
if ( any_of( tmp.cbegin(),
tmp.cend(),
[my_cls]( const TextContent *t) { return ( t->cls() == my_cls);} ) ){
Expand Down
18 changes: 9 additions & 9 deletions src/folia_subclasses.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ namespace folia {
*/
vector<FoliaElement *> result;
vector<TextContent*> v = par->FoliaElement::select<TextContent>( sett(),
false );
SELECT_FLAGS::LOCAL );
copy_if( v.begin(),
v.end(),
back_inserter(result),
Expand Down Expand Up @@ -2361,7 +2361,7 @@ namespace folia {
}
if ( e ){ // cppcheck-suppress knownConditionTrueFalse
// false positive. e can be changed in previous if statement
vector<Word*> wv = e->select<Word>(false);
vector<Word*> wv = e->select<Word>(SELECT_FLAGS::LOCAL);
if ( !wv.empty() ){
const FoliaElement *last = wv.back();
// DBG << "Correction::space!" << last << " ==> "
Expand All @@ -2374,7 +2374,7 @@ namespace folia {

bool Correction::hasNew() const {
/// check if this Correction has a New node
vector<New*> v = select<New>(false);
vector<New*> v = select<New>(SELECT_FLAGS::LOCAL);
return !v.empty();
}

Expand All @@ -2383,7 +2383,7 @@ namespace folia {
/*!
* \return the new node or 0 if not available
*/
vector<New*> v = FoliaElement::select<New>( false );
vector<New*> v = FoliaElement::select<New>(SELECT_FLAGS::LOCAL);
if ( v.empty() ) {
return 0;
}
Expand All @@ -2406,7 +2406,7 @@ namespace folia {

bool Correction::hasOriginal() const {
/// check if this Correction has an Original node
vector<Original*> v = select<Original>(false);
vector<Original*> v = select<Original>(SELECT_FLAGS::LOCAL);
return !v.empty();
}

Expand All @@ -2415,7 +2415,7 @@ namespace folia {
/*!
* \return the new node or 0 if not available
*/
vector<Original*> v = select<Original>( false );
vector<Original*> v = select<Original>(SELECT_FLAGS::LOCAL);
if ( v.empty() ) {
return 0;
}
Expand All @@ -2438,7 +2438,7 @@ namespace folia {

bool Correction::hasCurrent( ) const {
/// check if this Correction has a New node
vector<Current*> v = select<Current>(false);
vector<Current*> v = select<Current>(SELECT_FLAGS::LOCAL);
return !v.empty();
}

Expand All @@ -2447,7 +2447,7 @@ namespace folia {
/*!
* \return the new node or 0 if not available
*/
vector<Current*> v = FoliaElement::select<Current>( false );
vector<Current*> v = FoliaElement::select<Current>(SELECT_FLAGS::LOCAL);
if ( v.empty() ) {
return 0;
}
Expand Down Expand Up @@ -2476,7 +2476,7 @@ namespace folia {

vector<Suggestion*> Correction::suggestions( ) const {
/// get all Suggestion nodes of this Correction
return FoliaElement::select<Suggestion>( false );
return FoliaElement::select<Suggestion>(SELECT_FLAGS::LOCAL);
}

Suggestion *Correction::suggestions( size_t index ) const {
Expand Down

0 comments on commit 59c2d6a

Please sign in to comment.