def create(name, data, global_rank): assert isinstance(data, dict) targets = [] sentences = {} rank = Rank.create(data["rank"]) if "rank" in data else None if not rank: rank = Rank.create(global_rank) if "target" in data: raw_data = data["target"] assert isinstance(raw_data, list) for target in raw_data: targets.append(target) if "sentence" in data: raw_data = data["sentence"] assert isinstance(raw_data, dict) for sentence in raw_data: sentences[sentence] = Sentence.create(raw_data[sentence]) if "restrict" in data: raw_data = data["restrict"] assert isinstance(raw_data, dict) for restrict in raw_data: sentence_data = raw_data[restrict] if isinstance(sentence_data, list): for sentence in sentence_data: sentences[sentence] = Sentence.create(None, restrict) elif isinstance(sentence_data, dict): for sentence in sentence_data: sentences[sentence] = Sentence.create(sentence_data[sentence], restrict) else: assert False return PhraseGroup(name, targets, sentences, rank)
def create(pattern, data, group_name, option, size, global_rank): assert isinstance(data, dict) ranks = [] attributes = {} if RANK_KEY in data: raw_data = data[RANK_KEY] if isinstance(raw_data, list): for rank_data in raw_data: ranks.append(Rank.create(rank_data)) else: ranks.append(Rank.create(raw_data)) elif global_rank: ranks.append(Rank.create(global_rank)) else: ranks.append(Rank.create_default()) if ATTRIBUTE_KEY in data: raw_data = data[ATTRIBUTE_KEY] assert isinstance(raw_data, dict) for key in raw_data: assert type(raw_data[key]) in [unicode, list] attribute_value = [ raw_data[key] ] if type(raw_data[key]) is unicode else raw_data[key] attributes[key] = attribute_value location = data[LOCATION_KEY] if LOCATION_KEY in data else None if location and not os.path.exists(location): warning("directory \"%s\" does not exist" % location) return None return Image(pattern, group_name, ranks, attributes, option, size, location)
def create(data=None, global_restrict=None): if not data: return Sentence(Rank.create_default(), global_restrict, {}) assert isinstance(data, dict) rank = Rank.create(data["rank"]) if "rank" in data else Rank.create_default() restrict = str(data["restrict"]) if "restrict" in data else global_restrict default_values = {} if "default_value" in data: raw_data = data["default_value"] assert isinstance(raw_data, dict) for var_name in raw_data: default_values[var_name] = raw_data[var_name] return Sentence(rank, restrict, default_values)
def create(pattern, data, group_name, option, size, global_rank): assert isinstance(data, dict) ranks = [] attributes = {} if "rank" in data: raw_data = data["rank"] if isinstance(raw_data, list): for rank_data in raw_data: ranks.append(Rank.create(rank_data)) else: ranks.append(Rank.create(raw_data)) elif global_rank: ranks.append(Rank.create(global_rank)) else: ranks.append(Rank.create_default()) if "attribute" in data: raw_data = data["attribute"] assert isinstance(raw_data, dict) for key in raw_data: assert type(raw_data[key]) in [unicode, list] attribute_value = [raw_data[key]] if type(raw_data[key]) is unicode else raw_data[key] attributes[key] = attribute_value location = data["location"] if "location" in data else None return Image(pattern, group_name, ranks, attributes, option, size, location)