| 1 | /* Corpus.cpp |
| 2 | * |
| 3 | * Copyright (C) 2011,2016,2018,2020,2021,2026 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "Corpus.h"cxx . . $ `<file>/fon/Corpus.h`/ |
| 20 | #include "TextGrid_Sound.h"cxx . . $ `<file>/fon/TextGrid_Sound.h`/ |
| 21 | |
| 22 | #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/ |
| 23 | #include "Corpus_def.h"cxx . . $ `<file>/fon/Corpus_def.h`/ |
| 24 | #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/ |
| 25 | #include "Corpus_def.h"cxx . . $ `<file>/fon/Corpus_def.h`/ |
| 26 | #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/ |
| 27 | #include "Corpus_def.h"cxx . . $ `<file>/fon/Corpus_def.h`/ |
| 28 | #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/ |
| 29 | #include "Corpus_def.h"cxx . . $ `<file>/fon/Corpus_def.h`/ |
| 30 | #include "oo_WRITE_TEXT.h"cxx . . $ `<file>/sys/oo_WRITE_TEXT.h`/ |
| 31 | #include "Corpus_def.h"cxx . . $ `<file>/fon/Corpus_def.h`/ |
| 32 | #include "oo_READ_TEXT.h"cxx . . $ `<file>/sys/oo_READ_TEXT.h`/ |
| 33 | #include "Corpus_def.h"cxx . . $ `<file>/fon/Corpus_def.h`/ |
| 34 | #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/ |
| 35 | #include "Corpus_def.h"cxx . . $ `<file>/fon/Corpus_def.h`/ |
| 36 | #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/ |
| 37 | #include "Corpus_def.h"cxx . . $ `<file>/fon/Corpus_def.h`/ |
| 38 | #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/ |
| 39 | #include "Corpus_def.h"cxx . . $ `<file>/fon/Corpus_def.h`/ |
| 40 | |
| 41 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (Corpus, Table, 1); |
| 42 | |
| 43 | autoCorpus Corpus_createcxx . . $ Corpus_create(9eb1ff64165c83ae). (conststring32cxx . . $ conststring32# folderWithSoundFiles, conststring32cxx . . $ conststring32# soundFileExtension, |
| 44 | conststring32cxx . . $ conststring32# folderWithAnnotationFiles, conststring32cxx . . $ conststring32# annotationFileExtension) |
| 45 | { |
| 46 | autoCorpus me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Corpus); |
| 47 | mycxx . . $ `melder/melder.h:44:9`! folderWithSoundFiles =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (folderWithSoundFiles); |
| 48 | if (folderWithAnnotationFiles [0] == U'\0') |
| 49 | folderWithAnnotationFiles = folderWithSoundFiles; |
| 50 | mycxx . . $ `melder/melder.h:44:9`! folderWithAnnotationFiles =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (folderWithAnnotationFiles); |
| 51 | autoSTRVECcxx . . $ autoSTRVEC# fileList = fileNames_STRVECcxx . . $ fileNames_STRVEC(d3c03a92d990d008). (Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (folderWithSoundFiles, U"/*.", soundFileExtension)); |
| 52 | Table_initWithColumnNamescxx . . $ Table_initWithColumnNames(e65b0e546e66a14c). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), fileList.sizecxx . . $ _autostringautovector#size., |
| 53 | autoSTRVECcxx . . $ _conststringvector#_conststringvector(93d9e701af42cb0d). ({ U"Sound", U"Annotation" }).getcxx . . $ _autostringautovector#get(9d56076a9ef7dd02).()); |
| 54 | autoMelderStringcxx . . $ autoMelderString# annotationFileNamecxx . . $ autoMelderString#autoMelderString(49f6e7a06ebc5aa8).; |
| 55 | for (integercxx . . $ integer# ifile = 1; ifile <= fileList.sizecxx . . $ _autostringautovector#size.; ifile ++) { |
| 56 | conststring32cxx . . $ conststring32# soundFileName = fileList [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ifile].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(); |
| 57 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ifile, 1, soundFileName); |
| 58 | const char32cxx . . $ char32# *dotLocation = str32rchrcxx . . $ str32rchr(328a9ede0fba853a). (soundFileName, U'.'); |
| 59 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (!! dotLocation); |
| 60 | MelderString_ncopycxx . . $ MelderString_ncopy(b76236fd155635ca). (& annotationFileName, soundFileName, dotLocation - soundFileName + 1); |
| 61 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& annotationFileName, annotationFileExtension); |
| 62 | structMelderFilecxx . . $ structMelderFile# annotationFile { }; |
| 63 | Melder_pathToFilecxx . . $ Melder_pathToFile(82691f2ee21fbb13). (Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (folderWithAnnotationFiles, U"/", annotationFileName.stringcxx . . $ MelderString#string.), & annotationFile); |
| 64 | if (MelderFile_existscxx . . $ MelderFile_exists(8f92cdf95b27d908). (& annotationFile)) |
| 65 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ifile, 2, annotationFileName.stringcxx . . $ MelderString#string.); |
| 66 | } |
| 67 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 68 | } |
| 69 | |
| 70 | autoCorpus Corpus_readFromCGNcxx . . $ Corpus_readFromCGN(20f352efcfaa84bc). (conststring32cxx . . $ conststring32# rootFolderPath) { |
| 71 | autoCorpus me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Corpus); |
| 72 | const conststring32cxx . . $ conststring32# columnNames_array [] = { U"comp", U"region", U"data" }; |
| 73 | Table_initWithColumnNamescxx . . $ Table_initWithColumnNames(e65b0e546e66a14c). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0, ARRAY_TO_STRVECcxx . . $ `melder/melder_strvec.h:262:9`! (columnNames_array)); |
| 74 | |
| 75 | structMelderFoldercxx . . $ structMelderFolder# rootFolder { }; |
| 76 | Melder_relativePathToFoldercxx . . $ Melder_relativePathToFolder(f9a4643b225086b8). (rootFolderPath, & rootFolder); |
| 77 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (MelderFolder_exists (& rootFolder), |
| 78 | U"CGN folder ", MelderFolder_messageName (& rootFolder), U" does not exist."); |
| 79 | |
| 80 | autoSTRVECcxx . . $ autoSTRVEC# compFolderNames = folderNames_STRVECcxx . . $ folderNames_STRVEC(d3c03a92d990d008). (Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (MelderFolder_peekPathcxx . . $ MelderFolder_peekPath(fbe3b4f4d15c56ee). (& rootFolder), U"/comp-*")); |
| 81 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (compFolderNames.size > 0, |
| 82 | U"The folder ", MelderFolder_messageName (& rootFolder), U" contains no folders whose names start with “comp-”."); |
| 83 | |
| 84 | const conststring32cxx . . $ conststring32# regionNames_array [] = { U"vl", U"nl" }; |
| 85 | const constSTRVECcxx . . $ constSTRVEC# regionNames = ARRAY_TO_STRVECcxx . . $ `melder/melder_strvec.h:262:9`! (regionNames_array); |
| 86 | for (integercxx . . $ integer# icomp = 1; icomp <= compFolderNames.sizecxx . . $ _autostringautovector#size.; icomp ++) { |
| 87 | structMelderFoldercxx . . $ structMelderFolder# compFolder { }; |
| 88 | MelderFolder_getSubfoldercxx . . $ MelderFolder_getSubfolder(a6a48bbd99ea6094). (& rootFolder, compFolderNames [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).icomp].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), & compFolder); |
| 89 | for (integercxx . . $ integer# iregion = 1; iregion <= regionNames.sizecxx . . $ _conststringvector#size.; iregion ++) { |
| 90 | structMelderFoldercxx . . $ structMelderFolder# regionFolder { }; |
| 91 | MelderFolder_getSubfoldercxx . . $ MelderFolder_getSubfolder(a6a48bbd99ea6094). (& compFolder, regionNames [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).iregion], & regionFolder); |
| 92 | if (MelderFolder_existscxx . . $ MelderFolder_exists(f2f3cbeb84a71ab3). (& regionFolder)) { // allow partial corpora |
| 93 | autoSTRVECcxx . . $ autoSTRVEC# soundFileNames = fileNames_STRVECcxx . . $ fileNames_STRVEC(d3c03a92d990d008). (Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (MelderFolder_peekPathcxx . . $ MelderFolder_peekPath(fbe3b4f4d15c56ee). (& regionFolder), U"/*.wav")); |
| 94 | const conststring32cxx . . $ conststring32# brokenFiles [] = { |
| 95 | U"fn000483.wav", // zeroes, |
| 96 | U"fv701103.wav" // missing ort |
| 97 | }; |
| 98 | for (integercxx . . $ integer# ifile = 1; ifile <= soundFileNames.sizecxx . . $ _autostringautovector#size.; ifile ++) if (! NUMfindFirstcxx . . $ NUMfindFirst(5bcfdb87a5d5128). (ARRAY_TO_STRVECcxx . . $ `melder/melder_strvec.h:262:9`! (brokenFiles), soundFileNames [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ifile].getcxx . . $ _autostring#get(5a2a78a048fb49a8).())) { |
| 99 | TRACEcxx . . $ `melder/melder_debug.h:54:9`! |
| 100 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Reading file ", soundFileNames [ifile].get()); |
| 101 | autoTextGridcxx . . $ autoTextGrid# textGridcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 102 | autoSoundcxx . . $ autoSound# soundcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 103 | try { |
| 104 | textGrid =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). TextGrid_Sound_readFromCorpusGesprokenNederlandscxx . . $ TextGrid_Sound_readFromCorpusGesprokenNederlands(ee7e710952ff1d8f). (Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (MelderFolder_peekPathcxx . . $ MelderFolder_peekPath(fbe3b4f4d15c56ee). (& regionFolder), U"/", soundFileNames [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ifile].getcxx . . $ _autostring#get(5a2a78a048fb49a8).()), nullptr); |
| 105 | Table_appendRowcxx . . $ Table_appendRow(1499cd40562fac4f). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 106 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size., 1, compFolderNames [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).icomp].getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 107 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size., 2, regionNames [cxx . . $ _conststringvector#`operator[]`(2065423e0524e64a).iregion]); |
| 108 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size., 3, soundFileNames [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ifile].getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 109 | mycxx . . $ `melder/melder.h:44:9`! textGrids. addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (textGridcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 110 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 111 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 112 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Error handling file ", soundFileNames [ifile].get()); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 119 | } |
| 120 | |
| 121 | /* End of file Corpus.cpp */ |