Skip to content

Commit

Permalink
added a function in Label to correctly get the top-level category by …
Browse files Browse the repository at this point in the history
…aws, this improves on the existing solution of only looking for the top-level category in Label.ParentName, this is achieved by lookin at both ParentName and Name
  • Loading branch information
SiddharthV1 committed Sep 16, 2021
1 parent d756998 commit 234f0e6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/aws/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ pub struct Label {
pub ParentName: String,
}

impl Label {
pub fn get_top_level_category(&self) -> String {
match self.ParentName.is_empty() {
true => self.Name.clone(),
_ => self.ParentName.clone(),
}
}
}

#[derive(Deserialize)]
#[allow(non_snake_case)]
pub struct RekognitionResponse {
Expand All @@ -24,7 +33,7 @@ impl RekognitionResponse {
let labels: HashSet<String> = self
.ModerationLabels
.iter()
.map(|l| l.ParentName.clone())
.map(|l| l.get_top_level_category())
.filter(|l| !l.is_empty())
.collect();
labels
Expand Down

0 comments on commit 234f0e6

Please sign in to comment.