Пример #1
0
 def testRatingDuplicateCommands(self, results_data, command_kwargs,
                                 found_command_kwargs, expected_rating):
     results = search_util.CommandSearchResults(results_data)
     command = self.DummyCommand(**command_kwargs)
     found_commands = []
     for kwargs in found_command_kwargs:
         found_commands.append(self.DummyCommand(**kwargs))
     self.assertEqual(expected_rating,
                      rater.CommandRater(results, command).Rate())
Пример #2
0
 def testProcessResult(self, results_data):
   # Test that result 'commands' and 'result' are correctly set.
   version_command = self.parent.get(lookup.COMMANDS, {}).get('version', {})
   result = search_util.ProcessResult(
       version_command,
       search_util.CommandSearchResults(results_data))
   self.assertEqual([], result.get(lookup.COMMANDS))
   # The results are the same for both cases because only found terms are
   # shown.
   self.assertEqual({'term1': lookup.NAME},
                    result.get(lookup.RESULTS))
Пример #3
0
    def testCumulativeRater(self):
        cumulative_rater = rater.CumulativeRater()
        command1 = self.DummyCommand(release=lookup.GA,
                                     results={'t': 'section.EXAMPLES'})
        command2 = self.DummyCommand(release=lookup.BETA,
                                     results={'t': 'sections.NAME'})
        command3 = self.DummyCommand(release=lookup.ALPHA,
                                     results={'t': 'sections.PATH'})

        cumulative_rater.AddFoundCommand(
            command1, search_util.CommandSearchResults({'t': 'examples'}))
        cumulative_rater.AddFoundCommand(
            command2, search_util.CommandSearchResults({'t': 'name'}))
        cumulative_rater.RateAll()
        cumulative_rater.AddFoundCommand(
            command3, search_util.CommandSearchResults({'t': 'path'}))
        cumulative_rater.RateAll()

        self.assertEqual(0.25, command1[lookup.RELEVANCE])
        self.assertEqual(1, command2[lookup.RELEVANCE])
        self.assertEqual(0.5, command3[lookup.RELEVANCE])
Пример #4
0
    def _PossiblyGetResult(self, command):
        """Helper function to determine whether a command contains all terms.

    Returns a copy of the command or command group with modifications to the
    'commands' field and an added 'summary' field if the command matches
    the searcher's search terms.

    Args:
      command: dict, a json representation of a command.

    Returns:
      a modified copy of the command if the command is a result, otherwise None.
    """
        locations = [
            search_util.LocateTerm(command, term) for term in self.terms
        ]
        if any(locations):
            results = search_util.CommandSearchResults(
                dict(zip(self.terms, locations)))
            new_command = search_util.ProcessResult(command, results)
            self._rater.AddFoundCommand(new_command, results)
            return new_command
Пример #5
0
 def testRatingMultipleLocations(self, results_data, expected_rating):
     results = search_util.CommandSearchResults(results_data)
     command = self.DummyCommand()
     self.assertEqual(expected_rating,
                      rater.CommandRater(results, command).Rate())
Пример #6
0
 def testRatingSomeTermsNotFound(self, results_data, expected_rating):
     results = search_util.CommandSearchResults(results_data)
     command = self.DummyCommand()
     self.assertEqual(expected_rating,
                      rater.CommandRater(results, command).Rate())
Пример #7
0
 def testRatingSingleLocation(self, location, expected_rating):
     results = search_util.CommandSearchResults({'t': location})
     command = self.DummyCommand()
     self.assertEqual(expected_rating,
                      rater.CommandRater(results, command).Rate())