2

I am building an app that search for anime quotes. So, I have the following data, which is 331 Objects (which I call them 'Quote Cards') long and so it will also be updated in future as I add more and more quotes. The problem I having is in creating concepts for JS's array items such as keywords, and imageTag. and also the the character names which are listed as property. I am also willing to change the output as long as I can keep category, and keywords array items. Those are necessary for my quote cards

[
  {
    $id: "Cold_Souls_1",
    animeTitle: "Fullmetal Alchemist Brotherhood",
    animePoster:{
      referenceImage: 'https://qph.fs.quoracdn.net/main-qimg-da58c837c7197acf364cb2ada34fc5fb.webp',
      imageTags: ["Grey","Yellow","Blue","Metal Body","Machine", "Robot","Yellow Hair Boy"],
    },
    animeCharacters:{
      "Edward Elric": [
        {
          quote: "A lesson without pain is meaningless. For you cannot gain something without sacrificing something else in return. But once you have recovered it and made it your own... You will gain an irreplaceable Fullmetal heart.",
          keywords: ["lesson", "pain", "return", "meaningless", "gain","sacrificing", "recover"],
          category: "Life Lesson"
        }
      ]
    }
  },....................
]

1 Answers1

4

In Bixby, you would model a structure that represents the JSON response.

structure (Anime) {
  description (The output of your action)

  property (title) {
    type(viv.core.Text)
    visibility (Private)
  }

  property (poster){
    type(AnimePoster)
    visibility (Private)
  }

  property (characters) {
    type (AnimeCharacter)
    max (Many)
    visibility (Private)
  }

}

structure (AnimePoster) {

  property (referenceImage) {
    type (viv.core.Text)
    visibility (Private)
  }

  property (imageTags) {
    type (viv.core.Text)
    max (Many)
    visibility (Private)
  }

}


structure (AnimeCharacter) {

  property (name) {
    type (viv.core.Text)
    visibility (Private)
  }

  property (quote) {
    type (viv.core.Text)
    visibility (Private)
  }

  property (keywords) {
    type (viv.core.Text)
    max (Many)
    visibility (Private)
  }

  property (category) {
    type (viv.core.Text)
    visibility (Private)
  }

}

In your javascript file, you process the JSON structure of animes

// listOfAnimes is the JSON  object described in the question

var animes = [];

listOfAnimes.forEach((anime) => {

    var characterNames = Object.keys(anime.animeCharacters);
    var characters = [];

      Object.keys(anime.animeCharacters).forEach((key) => {
           characters.push({
             name: key,
             quote: anime.animeCharacters[key][0].quote, // * warning, can be many
             category: anime.animeCharacters[key][0].category// * warning, can be many
           });
    });

    animes.push( {
       $id: anime.$id,
       title: anime.title,
       characters: characters,
       poster: {
         referenceImage: anime.animePoster.referenceImage,
         imageTags: anime.animePoster.imageTags
       },

    });

});

enter image description here

Pete Haas
  • 1,800
  • 1
  • 12
  • 15
  • So I see I need to move character's name inside the quote Object using javascript. But Why is visibility private? – Nilay Patel Nov 15 '19 at 02:39
  • 1
    visibility(Private) hides the property from the planner. The benefit in this case is that you aren't forced to create a bunch of custom concepts to your model to return primitive properties like text, boolean, etc. – Pete Haas Nov 15 '19 at 02:45
  • I read docs, but would property projection would be helpful if user asked to remind them about the name of the character or title of the show. in those cases the property projections would be helpful as it would take the anime quote card as whole and outputs specific value. – Nilay Patel Nov 15 '19 at 02:56
  • Correct, if you plan to use the property as a projection or input to another action, you can model a custom concept. I find it faster to model my structures with visibility(Private) and get the results returned from the action first. – Pete Haas Nov 15 '19 at 13:06
  • Also One more question, very last. So we are not required to state structure property for any variable that follows $ symbol? Like $id in this case? Or $vivContext – Nilay Patel Nov 15 '19 at 18:24
  • 1
    No $ has no effect - used in $vivContext to denote it being an platform provided object – rogerkibbe Nov 17 '19 at 20:56