@@ -309,7 +309,7 @@ def __init__ (
309
309
# effectively, performs the same work as the `reset()` method;
310
310
# called explicitly here for the sake of type annotations
311
311
self .elapsed_time : float = 0.0
312
- self .lemma_graph : nx .DiGraph = nx .DiGraph ()
312
+ self .lemma_graph : nx .Graph = nx .Graph ()
313
313
self .phrases : typing .List [Phrase ] = []
314
314
self .ranks : typing .Dict [Lemma , float ] = {}
315
315
self .seen_lemma : typing .Dict [Lemma , typing .Set [int ]] = OrderedDict ()
@@ -323,7 +323,7 @@ def reset (
323
323
removing any pre-existing state.
324
324
"""
325
325
self .elapsed_time = 0.0
326
- self .lemma_graph = nx .DiGraph ()
326
+ self .lemma_graph = nx .Graph ()
327
327
self .phrases = []
328
328
self .ranks = {}
329
329
self .seen_lemma = OrderedDict ()
@@ -400,15 +400,15 @@ def get_personalization ( # pylint: disable=R0201
400
400
401
401
def _construct_graph (
402
402
self
403
- ) -> nx .DiGraph :
403
+ ) -> nx .Graph :
404
404
"""
405
405
Construct the
406
406
[*lemma graph*](https://derwen.ai/docs/ptr/glossary/#lemma-graph).
407
407
408
408
returns:
409
409
a directed graph representing the lemma graph
410
410
"""
411
- g = nx .DiGraph ()
411
+ g = nx .Graph ()
412
412
413
413
# add nodes made of Lemma(lemma, pos)
414
414
g .add_nodes_from (self .node_list )
@@ -571,6 +571,8 @@ def _calc_discounted_normalised_rank (
571
571
returns:
572
572
normalized rank metric
573
573
"""
574
+ if len (span ) < 1 :
575
+ return 0.0
574
576
non_lemma = len ([tok for tok in span if tok .pos_ not in self .pos_kept ])
575
577
non_lemma_discount = len (span ) / (len (span ) + (2.0 * non_lemma ) + 1.0 )
576
578
@@ -877,7 +879,7 @@ def write_dot (
877
879
path:
878
880
path for the output file; defaults to `"graph.dot"`
879
881
"""
880
- dot = graphviz .Digraph ()
882
+ dot = graphviz .Graph ()
881
883
882
884
for lemma in self .lemma_graph .nodes ():
883
885
rank = self .ranks [lemma ]
0 commit comments