Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Search the Rulebooks by Meaning

In this video, you put players’ questions to search() and printed the rank, score, game, page and heading of every chunk that came back. Two questions found the page that answers them. A third, which names a card number, didn’t, and reading the chunks’ text showed where its card ranked.

Key Points

  • See what the search found. Later in the course, the rules desk answers from the chunks search() returns, so a page that isn’t among them can’t be used. A printout shows which chunks came back, from which game and page, and with what score.
  • One line per result. printResults() prints the question, then, for each result, its rank (starting at 1), its score to three decimal places, and its game, page and heading, or no heading if there isn’t one.
  • Two questions, two right pages. Table 6’s Lantern Harbor question puts page 4, Trading, on top at 0.663. That’s the page with the pier rule, and the seating rule’s chunk comes second. Question 3’s Copper Canyon Express tie puts page 7, Breaking a Tie, on top at 0.719, the last page that a whole-book vector never reached. All six results come from the game each question names.
  • A miss. A new question from table 5 asks whether card 17 changes how many shells the market wants in Tidepool Traders. Its top three are page 4, Trading, page 1, Components, and page 5, Scoring. Page 4 has the market’s rate, so it belongs there, but card 17 is on page 3, under Tide Cards, and that page isn’t in the list. Given only these chunks, a model may make up a rule for card 17, as it did in the first lesson.
  • A score can’t confirm a page. The miss’s top score, 0.641, is close to the 0.663 that found the pier rule. A score ranks chunks for one question. It can’t tell you whether the right page came back.
  • Raise k, then read the text. With k at 6, page 3 shows up twice, because its Tide Cards section is two chunks. A loop prints the rank, id and text of each page 3 result. The one in sixth place, at 0.580, tidepool-traders-6, has card 17’s rule in full, and the fifth, tidepool-traders-7, has only its last words. A bigger k helps you look for a missing chunk, but it isn’t the fix. It sends more text with each question, and the search still ranks card 17’s chunk below five others, even the components list.

The rule:

  • Print rank, score, game and page, and check them against the chunk that answers the question.
  • Missing? Raise k to see where it ranked, and read its text.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 In the last lesson, you wrote search(). It scores a player’s question against all 90 chunks. Now you’ll put players’ questions to it and look at what comes back.

00:11 Later, the rules desk will answer from the chunks that search() returns. If the page that answers a question isn’t among them, the answer can’t use it. So you need to see which chunks came back, from which game and page, and with what score.

00:26 Create a new file, search-rulebooks.js, that imports search() from the last lesson. Then write a helper, printResults, that takes a question and its results.

00:38 It prints the question first. Then, for each result, it pulls out the score, game, page and heading, and builds where the chunk came from, or “no heading” if there isn’t one.

00:50 It prints the rank, the score to three decimal places, and where. Below the helper, the script reads questions.json and picks two questions by id: 10 and 3.

01:02 For each one, it searches for the top three chunks and prints them.

01:08 Run it. The first question is table 6’s, from Lantern Harbor: can they trade fish for oil with someone who isn’t next to them? search() embeds it, scores all 90 chunks, and sorts them.

01:20 The top three print. First is Lantern Harbor, page 4, Trading, at 0.663. That’s the pier rule, which answers it. Second is the next chunk of the same section, with the seating rule.

01:36 Question 3 asks who wins a tie in Copper Canyon Express. Its top result is page 7, Breaking a Tie, at 0.719. That’s the last page, the one a whole-book vector never reached.

01:50 All six results come from the game each question names. And the right page is on top both times.

01:58 A new player at table 5 asks something that isn’t in questions.json. In Tidepool Traders, does card 17 change how many shells the market wants? Add the question at the end of the script, search for its top three, and print them.

02:14 Run the script again. For the new question, page 4, Trading, comes first, at 0.641. It has the market’s rate, so it belongs here. Then come page 1, Components, and page 5, Scoring.

02:29 But card 17 is on page 3, under Tide Cards, and that page isn’t in the list. Given only these chunks, a model may make up a rule for card 17, as it did in the first lesson.

02:42 That top score, 0.641, is close to the 0.663 that found the pier rule. A score ranks chunks for one question. It can’t tell you the right page came back.

02:56 To see where it ranked, change k to 6. And since card 17 is on page 3, add a loop that prints the rank, id and text of any page 3 result. Run it again. Page 3 shows up at last, twice, because its Tide Cards section is two chunks.

03:16 The one in sixth place, at 0.580, has card 17’s rule in full. The fifth has only its last words.

03:26 A bigger k helps you look for a missing chunk, but it isn’t the fix. It sends more text with each question, and the search still ranks card 17’s chunk below five others, even the components list.

03:40 So, print each result’s rank, score, game and page, and check them against the chunk that answers the question. When it’s missing, raise k to find where it ranked, and read its text.

03:53 Run this check while you build, on test questions whose answer you’ve looked up, as you did here. Then you know whether to trust search() before players use it.

04:03 Two of the three questions found their page. The one about card 17 didn’t. The next lesson, Catch Exact Names and Numbers, shows why, and adds a step to search() that catches questions like it.

Become a Member to join the conversation.