#NEWLINE# def random_corpus( corpus_len , n_words , min_token_len , max_token_len , context_type = 'document' , metadata = False , seed = None ) : #NEWLINE# #INDENT# "\n    Generates a random integer corpus.\n\n    :param corpus_len: Size of the Corpus.\n    :type corpus_len: int\n\n    :param n_words: Number of words to draw random integers from.\n    :type n_words: int\n\n    :param min_token_len: minimum token length used to create indices\n        for corpus.\n    :type min_token_len: int\n\n    :param max_token_len: maximum token length used to create indices\n        for corpus.\n    :type max_token_len: int\n\n    :param context_type: A type of tokenization. Default is 'document'.\n    :type context_type: string, optional\n\n    :param metadata: If `True` generates metadata. If `False` the only\n        metadata for the corpus is the index information.\n    :type metadata: boolean, optional\n    \n    :param tokenizer: word tokenization function. Defaults to `vsm.extensions.corpusbuilders.util.word_tokenize`.\n    :type tokenizer: lambda s -> tokens\n\n    :returns: Corpus object with random integers as its entries. \n\n    :See Also: :class:`vsm.corpus.Corpus`\n    " #NEWLINE# random_state = np . random . RandomState ( seed ) #NEWLINE# corpus = random_state . randint ( n_words , size = corpus_len ) #NEWLINE# indices = [ ] #NEWLINE# i = np . random . randint ( min_token_len , max_token_len ) #NEWLINE# while ( i < corpus_len ) : #NEWLINE# #INDENT# indices . append ( i ) #NEWLINE# i += np . random . randint ( min_token_len , max_token_len ) #NEWLINE# #UNINDENT# indices . append ( corpus_len ) #NEWLINE# if metadata : #NEWLINE# #INDENT# metadata_ = [ '{0}_{1}' . format ( context_type , i ) for i in xrange ( len ( indices ) ) ] #NEWLINE# dtype = [ ( 'idx' , np . array ( indices ) . dtype ) , ( ( context_type + '_label' ) , np . array ( metadata_ ) . dtype ) ] #NEWLINE# rand_tok = np . array ( zip ( indices , metadata_ ) , dtype = dtype ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rand_tok = np . array ( [ ( i , ) for i in indices ] , dtype = [ ( 'idx' , np . array ( indices ) . dtype ) ] ) #NEWLINE# #UNINDENT# return Corpus ( corpus , context_types = [ context_type ] , context_data = [ rand_tok ] )