def create_paragraph(self): current_paragraph = None if len(self.bookTokens) > 0 and self.structs.has_key("p"): current_paragraph = Token( id = uuid4(), data = u"\u2029", #¶ "\n\n" type = Token.WHITESPACE, #i.e. PARAGRAPH work = self.work1, position = self.tokenCount, ) self.tokenCount += 1 current_paragraph.save() self.structs["p"].end_marker = current_paragraph self.close_structure("p") self.bookTokens.append(current_paragraph) assert(not self.structs.has_key("p")) print("¶") self.structs["p"] = Structure( work = self.work1, element = "p", position = self.structCount, ) if current_paragraph: self.structs["p"].start_marker = current_paragraph self.structCount += 1
def create_punct_token(self, punct_data): punc_token = Token( id = uuid4(), data = punct_data, type = Token.PUNCTUATION, work = self.work1, position = self.tokenCount, ) self.tokenCount += 1 punc_token.save() self.bookTokens.append(punc_token)
def create_whitespace_token(self): ws_token = Token( id = uuid4(), data = " ", type = Token.WHITESPACE, work = self.work1, position = self.tokenCount, ) self.tokenCount += 1 ws_token.save() self.bookTokens.append(ws_token)
def create_token(self, token_data): word_token = Token( id = uuid4(), data = token_data, type = Token.WORD, work = self.work1, position = self.tokenCount, ) self.tokenCount += 1 word_token.save() self.bookTokens.append(word_token)
def create_uncertain(self): assert(not self.structs.has_key('doubted')) print("### OPEN BRACKET") open_bracket_token = Token( id = uuid4(), data = '[', type = Token.PUNCTUATION, work = self.work1, position = self.tokenCount ) self.tokenCount += 1 open_bracket_token.save() self.bookTokens.append(open_bracket_token) self.structs['doubted'] = Structure( work = self.work1, element = 'doubted', position = self.structCount, start_marker = open_bracket_token ) self.structCount += 1