From b5736c51e06135433eb730af2f22decafd1049f0 Mon Sep 17 00:00:00 2001 From: Rob van Son Date: Fri, 8 Jan 2016 09:38:43 +0100 Subject: [PATCH] Made grading language independent --- Config.praat | 33 +++++++++++--------- InitialiseSGC2.praat | 86 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 79 insertions(+), 40 deletions(-) diff --git a/Config.praat b/Config.praat index 7552917..0d71bba 100644 --- a/Config.praat +++ b/Config.praat @@ -541,21 +541,26 @@ procedure processConfigOpenPerf .clickX .clickY .pressed$ if sgc.savePerf$ <> "" .defaultName$= sgc.savePerf$ endif - .performance_Name$ = chooseReadFile$ (.openDialogue$) - while .performance_Name$ <> "" and index_regex(.performance_Name$, "\.(tsv|TSV)$") <= 0 - .performance_Name$ = chooseReadFile$ (.openDialogue$) - endwhile - if .performance_Name$ <> "" and fileReadable(.performance_Name$) - sgc.savePerf$ = .performance_Name$ - call initialize_toneevaluation_tables - - # Set SaveAudio directory if it is not currently "in use" - if not sgc.saveAudioOn - sgc.saveAudio$ = replace_regex$(sgc.savePerf$, "[/\\][^/\\]+$", "", 0) - # We are not sure yet that this is actually an audio directory - config.audioName$ = "" + .notChoosen = 1 + while .notChoosen > 0 + .notChoosen = 0 + .performance_Name$ = chooseReadFile$ (.openDialogue$) + while .performance_Name$ <> "" and index_regex(.performance_Name$, "\.(tsv|TSV)$") <= 0 + .performance_Name$ = chooseReadFile$ (.openDialogue$) + endwhile + if .performance_Name$ <> "" and fileReadable(.performance_Name$) + sgc.savePerf$ = .performance_Name$ + call initialize_toneevaluation_tables + .notChoosen = initialize_toneevaluation_tables.invalidperformanceTable + + # Set SaveAudio directory if it is not currently "in use" + if not sgc.saveAudioOn + sgc.saveAudio$ = replace_regex$(sgc.savePerf$, "[/\\][^/\\]+$", "", 0) + # We are not sure yet that this is actually an audio directory + config.audioName$ = "" + endif endif - endif + endwhile endif call Draw_button '.table$' '.label$' 'sgc.saveAudioOn' diff --git a/InitialiseSGC2.praat b/InitialiseSGC2.praat index 5d82374..fa992cc 100644 --- a/InitialiseSGC2.praat +++ b/InitialiseSGC2.praat @@ -579,10 +579,12 @@ endproc # Prerequisites # initialiseSGC2.toneevaluation_table$ = "" procedure initialize_toneevaluation_tables - # Remove old table + .invalidperformanceTable = 0 + .oldPerformanceTable = -1 + # Mark old table for removal if initialiseSGC2.toneevaluation_table$ != "" - select sgc2.performanceTable - Remove + .oldPerformanceTable = sgc2.performanceTable + sgc2.performanceTable = -1 endif initialiseSGC2.toneevaluation_table$ = "" # Get the name of the table @@ -592,29 +594,39 @@ procedure initialize_toneevaluation_tables if sgc.savePerf$ <> "" and fileReadable(sgc.savePerf$) sgc2.performanceTable = Read Table from tab-separated file: sgc.savePerf$ Rename: performanceTableName$ + .columnNameList$ = "'eval.pinyin$' 'eval.grade$' 'eval.correct$' 'eval.wrong$' 'eval.total$' 'eval.high$' 'eval.low$' 'eval.wide$' 'eval.narrow$' 'eval.unknown$' 'eval.commented$' 'eval.level$' 'eval.time$' 'eval.wordlist$'" + .numPerfColumns = 14 # Check to make sure all columns are initialized, but only if Pinyin exists! select sgc2.performanceTable - .column = Get column index: eval.pinyin$ - if .column <= 0 - select sgc2.performanceTable - Remove - sgc2.performanceTable = Create Table with column names... "'performanceTableName$'" 0 'eval.pinyin$' 'eval.correct$' 'eval.wrong$' 'eval.total$' 'eval.high$' 'eval.low$' 'eval.wide$' 'eval.narrow$' 'eval.unknown$' 'eval.commented$' 'eval.level$' 'eval.time$' 'eval.wordlist$' - endif - .columnNameList$ = "'eval.correct$' 'eval.wrong$' 'eval.total$' 'eval.high$' 'eval.low$' 'eval.wide$' 'eval.narrow$' 'eval.unknown$' 'eval.commented$' 'eval.level$' 'eval.time$' 'eval.wordlist$'" - while index_regex(.columnNameList$, "\S") - .columnNameList$ = replace_regex$(.columnNameList$, "^\s+", "", 1) - .columnHeader$ = extractWord$(.columnNameList$, "") - .columnNameList$ = replace_regex$(.columnNameList$, "^\s*'.columnHeader$'\s*", "", 1) - # Initialize header - select sgc2.performanceTable - .column = Get column index: .columnHeader$ + .numColumns = Get number of columns + # Find Pinyin column on 1 + if index("Pinyin 拼音 ピンイン", eval.pinyin$) > 0 + .column = Get column index: "Pinyin" if .column <= 0 - select sgc2.performanceTable - Append column: .columnHeader$ + .column = Get column index: "拼音" endif - - endwhile - + if .column <= 0 + .column = Get column index: "ピンイン" + endif + else + .column = Get column index: eval.pinyin$ + endif + if .column != 1 or .numColumns != .numPerfColumns + # Set ERROR and remove file read + .invalidperformanceTable = 1 + sgc2.performanceTable = .oldPerformanceTable + .oldPerformanceTable = -1 + else + .nameList$ = .columnNameList$ + for .col to .numColumns + .columnNameList$ = replace_regex$(.columnNameList$, "^\s+", "", 1) + .columnHeader$ = extractWord$(.columnNameList$, "") + .columnNameList$ = replace_regex$(.columnNameList$, "^\s*'.columnHeader$'\s*", "", 1) + select sgc2.performanceTable + Set column label (index): .col, .columnHeader$ + endfor + endif + # Performance table has been read. Set the wordlist to the first row select sgc2.performanceTable .numWords = Get number of rows @@ -634,15 +646,39 @@ procedure initialize_toneevaluation_tables call load_word_list: localWordlistDir$, 0 else # Create new table - sgc2.performanceTable = Create Table with column names... "'performanceTableName$'" 0 'eval.pinyin$' 'eval.correct$' 'eval.wrong$' 'eval.total$' 'eval.high$' 'eval.low$' 'eval.wide$' 'eval.narrow$' 'eval.unknown$' 'eval.commented$' 'eval.level$' 'eval.time$' 'eval.wordlist$' + sgc2.performanceTable = Create Table with column names... "'performanceTableName$'" 0 'eval.pinyin$' 'eval.grade$' 'eval.correct$' 'eval.wrong$' 'eval.total$' 'eval.high$' 'eval.low$' 'eval.wide$' 'eval.narrow$' 'eval.unknown$' 'eval.commented$' 'eval.level$' 'eval.time$' 'eval.wordlist$' endif initialiseSGC2.toneevaluation_table$ = performanceTableName$ call get_toneevaluation_row 'eval.total$' + + # Remove marked old table + if .oldPerformanceTable > 0 + select .oldPerformanceTable + Remove + .oldPerformanceTable = -1 + endif endproc procedure get_toneevaluation_row .pinyin$ select sgc2.performanceTable - .row = Search column... "'eval.pinyin$'" '.pinyin$' + # Catch and rename Totals. Make sure it works when you stay within a new language + if index("Total Totaal 总计 合計", .pinyin$) > 0 + .row = Search column: eval.pinyin$, "Total" + if .row < 1 + .row = Search column: eval.pinyin$, "Totaal" + endif + if .row < 1 + .row = Search column: eval.pinyin$, "总计" + endif + if .row < 1 + .row = Search column: eval.pinyin$, "合計" + endif + if .row > 0 + Set string value: .row, eval.pinyin$, .pinyin$ + endif + else + .row = Search column... "'eval.pinyin$'" '.pinyin$' + endif if .row < 1 Append row .row = Get number of rows @@ -741,7 +777,6 @@ endproc procedure setGrade .grade$ select sgc.currentWordlist -printline {'.grade$'} if recordedSound$ <> "" and sgc.pinyin$ <> "" call get_toneevaluation_row 'sgc.pinyin$' .row = get_toneevaluation_row.row @@ -751,7 +786,6 @@ printline {'.grade$'} Insert column: 2, eval.grade$ endif .gradeNum = '.grade$' -printline ['.grade$'] if .gradeNum = 0 .gradeNum = 10 endif -- 2.11.4.GIT