Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
textTransform/funcs.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (41 sloc)
1.2 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!C:\pythonCode | |
# -*- coding: utf-8 -*- | |
# @Time : 2023/2/17 01:42 | |
# @Author : Lertoon Wang | |
# @File : funcs.py | |
# @Software: PyCharm | |
import logging | |
def __sliceFactors(para, dict): | |
""" | |
slice the factors from the control title with 【】 | |
:param para: the paragraph object | |
:return: the dict of factors | |
""" | |
factors = {} | |
# slice the factors | |
factorList = para.text.split("】") | |
for factor in factorList: | |
if factor.startswith("【"): | |
factor = factor[1:] | |
index = factor.find(":") | |
if index != -1: | |
key = dict.get(factor[:index]) | |
value = factor[index + 1:] | |
factors[key] = value | |
return factors | |
def __slicePlainText(para): | |
""" | |
slice the plain text into character and dialogue | |
:param para: the paragraph object | |
:return: the character and dialogue | |
""" | |
index = para.text.find(":") | |
print("the index of : is " + str(index)) | |
if index > 0: | |
character = para.runs[0].text[:index - 1] | |
dialogue = para.runs[0].text[index + 1:] | |
logging.info(character + ":" + dialogue) | |
else: | |
character = "" | |
dialogue = para.runs[0].text[1:] | |
return character, dialogue | |