code: def _GetPathSegmentIndexForOccurrenceWeights(
        self, occurrence_weights, value_weights):
      
      largest_weight = occurrence_weights.GetLargestWeight()
  
      if largest_weight > 0:
        occurrence_weight_indexes = occurrence_weights.GetIndexesForWeight(
            largest_weight)
        number_of_occurrence_indexes = len(occurrence_weight_indexes)
      else:
        number_of_occurrence_indexes = 0
  
      path_segment_index = None
      if number_of_occurrence_indexes == 0:
        path_segment_index = self._GetPathSegmentIndexForValueWeights(
            value_weights)
  
      elif number_of_occurrence_indexes == 1:
        path_segment_index = occurrence_weight_indexes[0]
  
      else:
        largest_weight = 0
  
        for occurrence_index in occurrence_weight_indexes:
          value_weight = value_weights.GetWeightForIndex(occurrence_index)
  
          if not path_segment_index or largest_weight < value_weight:
            largest_weight = value_weight
            path_segment_index = occurrence_index
  
      return path_segment_index
docs: Retrieves the index of the path segment based on occurrence weights.
  
      Args:
        occurrence_weights: the occurrence weights object (instance of
                            _PathSegmentWeights).
        value_weights: the value weights object (instance of _PathSegmentWeights).
  
      Returns:
        An integer containing the path segment index.