This commit is contained in:
parent
2fea6c4c80
commit
d9231fa131
|
@ -5,15 +5,9 @@
|
|||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="f609c0f2-cd0d-4eea-87f1-8caf02d3f04f" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/StoryTools.iml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/entry.py" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/parse/__init__.py" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/parse/ast_load.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/entry.py" beforeDir="false" afterPath="$PROJECT_DIR$/entry.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/parse/ast_load.py" beforeDir="false" afterPath="$PROJECT_DIR$/parse/ast_load.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -43,11 +37,41 @@
|
|||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"Python.entry.executor": "Run",
|
||||
"Python.ast_load.executor": "Debug",
|
||||
"Python.entry.executor": "Debug",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"git-widget-placeholder": "master"
|
||||
}
|
||||
}]]></component>
|
||||
<component name="RunManager">
|
||||
<configuration name="entry" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="StoryTools" />
|
||||
<option name="ENV_FILES" value="" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<option name="IS_MODULE_SDK" value="true" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/entry.py" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Python.entry" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
|
|
8
entry.py
8
entry.py
|
@ -1,8 +1,8 @@
|
|||
from PyQt5.QtWidgets import QWidget, QApplication
|
||||
from sys import argv
|
||||
from parse.ast_load import global_ast_path, AstParse
|
||||
|
||||
|
||||
app = QApplication(argv)
|
||||
win = QWidget()
|
||||
win.show()
|
||||
app.exec()
|
||||
tool = AstParse(global_ast_path)
|
||||
print(tool.generate_time())
|
||||
tool.peak_storylines()
|
Binary file not shown.
Binary file not shown.
|
@ -1,14 +1,93 @@
|
|||
from lxml import etree
|
||||
from typing import List
|
||||
|
||||
|
||||
class ast_parse():
|
||||
global_ast_path = r"E:\storyline.xast"
|
||||
|
||||
|
||||
def items_filter(items, proc):
|
||||
values = []
|
||||
for it in items:
|
||||
if proc(it):
|
||||
values.append(it)
|
||||
pass
|
||||
pass
|
||||
return values
|
||||
|
||||
|
||||
class FragmentSlice():
|
||||
def __init__(self, signature: str):
|
||||
self.signature = signature
|
||||
self.text_sections = []
|
||||
pass
|
||||
|
||||
def append_text_section(self, section: str):
|
||||
self.text_sections.append(section)
|
||||
pass
|
||||
|
||||
|
||||
class StorySlice():
|
||||
def __init__(self, signature: str):
|
||||
self.signature = signature
|
||||
self.text_sections = []
|
||||
self.fragment_slices = []
|
||||
pass
|
||||
|
||||
def append_text_section(self, section: str):
|
||||
self.text_sections.append(section)
|
||||
pass
|
||||
|
||||
def append_fragment_slice(self, slice: FragmentSlice):
|
||||
self.fragment_slices.append(slice)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class AstParse():
|
||||
def __init__(self, ast_path: str):
|
||||
self.ast_path = ast_path
|
||||
ast_file = open(ast_path, "rt")
|
||||
ast_file = open(ast_path, "rb")
|
||||
ast_text = ast_file.read()
|
||||
self.ast_inst = etree.XML(ast_text)
|
||||
pass
|
||||
|
||||
def generate_time(self)-> str:
|
||||
self.ast_inst.xpath
|
||||
def generate_time(self) -> str:
|
||||
attr_time = self.ast_inst.xpath("/ast[1]/@time")[0]
|
||||
return str(attr_time)
|
||||
|
||||
def peak_storylines(self) -> List[StorySlice]:
|
||||
story_list = self.ast_inst.xpath("/ast/story") # 获取所有故事节点
|
||||
|
||||
story_items = []
|
||||
for story in story_list:
|
||||
story_name = story.xpath("@name")[0]
|
||||
story_slice = StorySlice("story:"+story_name)
|
||||
story_items.append(story_slice)
|
||||
|
||||
story_text_lines = story.xpath("text-section/@text") # 获取所有描述
|
||||
for line in story_text_lines:
|
||||
story_slice.append_text_section(line)
|
||||
pass
|
||||
|
||||
fragment_items = story.xpath("fragment") # 获取所有情节定义
|
||||
for fragm in fragment_items:
|
||||
fragment_name = fragm.xpath("@name")
|
||||
fragm_slice = FragmentSlice("fragment:"+story_name+"#"+fragment_name)
|
||||
fragm_text_lines = fragm.xpath("text-section/@text")
|
||||
for line in fragm_text_lines:
|
||||
fragm_slice.append_text_section(line)
|
||||
pass
|
||||
pass
|
||||
pass
|
||||
|
||||
fragm_refers = self.ast_inst.xpath("//refer")
|
||||
for refer in fragm_refers:
|
||||
story_name = refer.xpath("@story")
|
||||
fragm_name = refer.xpath("@fragment")
|
||||
story_refers = items_filter(story_items, lambda x:x.signature == f"story:{story_name}")
|
||||
if(len(story_refers) > 0):
|
||||
story_refer = story_refers[0]
|
||||
|
||||
|
||||
return story_items
|
||||
|
||||
|
|
Loading…
Reference in New Issue