XML 내용 중 Chart XML 내용이 없으면 0점 처리로 넘어가도록 로직 수정
This commit is contained in:
26
score5.py
26
score5.py
@@ -52,14 +52,13 @@ class XMLScorer:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def chart_query_xml(self, tree, xpath, namespaces):
|
def chart_query_xml(self, tree, xpath, namespaces):
|
||||||
try:
|
|
||||||
result = tree.xpath(xpath, namespaces=namespaces)
|
result = tree.xpath(xpath, namespaces=namespaces)
|
||||||
if type(result) is list and len(result) == 0:
|
if type(result) is list and len(result) == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return result
|
return result
|
||||||
except ET.XPathEvalError as e:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# 유사한 텍스트 찾기
|
# 유사한 텍스트 찾기
|
||||||
def find_similar_text(self, root, target_text, threshold=0.5):
|
def find_similar_text(self, root, target_text, threshold=0.5):
|
||||||
@@ -109,7 +108,7 @@ class XMLScorer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if chart_xml is None:
|
if chart_xml is None:
|
||||||
chart_tree = ET.fromstring('')
|
chart_tree = ET.fromstring('<xml></xml>')
|
||||||
else:
|
else:
|
||||||
chart_tree = ET.fromstring(chart_xml)
|
chart_tree = ET.fromstring(chart_xml)
|
||||||
|
|
||||||
@@ -235,14 +234,14 @@ class XMLScorer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def binary_to_chartxml(self, xml_path):
|
def binary_to_chartxml(self, xml_path):
|
||||||
try:
|
|
||||||
print(f'binary_to_chartxml {xml_path}')
|
print(f'binary_to_chartxml {xml_path}')
|
||||||
tree = ET.parse(xml_path)
|
tree = ET.parse(xml_path)
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
|
||||||
binary_data = root.xpath('//BINDATA[@Id=//BINITEM[@Format="OLE"]/@BinData]/text()')
|
binary_data = root.xpath('//BINDATA[@Id=//BINITEM[@Format="OLE"]/@BinData]/text()')
|
||||||
if not binary_data:
|
if not binary_data:
|
||||||
raise ValueError("No binary data found in the XML.")
|
return None
|
||||||
binary_data = binary_data[0].encode('utf-8')
|
binary_data = binary_data[0].encode('utf-8')
|
||||||
|
|
||||||
# <BINDATA ...> 태그와 그 내부 내용을 삭제합니다.
|
# <BINDATA ...> 태그와 그 내부 내용을 삭제합니다.
|
||||||
@@ -260,6 +259,9 @@ class XMLScorer:
|
|||||||
print(end)
|
print(end)
|
||||||
xml_data = decoded_data[start:end+len(b'</c:chartSpace>')]
|
xml_data = decoded_data[start:end+len(b'</c:chartSpace>')]
|
||||||
|
|
||||||
|
if -1 in [start, end]:
|
||||||
|
return None
|
||||||
|
|
||||||
# 디코딩된 데이터를 파일로 저장합니다.
|
# 디코딩된 데이터를 파일로 저장합니다.
|
||||||
base_filename = os.path.splitext(xml_path)[0]
|
base_filename = os.path.splitext(xml_path)[0]
|
||||||
new_filename = f'{base_filename}.xml'
|
new_filename = f'{base_filename}.xml'
|
||||||
@@ -268,14 +270,6 @@ class XMLScorer:
|
|||||||
|
|
||||||
return xml_data
|
return xml_data
|
||||||
|
|
||||||
except ET.ParseError as e:
|
|
||||||
print(f"XML 파싱 오류: {str(e)}")
|
|
||||||
except IndexError as e:
|
|
||||||
print(f"IndexError: {str(e)}")
|
|
||||||
except ValueError as e:
|
|
||||||
print(f"ValueError: {str(e)}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Unexpected error: {str(e)}")
|
|
||||||
|
|
||||||
# XML 파일 채점
|
# XML 파일 채점
|
||||||
def score_directory(self, xml_directory):
|
def score_directory(self, xml_directory):
|
||||||
@@ -365,10 +359,10 @@ class XMLScorer:
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
scoring_criteria_path = r'C:\Users\dra\project\HWP-Scoring\scoring_criteria.json'
|
scoring_criteria_path = r'./scoring_criteria.json'
|
||||||
|
|
||||||
# xml(hml)파일 디렉토리 경로
|
# xml(hml)파일 디렉토리 경로
|
||||||
xml_directory = r'C:\Users\dra\project\HWP-Scoring\output'
|
xml_directory = r'./output'
|
||||||
|
|
||||||
# 채점 클래스 초기화
|
# 채점 클래스 초기화
|
||||||
scorer = XMLScorer(scoring_criteria_path)
|
scorer = XMLScorer(scoring_criteria_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user