<commit_before>from numpy import uint16


from data_record import DataRecord


class Document(DataRecord):
  def __init__(self, docid):
    DataRecord.__init__( self, docid )
    self.relevances = {}

  def add_relevance(self, relevance):
    self.relevances[ relevance.topic.record_id ] = relevance

  def get_relevance_for_topic(self, topic):
    return self.get_relevance_for_topic_id( topic.record_id )

  def get_relevance_for_topic_id(self, topic_id):
    return self.relevances.get( uint16(topic_id) )

  def is_relevant_for_topic(self, topic):
    return self.is_relevant_for_topic_id( topic.record_id )

  def is_relevant_for_topic_id(self, topic_id):
    return self.get_relevance_for_topic_id( topic_id ).is_relevant()

  def is_highly_relevant_for_topic(self, topic):
    return self.is_highly_relevant_for_topic_id( topic.record_id )

  def is_highly_relevant_for_topic_id(self, topic_id):
    return self.get_relevance_for_topic_id( topic_id ).is_highly_relevant()

  def is_moderately_relevant_for_topic(self, topic):
    return self.is_moderately_relevant_for_topic_id( topic.record_id )

  def is_moderately_relevant_for_topic_id(self, topic_id):
    return self.get_relevance_for_topic_id( topic_id ).is_moderately_relevant()<commit_msg>Use string keys for document's relevance dict<commit_after>import sys


from numpy import uint16


from data_record import DataRecord


class Document(DataRecord):
  def __init__(self, docid):
    DataRecord.__init__( self, docid )
    self.relevances = {}

  def add_relevance(self, relevance):
    self.relevances[ str(relevance.topic.record_id) ] = relevance

  def get_relevance_for_topic(self, topic):
    return self.get_relevance_for_topic_id( topic.record_id )

  def get_relevance_for_topic_id(self, topic_id):
    return self.relevances.get( str(topic_id) )

  def is_relevant_for_topic(self, topic):
    return self.is_relevant_for_topic_id( topic.record_id )

  def is_relevant_for_topic_id(self, topic_id):
    return self.get_relevance_for_topic_id( topic_id ).is_relevant()

  def is_highly_relevant_for_topic(self, topic):
    return self.is_highly_relevant_for_topic_id( topic.record_id )

  def is_highly_relevant_for_topic_id(self, topic_id):
    relevance = self.get_relevance_for_topic_id( topic_id )
    if relevance is None:
      raise RuntimeError( "ERROR: No relevance data found for document %s, topic %s. Available for topics: %s\n" % (self.record_id, topic_id, self.relevances.keys()) )
    return relevance.is_highly_relevant()

  def is_moderately_relevant_for_topic(self, topic):
    return self.is_moderately_relevant_for_topic_id( topic.record_id )

  def is_moderately_relevant_for_topic_id(self, topic_id):
    return self.get_relevance_for_topic_id( topic_id ).is_moderately_relevant()
{'fraction_non_alphanumeric': 0.08174288800864242, 'fraction_numerical': 0.0021606049693914295, 'mean_word_length': 5.614285714285714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5152978', 'n_tokens_mistral': 1024, 'n_tokens_neox': 948, 'n_words': 179}