def p_boolean_sliding_window(texts, segmented_topics, dictionary, window_size):
 top_ids = _ret_top_ids(segmented_topics)
 window_id = 0
 per_topic_postings = {}
 token2id_dict = dictionary.token2id
 def add_topic_posting(top_ids, window, per_topic_postings, window_id, token2id_dict):
  for word in window:
   word_id = token2id_dict[word]
   if (word_id in top_ids):
    if (word_id in per_topic_postings):
     per_topic_postings[word_id].add(window_id)
    else:
     per_topic_postings[word_id] = set([window_id])
  window_id += 1
  return (window_id, per_topic_postings)
 for document in texts:
  it = iter(document)
  window = tuple(islice(it, window_size))
  (window_id, per_topic_postings) = add_topic_posting(top_ids, window, per_topic_postings, window_id, token2id_dict)
  for elem in it:
   window = (window[1:] + (elem,))
   (window_id, per_topic_postings) = add_topic_posting(top_ids, window, per_topic_postings, window_id, token2id_dict)
 return (per_topic_postings, window_id)

def p_boolean_sliding_window ( texts , segmented_topics , dictionary , window_size ) : top_ids = _ret_top_ids ( segmented_topics ) window_id = 0 per_topic_postings = { } token2id_dict = dictionary . token2id def add_topic_posting ( top_ids , window , per_topic_postings , window_id , token2id_dict ) : for word in window : word_id = token2id_dict [ word ] if ( word_id in top_ids ) : if ( word_id in per_topic_postings ) : per_topic_postings [ word_id ] . add ( window_id ) else : per_topic_postings [ word_id ] = set ( [ window_id ] ) window_id += 1 return ( window_id , per_topic_postings ) for document in texts : it = iter ( document ) window = tuple ( islice ( it , window_size ) ) ( window_id , per_topic_postings ) = add_topic_posting ( top_ids , window , per_topic_postings , window_id , token2id_dict ) for elem in it : window = ( window [ 1 : ] + ( elem , ) ) ( window_id , per_topic_postings ) = add_topic_posting ( top_ids , window , per_topic_postings , window_id , token2id_dict ) return ( per_topic_postings , window_id )
this function performs the boolean sliding window probability estimation .