blob: 344ceeb36222ae27a0ef8cf6bc9c125731092e0f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include "builder.h"
#include "common.h"
#include <library/cpp/codecs/static/static_codec_info.pb.h>
#include <library/cpp/codecs/codecs.h>
#include <util/generic/yexception.h>
#include <util/string/subst.h>
namespace NCodecs {
TStaticCodecInfo BuildStaticCodec(const TVector<TString>& trainingData, const TCodecBuildInfo& info) {
TStaticCodecInfo result;
TCodecPtr codec = ICodec::GetInstance(info.CodecName);
Y_ENSURE_EX(codec, TCodecException() << "empty codec is not allowed");
codec->LearnX(trainingData.begin(), trainingData.end(), info.SampleSizeMultiplier);
{
TStringOutput sout{*result.MutableStoredCodec()};
ICodec::Store(&sout, codec);
}
auto& debugInfo = *result.MutableDebugInfo();
debugInfo.SetStoredCodecHash(DataSignature(result.GetStoredCodec()));
debugInfo.SetCodecName(info.CodecName);
debugInfo.SetSampleSizeMultiplier(info.SampleSizeMultiplier);
debugInfo.SetTimestamp(info.Timestamp);
debugInfo.SetRevisionInfo(info.RevisionInfo);
debugInfo.SetTrainingSetComment(info.TrainingSetComment);
debugInfo.SetTrainingSetResId(info.TrainingSetResId);
return result;
}
TString GetStandardFileName(const TStaticCodecInfo& info) {
TString cName = info.GetDebugInfo().GetCodecName();
SubstGlobal(cName, ':', '.');
return TStringBuilder() << cName << "." << info.GetDebugInfo().GetTimestamp() << ".codec_info";
}
}
|