Esempio n. 1
0
def make_all_tiers(item_data, options):
    tier_map = options['tier_map']
    tier_types = options['tier_types']
    alignments = options['alignments']
    tb_alignments = options['tb_alignments']
    phrase_opts = options.get('make_phrase_tier')
    aligned_tiers = set(tb_alignments.keys()).union(tb_alignments.values())
    # use strip=False because we want same-length strings
    tier_data = toolbox.normalize_record(item_data, aligned_tiers, strip=False)
    prev = {}
    aligned_fields = toolbox.align_fields(
        tier_data, tb_alignments, errors=options['error_recovery_method']
    )
    for mkr, aln_tokens in aligned_fields:
        if mkr not in tier_map:
            continue
        tier_id = tier_map.get(mkr)
        if phrase_opts and phrase_opts[0] == tier_id:
            tier = make_phrase_tier(phrase_opts[1], aln_tokens)
            prev[phrase_opts[1]] = tier
            yield tier
        tier_type = tier_types[tier_id].get('type')
        refattr, aln_id = alignments.get(tier_id, (None, None))
        algn_tier = prev.get(aln_id)  # could be None
        try:
            tier = make_tier(tier_type, tier_id,
                             refattr, aln_tokens, algn_tier)
        except (AttributeError, AssertionError):
            raise XigtImportError('Error making {} tier (marker: {}).'
                                  .format(tier_type, mkr))
        prev[tier_id] = tier
        yield tier
Esempio n. 2
0
File: toolbox.py Progetto: xigt/xigt
def make_all_tiers(item_data, options):
    tier_map = options['tier_map']
    tier_types = options['tier_types']
    alignments = options['alignments']
    tb_alignments = options['tb_alignments']
    phrase_opts = options.get('make_phrase_tier')
    aligned_tiers = set(tb_alignments.keys()).union(tb_alignments.values())
    # use strip=False because we want same-length strings
    tier_data = toolbox.normalize_record(item_data, aligned_tiers, strip=False)
    prev = {}
    aligned_fields = toolbox.align_fields(
        tier_data, tb_alignments, errors=options['error_recovery_method']
    )
    for mkr, aln_tokens in aligned_fields:
        if mkr not in tier_map:
            continue
        tier_id = tier_map.get(mkr)
        if phrase_opts and phrase_opts[0] == tier_id:
            tier = make_phrase_tier(phrase_opts[1], aln_tokens)
            prev[phrase_opts[1]] = tier
            yield tier
        tier_type = tier_types[tier_id].get('type')
        refattr, aln_id = alignments.get(tier_id, (None, None))
        algn_tier = prev.get(aln_id)  # could be None
        try:
            tier = make_tier(tier_type, tier_id,
                             refattr, aln_tokens, algn_tier)
        except (AttributeError, AssertionError):
            raise XigtImportError('Error making {} tier (marker: {}).'
                                  .format(tier_type, mkr))
        prev[tier_id] = tier
        yield tier
Esempio n. 3
0
def make_all_tiers(item_data, tier_types, alignments):
    aligned_tiers = set(alignments.keys()).union(alignments.values())
    # use strip=False because we want same-length strings
    tier_data = toolbox.normalize_record(item_data, aligned_tiers, strip=False)
    prev = {}
    aligned_fields = toolbox.align_fields(tier_data, alignments, errors="ratio")
    for mkr, aligned_tokens in aligned_fields:
        tier_type = tier_types.get(mkr)
        tier_id = mkr.lstrip("\\")
        algn_tier = prev.get(alignments.get(mkr))  # could be None
        try:
            tier = make_tier(tier_type, tier_id, aligned_tokens, algn_tier)
        except (AttributeError, AssertionError):
            raise XigtImportError("Error making {} tier (marker: {}).".format(tier_type, mkr))
        prev[mkr] = tier
        yield tier
Esempio n. 4
0
def make_all_tiers(item_data, options):
    tier_types = options['tier_types']
    alignments = options['alignments']
    aligned_tiers = set(alignments.keys()).union(alignments.values())
    # use strip=False because we want same-length strings
    tier_data = toolbox.normalize_record(item_data, aligned_tiers, strip=False)
    prev = {}
    aligned_fields = toolbox.align_fields(
        tier_data, alignments, errors=options['error_recovery_method'])
    for mkr, aligned_tokens in aligned_fields:
        tier_type = tier_types.get(mkr)
        tier_id = mkr.lstrip('\\')
        algn_tier = prev.get(alignments.get(mkr))  # could be None
        try:
            tier = make_tier(tier_type, tier_id, aligned_tokens, algn_tier)
        except (AttributeError, AssertionError):
            raise XigtImportError('Error making {} tier (marker: {}).'.format(
                tier_type, mkr))
        prev[mkr] = tier
        yield tier