mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 07:39:16 +00:00
parent
a7a2ad0501
commit
6d56429336
2 changed files with 19 additions and 22 deletions
|
@ -373,13 +373,12 @@ struct LSTMData : public UMemory {
|
|||
ConstArray1D fOutputB;
|
||||
|
||||
private:
|
||||
UResourceBundle* fDataRes;
|
||||
UResourceBundle* fDictRes;
|
||||
UResourceBundle* fBundle;
|
||||
};
|
||||
|
||||
LSTMData::LSTMData(UResourceBundle* rb, UErrorCode &status)
|
||||
: fDict(nullptr), fType(UNKNOWN), fName(nullptr),
|
||||
fDataRes(nullptr), fDictRes(nullptr)
|
||||
fBundle(rb)
|
||||
{
|
||||
if (U_FAILURE(status)) {
|
||||
return;
|
||||
|
@ -403,26 +402,25 @@ LSTMData::LSTMData(UResourceBundle* rb, UErrorCode &status)
|
|||
fType = GRAPHEME_CLUSTER;
|
||||
}
|
||||
fName = ures_getStringByKey(rb, "model", nullptr, &status);
|
||||
fDataRes = ures_getByKey(rb, "data", nullptr, &status);
|
||||
LocalUResourceBundlePointer dataRes(ures_getByKey(rb, "data", nullptr, &status));
|
||||
if (U_FAILURE(status)) return;
|
||||
int32_t data_len = 0;
|
||||
const int32_t* data = ures_getIntVector(fDataRes, &data_len, &status);
|
||||
if (U_FAILURE(status)) return;
|
||||
fDictRes = ures_getByKey(rb, "dict", nullptr, &status);
|
||||
if (U_FAILURE(status)) return;
|
||||
U_ASSERT(fDictRes != nullptr);
|
||||
int32_t num_index = ures_getSize(fDictRes);
|
||||
const int32_t* data = ures_getIntVector(dataRes.getAlias(), &data_len, &status);
|
||||
fDict = uhash_open(uhash_hashUChars, uhash_compareUChars, nullptr, &status);
|
||||
if (U_FAILURE(status)) return;
|
||||
|
||||
ures_resetIterator(fDictRes);
|
||||
int32_t idx = 0;
|
||||
StackUResourceBundle stackTempBundle;
|
||||
ResourceDataValue value;
|
||||
ures_getValueWithFallback(rb, "dict", stackTempBundle.getAlias(), value, status);
|
||||
ResourceArray stringArray = value.getArray(status);
|
||||
int32_t num_index = stringArray.getSize();
|
||||
if (U_FAILURE(status)) { return; }
|
||||
|
||||
// put dict into hash
|
||||
while(ures_hasNext(fDictRes)) {
|
||||
const char *tempKey = nullptr;
|
||||
const UChar* str = ures_getNextString(fDictRes, nullptr, &tempKey, &status);
|
||||
if (U_FAILURE(status)) return;
|
||||
uhash_putiAllowZero(fDict, (void*)str, idx++, &status);
|
||||
int32_t stringLength;
|
||||
for (int32_t idx = 0; idx < num_index; idx++) {
|
||||
stringArray.getValue(idx, value);
|
||||
const UChar* str = value.getString(stringLength, status);
|
||||
uhash_putiAllowZero(fDict, (void*)str, idx, &status);
|
||||
if (U_FAILURE(status)) return;
|
||||
#ifdef LSTM_VECTORIZER_DEBUG
|
||||
printf("Assign [");
|
||||
|
@ -468,8 +466,7 @@ LSTMData::LSTMData(UResourceBundle* rb, UErrorCode &status)
|
|||
|
||||
LSTMData::~LSTMData() {
|
||||
uhash_close(fDict);
|
||||
ures_close(fDictRes);
|
||||
ures_close(fDataRes);
|
||||
ures_close(fBundle);
|
||||
}
|
||||
|
||||
class Vectorizer : public UMemory {
|
||||
|
@ -806,7 +803,7 @@ U_CAPI const LSTMData* U_EXPORT2 CreateLSTMDataForScript(UScriptCode script, UEr
|
|||
ures_openDirect(U_ICUDATA_BRKITR, namebuf.data(), &status));
|
||||
if (U_FAILURE(status)) return nullptr;
|
||||
|
||||
return CreateLSTMData(rb.getAlias(), status);
|
||||
return CreateLSTMData(rb.orphan(), status);
|
||||
}
|
||||
|
||||
U_CAPI const LSTMData* U_EXPORT2 CreateLSTMData(UResourceBundle* rb, UErrorCode& status)
|
||||
|
|
|
@ -229,7 +229,7 @@ const LanguageBreakEngine* LSTMBETest::createEngineFromTestData(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
const LSTMData* data = CreateLSTMData(rb.getAlias(), status);
|
||||
const LSTMData* data = CreateLSTMData(rb.orphan(), status);
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("Could not CreateLSTMData " + UnicodeString(model) + " under " + UnicodeString(testdatapath) + ", " +
|
||||
UnicodeString(u_errorName(status)));
|
||||
|
|
Loading…
Add table
Reference in a new issue