Add swedish hyphenation (upstream PR 1637)
This commit is contained in:
@@ -8,15 +8,19 @@
|
|||||||
#include "LanguageHyphenator.h"
|
#include "LanguageHyphenator.h"
|
||||||
#include "LanguageRegistry.h"
|
#include "LanguageRegistry.h"
|
||||||
|
|
||||||
const LanguageHyphenator* Hyphenator::cachedHyphenator_ = nullptr;
|
struct Iso639Mapping {
|
||||||
|
const char* iso639_2;
|
||||||
|
const char* iso639_1;
|
||||||
|
};
|
||||||
|
static constexpr Iso639Mapping kIso639Mappings[] = {{"eng", "en"}, {"fra", "fr"}, {"fre", "fr"}, {"deu", "de"},
|
||||||
|
{"ger", "de"}, {"rus", "ru"}, {"spa", "es"}, {"ita", "it"},
|
||||||
|
{"ukr", "uk"}, {"swe", "sv"}};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Maps a BCP-47 language tag to a language-specific hyphenator.
|
|
||||||
const LanguageHyphenator* hyphenatorForLanguage(const std::string& langTag) {
|
const LanguageHyphenator* hyphenatorForLanguage(const std::string& langTag) {
|
||||||
if (langTag.empty()) return nullptr;
|
if (langTag.empty()) return nullptr;
|
||||||
|
|
||||||
// Extract primary subtag and normalize to lowercase (e.g., "en-US" -> "en").
|
|
||||||
std::string primary;
|
std::string primary;
|
||||||
primary.reserve(langTag.size());
|
primary.reserve(langTag.size());
|
||||||
for (char c : langTag) {
|
for (char c : langTag) {
|
||||||
@@ -26,6 +30,12 @@ const LanguageHyphenator* hyphenatorForLanguage(const std::string& langTag) {
|
|||||||
}
|
}
|
||||||
if (primary.empty()) return nullptr;
|
if (primary.empty()) return nullptr;
|
||||||
|
|
||||||
|
for (const auto& mapping : kIso639Mappings) {
|
||||||
|
if (primary == mapping.iso639_2) {
|
||||||
|
return getLanguageHyphenatorForPrimaryTag(mapping.iso639_1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return getLanguageHyphenatorForPrimaryTag(primary);
|
return getLanguageHyphenatorForPrimaryTag(primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "generated/hyph-it.trie.h"
|
#include "generated/hyph-it.trie.h"
|
||||||
#include "generated/hyph-pl.trie.h"
|
#include "generated/hyph-pl.trie.h"
|
||||||
#include "generated/hyph-ru.trie.h"
|
#include "generated/hyph-ru.trie.h"
|
||||||
|
#include "generated/hyph-sv.trie.h"
|
||||||
#include "generated/hyph-uk.trie.h"
|
#include "generated/hyph-uk.trie.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -22,10 +23,11 @@ LanguageHyphenator germanHyphenator(de_patterns, isLatinLetter, toLowerLatin);
|
|||||||
LanguageHyphenator russianHyphenator(ru_patterns, isCyrillicLetter, toLowerCyrillic);
|
LanguageHyphenator russianHyphenator(ru_patterns, isCyrillicLetter, toLowerCyrillic);
|
||||||
LanguageHyphenator spanishHyphenator(es_patterns, isLatinLetter, toLowerLatin);
|
LanguageHyphenator spanishHyphenator(es_patterns, isLatinLetter, toLowerLatin);
|
||||||
LanguageHyphenator italianHyphenator(it_patterns, isLatinLetter, toLowerLatin);
|
LanguageHyphenator italianHyphenator(it_patterns, isLatinLetter, toLowerLatin);
|
||||||
|
LanguageHyphenator swedishHyphenator(sv_patterns, isLatinLetter, toLowerLatin);
|
||||||
LanguageHyphenator ukrainianHyphenator(uk_patterns, isCyrillicLetter, toLowerCyrillic);
|
LanguageHyphenator ukrainianHyphenator(uk_patterns, isCyrillicLetter, toLowerCyrillic);
|
||||||
LanguageHyphenator polishHyphenator(pl_patterns, isLatinLetter, toLowerLatin);
|
LanguageHyphenator polishHyphenator(pl_patterns, isLatinLetter, toLowerLatin);
|
||||||
|
|
||||||
using EntryArray = std::array<LanguageEntry, 8>;
|
using EntryArray = std::array<LanguageEntry, 9>;
|
||||||
|
|
||||||
const EntryArray& entries() {
|
const EntryArray& entries() {
|
||||||
static const EntryArray kEntries = {{{"english", "en", &englishHyphenator},
|
static const EntryArray kEntries = {{{"english", "en", &englishHyphenator},
|
||||||
@@ -34,6 +36,7 @@ const EntryArray& entries() {
|
|||||||
{"russian", "ru", &russianHyphenator},
|
{"russian", "ru", &russianHyphenator},
|
||||||
{"spanish", "es", &spanishHyphenator},
|
{"spanish", "es", &spanishHyphenator},
|
||||||
{"italian", "it", &italianHyphenator},
|
{"italian", "it", &italianHyphenator},
|
||||||
|
{"swedish", "sv", &swedishHyphenator},
|
||||||
{"polish", "pl", &polishHyphenator},
|
{"polish", "pl", &polishHyphenator},
|
||||||
{"ukrainian", "uk", &ukrainianHyphenator}}};
|
{"ukrainian", "uk", &ukrainianHyphenator}}};
|
||||||
return kEntries;
|
return kEntries;
|
||||||
|
|||||||
Binary file not shown.
@@ -23,3 +23,4 @@ process es
|
|||||||
process ru
|
process ru
|
||||||
process it
|
process it
|
||||||
process uk
|
process uk
|
||||||
|
process sv
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ const std::vector<LanguageConfig> kSupportedLanguages = {
|
|||||||
{"russian", "test/hyphenation_eval/resources/russian_hyphenation_tests.txt", "ru"},
|
{"russian", "test/hyphenation_eval/resources/russian_hyphenation_tests.txt", "ru"},
|
||||||
{"spanish", "test/hyphenation_eval/resources/spanish_hyphenation_tests.txt", "es"},
|
{"spanish", "test/hyphenation_eval/resources/spanish_hyphenation_tests.txt", "es"},
|
||||||
{"italian", "test/hyphenation_eval/resources/italian_hyphenation_tests.txt", "it"},
|
{"italian", "test/hyphenation_eval/resources/italian_hyphenation_tests.txt", "it"},
|
||||||
|
{"swedish", "test/hyphenation_eval/resources/swedish_hyphenation_tests.txt", "sv"},
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<size_t> expectedPositionsFromAnnotatedWord(const std::string& annotated) {
|
std::vector<size_t> expectedPositionsFromAnnotatedWord(const std::string& annotated) {
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user