Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taxon Names With/Without-gender filter #4194

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,19 @@ const WITH_PARAMS = [
'data_attributes',
'data_depictions',
'depictions',
'leaves', // 'Descendants'
'etymology',
'global_identifiers',
'leaves',
'not_specified', // 'Incomplete combination relationships'
'latinized',
'local_identifiers',
'nomenclature_date',
'not_specified',
'notes',
'origin_citation',
'original_combination',
'otus',
'tags',
'type_metadata',
'type_metadata', // 'Type information'
'verbatim_name'
]

Expand Down
46 changes: 45 additions & 1 deletion lib/queries/taxon_name/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Filter < Query::Filter
:descendants_max_depth,
:epithet_only,
:etymology,
:latinized,
:leaves,
:name,
:name_exact,
Expand Down Expand Up @@ -264,6 +265,15 @@ class Filter < Query::Filter
# if 'false' then return only names with descendents
attr_accessor :leaves

# @return [Boolean, nil]
# &latinized=<"true"|"false">
# if 'true' then return only genus group names with gender and species
# group names with part of speech
# if 'false' then return only genus group names without gender and
# species group names without part of speech
# if nil, ignore
attr_accessor :latinized

# @return [String, nil]
# &taxon_name_type=<Protonym|Combination|Hybrid>
attr_accessor :taxon_name_type
Expand Down Expand Up @@ -314,6 +324,7 @@ def initialize(query_params)
@descendants_max_depth = params[:descendants_max_depth]
@etymology = boolean_param(params, :etymology)
@epithet_only = params[:epithet_only]
@latinized = boolean_param(params, :latinized)
@geo_json = params[:geo_json]
@leaves = boolean_param(params, :leaves)
@name = params[:name]
Expand Down Expand Up @@ -562,6 +573,38 @@ def leaves_facet
leaves ? ::TaxonName.leaves : ::TaxonName.not_leaves
end

# @return Scope
def latinized_facet
return nil if latinized.nil?

tnc = ::TaxonNameClassification.arel_table
if latinized == true
# Note the query here does not restrict to genus/species groups - a
# genus whose rank is changed to subfamily can retain its gender,
# e.g., and we want to include those here.
::TaxonName.where(
::TaxonNameClassification.where(
tnc[:taxon_name_id].eq(::TaxonName.arel_table[:id]).and(
kleintom marked this conversation as resolved.
Show resolved Hide resolved
tnc[:type].matches('%latinized%')
)
).arel.exists
)
else
::TaxonName
.where(
"rank_class ILIKE '%speciesgroup%' OR \
rank_class ILIKE '%genusgroup%'"
)
.where.not(
::TaxonNameClassification.where(
tnc[:taxon_name_id].eq(::TaxonName.arel_table[:id]).and(
tnc[:type].matches('%latinized%')
kleintom marked this conversation as resolved.
Show resolved Hide resolved
)
).arel.exists
)
end
end

# @return Scope
# wrapped in descendant_facet!
def taxon_name_relationship_facet(hsh)
Expand Down Expand Up @@ -844,12 +887,13 @@ def merge_clauses
combination_taxon_name_id_facet,
combinations_facet,
descendant_facet,
latinized_facet,
leaves_facet,
not_specified_facet,
original_combination_facet,
otu_id_facet,
taxon_name_author_id_facet,
otus_facet,
taxon_name_author_id_facet,
taxon_name_classification_facet,
taxon_name_relationship_type_facet,
type_metadata_facet,
Expand Down
33 changes: 33 additions & 0 deletions spec/lib/queries/taxon_name/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,39 @@
expect(query.all.map(&:id)).to contain_exactly(genus.id, root.id)
end

context '#latinized' do
let!(:fem_genus) {
g = Protonym.create!(name: 'Rosa',
rank_class: Ranks.lookup(:iczn, 'genus'), parent: root)
TaxonNameClassification::Latinized::Gender::Feminine.create!(taxon_name: g)
g
}

let!(:fem_species) {
s = Protonym.create!(
name: 'blanda',
rank_class: Ranks.lookup(:iczn, 'species'),
parent: fem_genus
)
TaxonNameClassification::Latinized::PartOfSpeech::Adjective.create!(taxon_name: s)
s
}

specify '#latinized true' do
query.latinized = true
expect(query.all.map(&:id)).to contain_exactly(
fem_genus.id, fem_species.id
)
end

specify '#latinized false' do
query.latinized = false
expect(query.all.map(&:id)).to contain_exactly(
genus.id, original_genus.id, species.id
)
end
end

specify "#nomenclature_group 1" do
query.nomenclature_group = "Species"
expect(query.all.map(&:id)).to contain_exactly(species.id)
Expand Down