for i, tree in enumerate(chunked_corpus.parsed_sents(**kwargs)): try: chunk_trees.append(transforms.flatten_deeptree(tree)) except AttributeError as exc: if args.trace > 1: print('skipping bad tree %d: %s' % (i, exc)) elif args.shallow_tree: if args.trace: print('creating shallow trees from %s' % args.corpus) chunk_trees = [] for i, tree in enumerate(chunked_corpus.parsed_sents(**kwargs)): try: chunk_trees.append(transforms.shallow_tree(tree)) except AttributeError as exc: if args.trace > 1: print('skipping bad tree %d: %s' % (i, exc)) elif not hasattr(chunked_corpus, 'chunked_sents'): raise ValueError('%s does not have chunked sents' % args.corpus) else: chunk_trees = chunked_corpus.chunked_sents(**kwargs) ################## ## train chunks ## ################## nchunks = len(chunk_trees) if args.fraction == 1.0:
for i, tree in enumerate(chunked_corpus.parsed_sents(**kwargs)): try: chunk_trees.append(transforms.flatten_deeptree(tree)) except AttributeError as exc: if args.trace > 1: print 'skipping bad tree %d: %s' % (i, exc) elif args.shallow_tree: if args.trace: print 'creating shallow trees from %s' % args.corpus chunk_trees = [] for i, tree in enumerate(chunked_corpus.parsed_sents(**kwargs)): try: chunk_trees.append(transforms.shallow_tree(tree)) except AttributeError as exc: if args.trace > 1: print 'skipping bad tree %d: %s' % (i, exc) elif not hasattr(chunked_corpus, 'chunked_sents'): raise ValueError('%s does not have chunked sents' % args.corpus) else: chunk_trees = chunked_corpus.chunked_sents(**kwargs) ################## ## train chunks ## ################## nchunks = len(chunk_trees) if args.fraction == 1.0: