Create a chapter
        that contains a random number
        of paragraphs
513718
def write_chapter(self):
        
        self.paragraphs = []
        self.paragraphs.append('\n')
        for x in range(randint(0, 50)):
            p = Paragraph(self.model)
            self.paragraphs.append(p.get_paragraph())
            self.paragraphs.append('\n')
        return self.paragraphs
740069
function(_content,_out){
        if (!_content) return;
        var _lines = _content.split('\n');
        if (!_lines||!_lines.length) return;
        for(var i=0,l=_lines.length,_line;i<l;i++){
            _line = _lines[i];
            if (!!_trim){
                _line = _line.trim();
                if (!_line) continue;
            } 
            _doParseSectionTextLine(_line,_out);
            if (!!_trim&&i<l-1) _out.push('__OUT.push(\'\\n\');');
        }
    }
862847
def create_random_string(length=7, chars='ABCDEFGHJKMNPQRSTUVWXYZ23456789',
                         repetitions=False):
    
    if repetitions:
        return ''.join(random.choice(chars) for _ in range(length))
    return ''.join(random.sample(chars, length))
359158
def paragraphs(self, index = None):
        """"""
        if index is None:
            return self.select(Paragraph)
        else:
            if index < 0:
                index = sum(t.count(Paragraph) for t in self.data) + index
            for t in self.data:
                for i,e in enumerate(t.select(Paragraph)) :
                    if i == index:
                        return e
            raise IndexError
790800
function ( source ) {

		var comment = false;
		var chapters = [];
		var chapter = null;
		var sections = [];
		var section = null;
		var marker = new Showdown.converter ();

		function nextchapter ( title ) {
			if ( chapter ) {
				chapter.sections = sections.map ( function ( section, i ) {
					section.desc = marker.makeHtml ( section.desc );
					return section;
				});
				chapters.push ( chapter );
			}
			chapter = new dox.Chapter ({
				title : title || null
			});
			sections = [];
		}

		function nextsection ( line ) {
			if ( section && section.code ) {
				sections.push ( section );
			}
			section = new dox.Block ({
				line : line || 0,
				tags : [],
				desc : "",
				code : ""
			});
		}

		nextsection ();
		nextchapter ();
		source.split ( "\n" ).forEach ( function ( line, index ) {
			var md, trim = line.trim ();
			if ( comment ) {
				if ( trim.startsWith ( "*/" )) {
					comment = false;
				} else {
					if ( trim === "*" ) {
						section.desc += "\n\n";
					} else {
						md = line.replace ( this._GUTTER, "" );
						switch ( md [ 0 ]) {
							case "@" :
								section.tags.push ( new dox.Tag ({
									text : this._encode ( md )
								}));
								break;
							case "#" :
								//chapter.title = md.replace ( this._HEADER, "" );
								section.desc += "\n" + md + "\n\n";
								break;
							default :
								if ( !md.match ( this._LETTER )) {
									section.desc += "\n";
								}
								section.desc += this._encode ( md );
								break;
						}
					}
				}
			} else {
				if ( line.match ( this._CHAPTER )) {
					var title = this._TITLE.exec ( line );
					nextsection ( index );
					nextchapter ( title ? title [ 0 ] : null );
					section.code += this._HELLO.exec ( line );
				} else {
					if ( trim.startsWith ( "/**" )) {
						comment = true;
						nextsection ( index );
					} else {
						section.code += line + "\n";
					}
				}
			}
		}, this );
		nextsection ();
		nextchapter ();
		return chapters;
	}
603761
def paragraph_texts(self):
        """"""
        if not self.is_tagged(PARAGRAPHS):
            self.tokenize_paragraphs()
        return self.texts(PARAGRAPHS)
916571
def create_random_context(dialog, rng, minimum_context_length=2, max_context_length=20):
    
    # sample dialog context
    #context_turns = rng.randint(minimum_context_length,len(dialog)-1)
    max_len = min(max_context_length, len(dialog)) - 2
    if max_len <= minimum_context_length:
        context_turns = max_len
    else:
        context_turns = rng.randint(minimum_context_length, max_len)

    # create string
    return dialog_turns_to_string(dialog[:context_turns]), context_turns
408801
private static void splitInSentences(HashSet<String> sentencesSet, String text) {
		
		if (inputType == inputTypes.PARAGRAPH) { // split in multiple sentences
			LinkedList<LinkedList<Word>> sentences = Splitting.tokenizeSentences(LVMorphologyReaderAndWriter.getAnalyzer(), text);
			for (LinkedList<Word> sentence : sentences) 
			{
				if(sentence != null)
				{
					String madeSentence = "";
					for(int w = 0; w < sentence.size(); w++)
					{
						madeSentence = madeSentence + " " + sentence.get(w);
					}
					madeSentence = madeSentence.trim();
					//pārbaudam, vai teikuma atšķiribas nav punkts teikuma beigas
					if(madeSentence.length() > 0 && madeSentence.lastIndexOf(".") >= 0) madeSentence = madeSentence.substring(0, madeSentence.length() - 1);
					sentencesSet.add(madeSentence.trim());
				}
			}
		} 
	}
747244
def instantiate(self, value_of_n):
        """"""
        template = Cheetah.Template.Template(
            self.content,
            searchList={'n': value_of_n}
        )
        template.random_string = random_string
        return str(template)
1366488
def process_text(self, kind, context):
		""""""
		
		result = None
		
		while True:
			chunk = yield None
			
			if chunk is None:
				if result:
					yield result.clone(line=repr(result.line))
				
				return
			
			if not result:
				result = chunk
				continue
			
			result.line += chunk.line
600763
def randomprune(self,n):
        """"""
        self.data = random.sample(self.data, n)
909178
function genTree (toc, maxLevel) {
  var headlines = [];
  var last = {};

  toc.forEach(function (headline) {
    var level = headline.level || 1;
    var len = level - 1;

    if (level > maxLevel) { return }
    if (last[len]) {
      last[len].children = (last[len].children || []).concat(headline);
    } else {
      headlines.push(headline);
    }
    last[level] = headline;
  });

  return headlines
}
356521
def _random_fill(self):
        """"""
        a = self._array
        for p, tile in self.positions_with_tile():
            if tile.is_blank():
                a[p] = Tile.random_tile()
1145670
def make_random_xml_file(fname, num_elements=200, depth=3):
    
    with open(fname, 'w') as f:
        f.write('<?xml version="1.0" ?>\n<random>\n')
        for dep_num, _ in enumerate(range(1,depth)):
            f.write(' <depth>\n  <content>\n')
            #f.write('<depth' + str(dep_num) + '>\n')
            for num, _ in enumerate(range(1, num_elements)):
                f.write('    <stuff>data line ' + str(num) + '</stuff>\n')
            #f.write('</depth' + str(dep_num) + '>\n')
            f.write('  </content>\n </depth>\n')
    
        f.write('</random>\n')
41096
def get_paragraph(self):
        
        self.text = ''
        for x in range(randint(5, 12)):
            sentence = self._write_sentence()
            self.text = self.text + sentence
        return self.text
7425
def _fill_text(self, text, width=None, indent=None):
        
        assert isinstance(text, str)
        if indent is None:
            indent = NBSP * self._current_indent
        assert isinstance(indent, str)
        paragraphs = []
        line_buf = []
        pre = ''
        for fragment in text.splitlines():
            pre_indent = self.leadingws.match(fragment)
            if not fragment or pre_indent:
                if line_buf:
                    line = ' '.join(line_buf)
                    paragraphs.append((pre, self.whitespace.sub(' ', line)))
                if not fragment:
                    paragraphs.append(('', ''))
                else:
                    pre = pre_indent.group()
                    fragment = self.leadingws.sub('', fragment)
                    paragraphs.append((pre, fragment))
                line_buf = []
                pre = ''
            else:
                line_buf.append(fragment)
        if line_buf:
            line = ' '.join(line_buf)
            paragraphs.append((pre, self.whitespace.sub(' ', line)))
        indent = VTMLBuffer(indent)
        nl = VTMLBuffer('\n')
        if width is None:
            width = self._width - len(indent)
        lines = []
        for pre, paragraph in paragraphs:
            pwidth = width - len(pre)
            lines.append(nl.join((indent + pre + x)
                         for x in vtmlrender(paragraph).wrap(pwidth)))
        return nl.join(lines)
119616
public static function create_from_chapter(\stdClass $book, \context_module $context, \stdClass $chapter) {
        $data = array(
            'context' => $context,
            'objectid' => $chapter->id,
        );
        /** @var chapter_printed $event */
        $event = self::create($data);
        $event->add_record_snapshot('book', $book);
        $event->add_record_snapshot('book_chapters', $chapter);
        return $event;
    }