improve debugging experience

This commit is contained in:
yyc12345 2023-07-12 23:37:55 +08:00
parent 799ec37b65
commit 7078341556
4 changed files with 30 additions and 12 deletions

View File

@ -23,7 +23,7 @@ import java.nio.charset.StandardCharsets;
public class NlpRunner {
public static class NlpJsonConverter extends NlpBaseListener {
public NlpJsonConverter() {
mGsonInstance = new GsonBuilder().setPrettyPrinting().create();
mGsonInstance = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
mRoot = new JsonObject();
mSection = new JsonArray();
mSectionStack = new Stack<JsonArray>();

View File

@ -2,11 +2,18 @@ import NlpUtils
import jsondiff
import collections
g_SupportedEncoding = {
'zh-cn': ('Chinese', ('utf-8', 'gb2312', ), )
}
if NlpUtils.g_EnableDebugging:
g_SupportedEncoding = {
'template': ('English', ('ascii', ), )
}
else:
g_SupportedEncoding = {
'zh-cn': ('Chinese', ('utf-8', 'gb2312', ), )
}
VtTrDataTuple = collections.namedtuple('VtTrDataTuple', ('rawNlp', 'trTemplate', 'trDiff', 'trIndex'))
def GetNlpJsonPath(ver: str, lang: str) -> str:
return f'../NlpTr/out/VT{ver}.{lang}.json'
def GetRawNlpPath(ver: str, lang: str, enc: str) -> str:
return f'../NlpTr/out/VT{ver}.{lang}.{enc}.txt'
def GetTrPath(ver: str, lang: str) -> str:
@ -60,7 +67,8 @@ if __name__ == "__main__":
# convert plain json to nlp json
nlpJson = NlpUtils.PlainJson2NlpJson(plainKeys, plainValues)
NlpUtils.DumpJson(GetRawNlpPath(ver, lang, '')[:-5] + '.json', nlpJson)
if NlpUtils.g_EnableDebugging:
NlpUtils.DumpJson(GetNlpJsonPath(ver, lang), nlpJson)
# write into file with different encoding
lang_macro, encs = g_SupportedEncoding[lang]

View File

@ -4,20 +4,30 @@ import io
import json
import re
g_EnableDebugging = False
g_EnableDebugging = True
g_VirtoolsVersion: tuple[str] = (
'25', '35', '40', '50',
)
g_SupportedLangs: tuple[str] = (
'zh-cn',
)
if g_EnableDebugging:
g_SupportedLangs: tuple[str] = (
'template',
)
else:
g_SupportedLangs: tuple[str] = (
'zh-cn',
)
# ========== Basic File RW Functions ==========
def DumpJson(filepath: str, jsonData: dict):
with open(filepath, 'w', encoding='utf-8') as f:
json.dump(jsonData, f, indent=(2 if g_EnableDebugging else None), sort_keys=False)
json.dump(jsonData, f,
indent=(2 if g_EnableDebugging else None),
sort_keys=False,
ensure_ascii=False
)
def LoadJson(filepath: str) -> dict:
with open(filepath, 'r', encoding='utf-8') as f:

View File

@ -2,5 +2,5 @@
Useful comparing differences command:
`diff -u VT25.json VT50.json`
`diff -u VT25.txt VT50.txt`
`diff -u --strip-trailing-cr VT25.json VT50.json`
`diff -u --strip-trailing-cr VT25.txt VT50.txt`