@@ -353,7 +353,7 @@ def unweighted_minimum_spanning_digraph(tree, children=iter, shapes=None, attr=N
353353 >>> import nltk
354354 >>> wn=nltk.corpus.wordnet
355355 >>> from nltk.util import unweighted_minimum_spanning_digraph as umsd
356- >>> print(umsd(wn.synset('bound.a.01'), lambda s:s.also_sees()))
356+ >>> print(umsd(wn.synset('bound.a.01'), lambda s:sorted( s.also_sees() )))
357357 digraph G {
358358 "Synset('bound.a.01')" -> "Synset('unfree.a.02')";
359359 "Synset('unfree.a.02')" -> "Synset('confined.a.02')";
@@ -377,7 +377,7 @@ def unweighted_minimum_spanning_digraph(tree, children=iter, shapes=None, attr=N
377377##########################################################################
378378
379379
380- def acyclic_breadth_first (tree , children = iter , maxdepth = - 1 ):
380+ def acyclic_breadth_first (tree , children = iter , maxdepth = - 1 , verbose = False ):
381381 """Traverse the nodes of a tree in breadth-first order,
382382 discarding eventual cycles.
383383
@@ -397,17 +397,18 @@ def acyclic_breadth_first(tree, children=iter, maxdepth=-1):
397397 if child not in traversed :
398398 queue .append ((child , depth + 1 ))
399399 else :
400- warnings .warn (
401- "Discarded redundant search for {} at depth {}" .format (
402- child , depth + 1
403- ),
404- stacklevel = 2 ,
405- )
400+ if verbose :
401+ warnings .warn (
402+ "Discarded redundant search for {} at depth {}" .format (
403+ child , depth + 1
404+ ),
405+ stacklevel = 2 ,
406+ )
406407 except TypeError :
407408 pass
408409
409410
410- def acyclic_depth_first (tree , children = iter , depth = - 1 , cut_mark = None , traversed = None ):
411+ def acyclic_depth_first (tree , children = iter , depth = - 1 , cut_mark = None , traversed = None , verbose = False ):
411412 """Traverse the nodes of a tree in depth-first order,
412413 discarding eventual cycles within any branch,
413414 adding cut_mark (when specified) if cycles were truncated.
@@ -422,7 +423,7 @@ def acyclic_depth_first(tree, children=iter, depth=-1, cut_mark=None, traversed=
422423 >>> from nltk.util import acyclic_depth_first as acyclic_tree
423424 >>> wn=nltk.corpus.wordnet
424425 >>> from pprint import pprint
425- >>> pprint(acyclic_tree(wn.synset('dog.n.01'), lambda s:s.hypernyms(),cut_mark='...'))
426+ >>> pprint(acyclic_tree(wn.synset('dog.n.01'), lambda s:sorted( s.hypernyms() ),cut_mark='...'))
426427 [Synset('dog.n.01'),
427428 [Synset('canine.n.02'),
428429 [Synset('carnivore.n.01'),
@@ -454,12 +455,13 @@ def acyclic_depth_first(tree, children=iter, depth=-1, cut_mark=None, traversed=
454455 )
455456 ]
456457 else :
457- warnings .warn (
458- "Discarded redundant search for {} at depth {}" .format (
459- child , depth - 1
460- ),
461- stacklevel = 3 ,
462- )
458+ if verbose :
459+ warnings .warn (
460+ "Discarded redundant search for {} at depth {}" .format (
461+ child , depth - 1
462+ ),
463+ stacklevel = 3 ,
464+ )
463465 if cut_mark :
464466 out_tree += [f"Cycle({ child } ,{ depth - 1 } ,{ cut_mark } )" ]
465467 except TypeError :
@@ -470,7 +472,7 @@ def acyclic_depth_first(tree, children=iter, depth=-1, cut_mark=None, traversed=
470472
471473
472474def acyclic_branches_depth_first (
473- tree , children = iter , depth = - 1 , cut_mark = None , traversed = None
475+ tree , children = iter , depth = - 1 , cut_mark = None , traversed = None , verbose = False
474476):
475477 """Traverse the nodes of a tree in depth-first order,
476478 discarding eventual cycles within the same branch,
@@ -488,7 +490,7 @@ def acyclic_branches_depth_first(
488490 >>> from nltk.util import acyclic_branches_depth_first as tree
489491 >>> wn=nltk.corpus.wordnet
490492 >>> from pprint import pprint
491- >>> pprint(tree(wn.synset('certified.a.01'), lambda s:s.also_sees(), cut_mark='...', depth=4))
493+ >>> pprint(tree(wn.synset('certified.a.01'), lambda s:sorted( s.also_sees() ), cut_mark='...', depth=4))
492494 [Synset('certified.a.01'),
493495 [Synset('authorized.a.01'),
494496 [Synset('lawful.a.01'),
@@ -527,12 +529,13 @@ def acyclic_branches_depth_first(
527529 )
528530 ]
529531 else :
530- warnings .warn (
531- "Discarded redundant search for {} at depth {}" .format (
532- child , depth - 1
533- ),
534- stacklevel = 3 ,
535- )
532+ if verbose :
533+ warnings .warn (
534+ "Discarded redundant search for {} at depth {}" .format (
535+ child , depth - 1
536+ ),
537+ stacklevel = 3 ,
538+ )
536539 if cut_mark :
537540 out_tree += [f"Cycle({ child } ,{ depth - 1 } ,{ cut_mark } )" ]
538541 except TypeError :
@@ -563,7 +566,7 @@ def unweighted_minimum_spanning_dict(tree, children=iter):
563566 >>> from nltk.corpus import wordnet as wn
564567 >>> from nltk.util import unweighted_minimum_spanning_dict as umsd
565568 >>> from pprint import pprint
566- >>> pprint(umsd(wn.synset('bound.a.01'), lambda s:s.also_sees()))
569+ >>> pprint(umsd(wn.synset('bound.a.01'), lambda s:sorted( s.also_sees() )))
567570 {Synset('bound.a.01'): [Synset('unfree.a.02')],
568571 Synset('classified.a.02'): [],
569572 Synset('confined.a.02'): [],
@@ -605,7 +608,7 @@ def unweighted_minimum_spanning_tree(tree, children=iter):
605608 >>> from nltk.util import unweighted_minimum_spanning_tree as mst
606609 >>> wn=nltk.corpus.wordnet
607610 >>> from pprint import pprint
608- >>> pprint(mst(wn.synset('bound.a.01'), lambda s:s.also_sees()))
611+ >>> pprint(mst(wn.synset('bound.a.01'), lambda s:sorted( s.also_sees() )))
609612 [Synset('bound.a.01'),
610613 [Synset('unfree.a.02'),
611614 [Synset('confined.a.02')],
0 commit comments