Utility function implementation
| 18 | |
| 19 | // Utility function implementation |
| 20 | float compressionRatio(const std::string &Text) { |
| 21 | if (Text.empty()) |
| 22 | return 1.0f; |
| 23 | |
| 24 | std::vector<uint8_t> Input(Text.begin(), Text.end()); |
| 25 | uLongf CompressedSize = compressBound(Input.size()); |
| 26 | std::vector<uint8_t> Compressed(CompressedSize); |
| 27 | |
| 28 | int Result = |
| 29 | compress(Compressed.data(), &CompressedSize, Input.data(), Input.size()); |
| 30 | |
| 31 | if (Result != Z_OK) |
| 32 | return 1.0f; |
| 33 | |
| 34 | return static_cast<float>(Input.size()) / static_cast<float>(CompressedSize); |
| 35 | } |
| 36 | |
| 37 | // Language detection implementation |
| 38 | std::pair<mx::array, std::vector<std::map<std::string, float>>> |