Пример #1
0
def parse(origin, graf_header_file, stamp, data_items):
    '''Parse a LAF/GrAF resource and deliver results.'''
    global identifiers_n, identifiers_e
    init()
    saxparse(graf_header_file, HeaderHandler())

    osep = ':' if origin[0] == 'a' else ''
    if origin == 'm':
        with open(primary_data_file, "r", encoding="utf-8") as f: primary_data = f.read(None)
        Names.deliver(primary_data, (origin + osep + 'P00', ('primary_data',)), data_items)

    for kind in ('n', 'e'):
        xi_key = Names.comp('mX' + kind + 'f', ())
        xmlitems = data_items[xi_key] if xi_key in data_items else {}
        if kind == 'n':
            identifiers_n = xmlitems
        else:
            identifiers_e = xmlitems

    for annotation_file in annotation_files:
        stamp.Imsg("parsing {}".format(annotation_file))
        saxparse(annotation_file, AnnotationHandler(annotation_file, stamp))

    mg = '''END PARSING
{:>10} good   regions  and {:>5} faulty ones
{:>10} linked nodes    and {:>5} unlinked ones
{:>10} good   edges    and {:>5} faulty ones
{:>10} good   annots   and {:>5} faulty ones
{:>10} good   features and {:>5} faulty ones
{:>10} distinct xml identifiers
'''.format(
        good_regions, faulty_regions,
        linked_nodes, unlinked_nodes,
        good_edges, faulty_edges,
        good_annots, faulty_annots,
        good_feats, faulty_feats,  
        id_region + id_node + id_edge + id_annot,
    )
    stamp.Imsg(mg)
    if origin == 'm':
        Names.deliver(identifiers_n, (origin + osep + 'Xnf', ()), data_items)
        Names.deliver(identifiers_e, (origin + osep + 'Xef', ()), data_items)
        Names.deliver(edges_from, (origin + osep + 'G00', ('edges_from',)), data_items)
        Names.deliver(edges_to, (origin + osep + 'G00', ('edges_to',)), data_items)
        Names.deliver(region_begin, (origin + osep + 'T00', ('region_begin',)), data_items)
        Names.deliver(region_end, (origin + osep + 'T00', ('region_end',)), data_items)
        Names.deliver(node_region_list, (origin + osep + 'T00', ('node_region_list',)), data_items)

    for f in feature: Names.deliver(feature[f], (origin + osep + 'Fn0', f), data_items)
    for f in efeature: Names.deliver(efeature[f], (origin + osep + 'Fe0', f), data_items)
Пример #2
0
def saxparse(f,handler):
	from xml.sax import parse as saxparse
	saxparse (f, handler)