def test_custom_plot(): Token.set_extension('plot', default={'color': 'aquamarine'}) for token in doc: node_label = '{0} [{1}]\n({2} / {3})'.format(token.orth_, token.i, token.pos_, token.tag_) token._.plot['label'] = node_label if token.dep_ in ['ROOT', 'acl']: token._.plot['color'] = 'dodgerblue' if token.dep_ in ['nsubj', 'dobj']: token._.plot['color'] = 'deeppink1' plot = visualise_spacy_tree.create_png(doc) with open(os.path.join(example_plot_dir, 'custom_plot.png'), 'wb') as f: f.write(plot)
def test_visualise_pattern(): for i, doc in enumerate(docs): png = visualise_spacy_tree.create_png(doc) filepath = 'examples/sentence_vis/sentence_{}.png'.format(i) with open(filepath, 'wb') as f: f.write(png) feature_dict = {'DEP': 'dep_', 'TAG': 'tag_', 'LOWER': 'lower_'} for test_i, case in enumerate(cases): match_example = case['training_example']['match'] role_pattern_builder = RolePatternBuilder(feature_dict) for features_i, features in enumerate(feature_combs): role_pattern = role_pattern_builder.build(match_example, features=features) filepath = 'examples/spacy_dep_patterns/pattern_{}_{}.json'.format( test_i, features_i) with open(filepath, 'w') as f: json.dump(role_pattern.spacy_dep_pattern, f, indent=2) outpath = 'examples/pattern_vis/pattern_{0}_{1}.png'.format( test_i, features_i) role_pattern.write_vis(outpath, legend=True)
else: schemes.append(span) return schemes # apply function df2['Schemes1'] = df2.apply( lambda x: all_schemes(x.Sent, x.Check_Schemes), axis=1) # nlp_ie_12.py # To understand the structure of the sentence. doc = nlp(' Last year, I spoke about the Ujjwala programme, through which, I am happy to report, 50 million free liquid-gas connections have been provided so far') png = visualise_spacy_tree.create_png(doc) display(Image(png)) # nlp_ie_13.py # rule to extract initiative name def sent_subtree(text): """sent_subtree, In tree view to get the proper nouns in the subtree for initiative name. Args: text: """ # pattern match for schemes or initiatives
def dep_analyzer(my_text): #nlp = load_model('models1') docx = nlp(my_text) docx=darcolor(docx) png = visualise_spacy_tree.create_png(docx) return png
def test_partial_plot(): tokens = [doc[0], doc[1], doc[3]] plot = visualise_spacy_tree.create_png(tokens) with open(os.path.join(example_plot_dir, 'default_partial_plot.png'), 'wb') as f: f.write(plot)
def test_default_plot(): plot = visualise_spacy_tree.create_png(doc) with open(os.path.join(example_plot_dir, 'default_plot.png'), 'wb') as f: f.write(plot)
def tree(doc: Union[Doc, Span]): png = visualise_spacy_tree.create_png(doc) return display(Image(png))