MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / ParseSegmentation

Method ParseSegmentation

src/Config.cpp:586–624  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

584 }
585
586 SegmentationPtr ParseSegmentation(const JSONValue& doc) {
587 SegmentationPtr segmentation;
588
589 // Required: type
590 std::string type = GetStringProperty(doc, "type");
591 if (type == "mmseg") {
592 // Required: dict
593 DictPtr dict = ParseDict(GetObjectProperty(doc, "dict"), true);
594 segmentation = SegmentationPtr(new MaxMatchSegmentation(dict));
595 } else {
596 PluginConfigPairs configPairs;
597 configPairs.push_back(std::make_pair("__config_dir", configDirectory));
598 if (doc.HasMember("resources")) {
599 const JSONValue& resources = GetObjectProperty(doc, "resources");
600 for (auto it = resources.MemberBegin(); it != resources.MemberEnd();
601 ++it) {
602 if (!it->value.IsString()) {
603 throw InvalidFormat("Segmentation resource must be a string: " +
604 std::string(it->name.GetString()));
605 }
606 configPairs.push_back(std::make_pair(it->name.GetString(),
607 it->value.GetString()));
608 }
609 }
610 for (auto it = doc.MemberBegin(); it != doc.MemberEnd(); ++it) {
611 const std::string key = it->name.GetString();
612 if (key == "type" || key == "resources") {
613 continue;
614 }
615 if (!it->value.IsString()) {
616 throw InvalidFormat("Segmentation plugin property must be a string: " +
617 key);
618 }
619 configPairs.push_back(std::make_pair(key, it->value.GetString()));
620 }
621 segmentation = CreatePluginSegmentation(type, configPairs);
622 }
623 return segmentation;
624 }
625
626 ConversionPtr ParseConversion(const JSONValue& doc) {
627 // Required: dict

Callers 1

NewFromStringMethod · 0.80

Calls 6

CreatePluginSegmentationFunction · 0.85
HasMemberMethod · 0.80
MemberBeginMethod · 0.80
MemberEndMethod · 0.80
GetStringMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected