def similarityWords(dictOxfordNouns):

  print "\n --------------------------------------------------"
  print "new round"

  total_precision = 0;
  total_recall = 0;
  total_accuracy = 0;
  missingWORD = 0;
  total_word = 0
  count_step = 0

  for word in dictOxfordNouns:
    # print dictOxfordNouns[word]
    # if word == 'baby':
    matrix_result = similarity_by_synsets_synsets_nbest_withword_average(word,dictOxfordNouns[word]);

    if matrix_result == None:
      missingWORD += 1;
      continue

    # print "\n"
    print word

    (precision, recall, accuracy) = CompareWithGold.compareGoldWithResult(matrix_result,word)
    # print (precision, recall, accuracy)
    if precision != -1:
      total_precision += precision
      total_recall += recall
      total_accuracy += accuracy
      total_word += 1
      count_step += 1
      # print "result -------"
      # print precision
      # print recall
      # print accuracy
      # print "\n"
    else:
      missingWORD += 1

  # total_word = len(dictOxfordNouns) - missingWORD
  precision = total_precision/total_word
  recall = total_recall/total_word
  accuracy = total_accuracy/total_word
  print "total:"
  print total_word
  print precision
  print recall
  print accuracy

  WriteParametersAndResult.append_result_to_file(precision,recall,accuracy)
  return (precision, recall, accuracy)
Пример #2
0
def sim_ox_wn_via_definition_cal_word():

  total_precision = 0;
  total_recall = 0;
  total_accuracy = 0;
  total_word = 0

  dict_ox = OxfordParser.get_dict_nouns()
  for word in dict_ox:

    if word not in __m2d_sim__:
      m2d_sim = sim_ox_wn_definition(word)
      __m2d_sim__[word] = m2d_sim

    m2d_sim = copy.deepcopy(__m2d_sim__[word])

    if m2d_sim == None or len(m2d_sim) == 0 or len(m2d_sim[0]) == 0:
      continue

    print word
#
#    if len(m2d_sim) == 1 and len(m2d_sim[0]) == 1:
#      continue
#
    m2d_sim = choose_pair_0_1(m2d_sim, len(m2d_sim), len(m2d_sim[0]))

    (precision, recall, accuracy) = CompareWithGold.compareGoldWithResult(m2d_sim,word)
    if precision != -1:
      total_precision += precision
      total_recall += recall
      total_accuracy += accuracy
      total_word += 1

  precision = total_precision/total_word
  recall = total_recall/total_word
  f_score = 0
  if precision != 0 or recall != 0:
    f_score = 2*(precision*recall)/(precision + recall)
  accuracy = total_accuracy/total_word
  print "total:"
  print total_word
  print precision
  print recall
  print f_score
  print accuracy

  Parameters.append_result_to_file( precision, recall, f_score, accuracy)