improve debugging experience
This commit is contained in:
parent
799ec37b65
commit
7078341556
@ -23,7 +23,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
public class NlpRunner {
|
public class NlpRunner {
|
||||||
public static class NlpJsonConverter extends NlpBaseListener {
|
public static class NlpJsonConverter extends NlpBaseListener {
|
||||||
public NlpJsonConverter() {
|
public NlpJsonConverter() {
|
||||||
mGsonInstance = new GsonBuilder().setPrettyPrinting().create();
|
mGsonInstance = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||||
mRoot = new JsonObject();
|
mRoot = new JsonObject();
|
||||||
mSection = new JsonArray();
|
mSection = new JsonArray();
|
||||||
mSectionStack = new Stack<JsonArray>();
|
mSectionStack = new Stack<JsonArray>();
|
||||||
|
@ -2,11 +2,18 @@ import NlpUtils
|
|||||||
import jsondiff
|
import jsondiff
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
g_SupportedEncoding = {
|
if NlpUtils.g_EnableDebugging:
|
||||||
|
g_SupportedEncoding = {
|
||||||
|
'template': ('English', ('ascii', ), )
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
g_SupportedEncoding = {
|
||||||
'zh-cn': ('Chinese', ('utf-8', 'gb2312', ), )
|
'zh-cn': ('Chinese', ('utf-8', 'gb2312', ), )
|
||||||
}
|
}
|
||||||
|
|
||||||
VtTrDataTuple = collections.namedtuple('VtTrDataTuple', ('rawNlp', 'trTemplate', 'trDiff', 'trIndex'))
|
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:
|
def GetRawNlpPath(ver: str, lang: str, enc: str) -> str:
|
||||||
return f'../NlpTr/out/VT{ver}.{lang}.{enc}.txt'
|
return f'../NlpTr/out/VT{ver}.{lang}.{enc}.txt'
|
||||||
def GetTrPath(ver: str, lang: str) -> str:
|
def GetTrPath(ver: str, lang: str) -> str:
|
||||||
@ -60,7 +67,8 @@ if __name__ == "__main__":
|
|||||||
# convert plain json to nlp json
|
# convert plain json to nlp json
|
||||||
nlpJson = NlpUtils.PlainJson2NlpJson(plainKeys, plainValues)
|
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
|
# write into file with different encoding
|
||||||
lang_macro, encs = g_SupportedEncoding[lang]
|
lang_macro, encs = g_SupportedEncoding[lang]
|
||||||
|
@ -4,20 +4,30 @@ import io
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
g_EnableDebugging = False
|
g_EnableDebugging = True
|
||||||
|
|
||||||
g_VirtoolsVersion: tuple[str] = (
|
g_VirtoolsVersion: tuple[str] = (
|
||||||
'25', '35', '40', '50',
|
'25', '35', '40', '50',
|
||||||
)
|
)
|
||||||
g_SupportedLangs: tuple[str] = (
|
|
||||||
|
if g_EnableDebugging:
|
||||||
|
g_SupportedLangs: tuple[str] = (
|
||||||
|
'template',
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
g_SupportedLangs: tuple[str] = (
|
||||||
'zh-cn',
|
'zh-cn',
|
||||||
)
|
)
|
||||||
|
|
||||||
# ========== Basic File RW Functions ==========
|
# ========== Basic File RW Functions ==========
|
||||||
|
|
||||||
def DumpJson(filepath: str, jsonData: dict):
|
def DumpJson(filepath: str, jsonData: dict):
|
||||||
with open(filepath, 'w', encoding='utf-8') as f:
|
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:
|
def LoadJson(filepath: str) -> dict:
|
||||||
with open(filepath, 'r', encoding='utf-8') as f:
|
with open(filepath, 'r', encoding='utf-8') as f:
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
Useful comparing differences command:
|
Useful comparing differences command:
|
||||||
|
|
||||||
`diff -u VT25.json VT50.json`
|
`diff -u --strip-trailing-cr VT25.json VT50.json`
|
||||||
`diff -u VT25.txt VT50.txt`
|
`diff -u --strip-trailing-cr VT25.txt VT50.txt`
|
||||||
|
Loading…
Reference in New Issue
Block a user