def _calculate(lemmas, stems):
 n = sum((len(lemmas[word]) for word in lemmas))
 (gdmt, gdnt, gumt, gwmt) = (0.0, 0.0, 0.0, 0.0)
 for lemma in lemmas:
  lemmacount = len(lemmas[lemma])
  gdmt += (lemmacount * (lemmacount - 1))
  gdnt += (lemmacount * (n - lemmacount))
  (umt, wmt) = _calculate_cut(lemmas[lemma], stems)
  gumt += umt
  gwmt += wmt
 return ((gumt / 2), (gdmt / 2), (gwmt / 2), (gdnt / 2))

def _calculate ( lemmas , stems ) : n = sum ( ( len ( lemmas [ word ] ) for word in lemmas ) ) ( gdmt , gdnt , gumt , gwmt ) = ( 0.0 , 0.0 , 0.0 , 0.0 ) for lemma in lemmas : lemmacount = len ( lemmas [ lemma ] ) gdmt += ( lemmacount * ( lemmacount - 1 ) ) gdnt += ( lemmacount * ( n - lemmacount ) ) ( umt , wmt ) = _calculate_cut ( lemmas [ lemma ] , stems ) gumt += umt gwmt += wmt return ( ( gumt / 2 ) , ( gdmt / 2 ) , ( gwmt / 2 ) , ( gdnt / 2 ) )
calculate actual and maximum possible amounts of understemmed and overstemmed word pairs .