Exemplo n.º 1
0
def create_metadata(args):
    """Creates a Metadata object from the given arguments."""
    # using getattr because the SRL args object doesn't have a "suffix" attribute
    use_caps = getattr(args, 'caps', False)
    use_suffix = getattr(args, 'suffix', False)
    use_prefix = getattr(args, 'prefix', False)
    use_pos = getattr(args, 'pos', False)
    use_chunk = getattr(args, 'chunk', False)

    return metadata.Metadata(args.task, None, use_caps, use_suffix, use_prefix,
                             use_pos, use_chunk)
Exemplo n.º 2
0
    logging_level = logging.DEBUG if args.verbose else logging.INFO
    utils.set_logger(logging_level)
    logger = logging.getLogger("Logger")

    config.set_data_dir(args.data)
    text_reader = create_reader(args)

    use_caps = args.caps is not None
    use_suffix = args.suffix is not None
    use_pos = args.pos is not None
    use_chunk = args.chunk is not None
    use_lemma = args.use_lemma

    if not args.load_network:
        # if we are about to create a new network, create the metadata too
        md = metadata.Metadata(args.task, use_caps, use_suffix, use_pos,
                               use_chunk, use_lemma)
        md.save_to_file()
    else:
        md = metadata.Metadata.load_from_file(args.task)

    text_reader.create_converter(md)
    text_reader.codify_sentences()

    feature_tables = utils.load_features(args, md, text_reader)

    if args.load_network or args.semi:
        logger.info("Loading provided network...")
        nn = load_network_train(args, md)
    else:
        logger.info('Creating new network...')
        nn = create_network(args, text_reader, feature_tables, md)
Exemplo n.º 3
0
 def _set_metadata(self, md):
     if md is None:
         #metadata not provided = using global data_dir for files
         self.md = metadata.Metadata(self.task, config.FILES)
     else:
         self.md = md
Exemplo n.º 4
0
    utils.set_logger(logging_level)
    logger = logging.getLogger("Logger")

    config.set_data_dir(args.data)

    use_caps = getattr(args, 'caps', False)
    use_suffix = getattr(args, 'suffix', False)
    use_prefix = getattr(args, 'prefix', False)
    use_pos = getattr(args, 'pos', False)
    use_chunk = getattr(args, 'chunk', False)
    use_lemma = getattr(args, 'lemma', False)
    use_gazetteer = getattr(args, 'gazetteer', False)

    if not args.load_network:
        # if we are about to create a new network, create the metadata too
        md = metadata.Metadata(args.task, use_caps, use_suffix, use_prefix,
                               use_pos, use_chunk, use_lemma, use_gazetteer)
        md.save_to_file()
    else:
        md = metadata.Metadata.load_from_file(args.task)

    text_reader = create_reader(args, md)

    text_reader.create_converter()
    text_reader.codify_sentences()

    if args.load_network:
        logger.info("Loading provided network...")
        nn = load_network_train(args, md)
    else:
        logger.info('Creating new network...')
        feature_tables = utils.load_features(args, md, text_reader)