Exemplo n.º 1
0
def get_dict_vectors_word_for_word(word):
  vectors = OrderedDict()
  definitions = OxfordParser.get_definitions_of_word(word)
  for definition in definitions:
    vector = PreprocessDefinition.preprocess_sentence(definition)
    key = definition
    vectors[key] = vector

  return vectors
def get_dict_vectors_words_for_word(word):
  vectors = OrderedDict()
  synsets = WordnetHandler.get_synsets_for_word(word, 'n')
  for synset in synsets:
    definition = synset.definition()
    vector = PreprocessDefinition.preprocess_sentence(definition)
    key = synset.definition()
    vectors[key] = vector

  return vectors
Exemplo n.º 3
0
def get_definition_synset_with_synsetwn(definition, synsets_wn):
  definition_synsets = []
#  nouns = PreprocessDefinition.preprocess_sentence_to_nouns(definition)
  nouns = PreprocessDefinition.preprocess_sentence(definition)
#  nouns = list(set(nouns))
  for noun in nouns:
    synset_max = get_greatest_synset_similarity_between(synsets_wn, noun)
    if synset_max is not None:
      definition_synsets.append((synset_max,1))

  return definition_synsets
def get_definition_synset(synset):
  key = synset.name()
  if key not in __dict_defi_for_synset__:
    synsets_definition = []
    definition = synset.definition()
  #  nouns = PreprocessDefinition.preprocess_sentence_to_nouns(definition)
    nouns = PreprocessDefinition.preprocess_sentence(definition)
#    nouns = list(set(nouns))
    for noun in nouns:
      synset_max = get_greatest_synset_similarity_between(synset, noun)
      if synset_max is not None:
        synsets_definition.append(synset_max)
    __dict_defi_for_synset__[key] = synsets_definition

  return __dict_defi_for_synset__[key]
def get_feature_synset_for(synset):
  key = synset.name()
  if key not in __dict_feature_for_synset:
    synsets_definition = []
    definition = synset.definition()
    nouns = PreprocessDefinition.preprocess_sentence(definition)
#    nouns = list(set(nouns))
    for noun in nouns:
      synset_max = get_greatest_synset_similarity_between(synset, noun)
      if synset_max is not None:
        synsets_definition.append((synset_max,PARAMS.PARAMS_WN.DEFI))
#
#      # # - - - - - - - - - - - - - - - - - - - - - - - - - - -
#      # # get hypernyms
#      # print "\nhypernyms ------";
#    for hypernym in synset.hypernyms():
#      synsets_definition.append((hypernym,PARAMS.PARAMS_WN.HYPER))
#
#      # - - - - - - - - - - - - - - - - - - - - - - - - - - -
#      # get hyponyms
#    for hyponym in synset.hyponyms():
#      synsets_definition.append((hyponym,PARAMS.PARAMS_WN.HYPO))
#
#    for meronym in synset.part_meronyms():
#      synsets_definition.append((meronym,PARAMS.PARAMS_WN.MERO))
#
#    for holonym in synset.member_holonyms():
#      synsets_definition.append((holonym,PARAMS.PARAMS_WN.HOLO))
#
#    for example in synset.examples():
#      for lemma in synset.lemmas():
#        example = example.replace(lemma.name(), "")
#      nouns = PreprocessDefinition.preprocess_sentence(example)
#      nouns = list(set(nouns))
#      for noun in nouns:
#        synset_max = get_greatest_synset_similarity_between(synset, noun)
#        if synset_max is not None:
#          synsets_definition.append((synset_max,PARAMS.PARAMS_WN.EX))
#
    synsets_definition.append((synset,PARAMS.PARAMS_WN.MAIN))
    __dict_feature_for_synset[key] = synsets_definition

  return __dict_feature_for_synset[key]
def get_value_synset_for(cur_synset, synsets):
  synsets_value = []
  definition = cur_synset.definition()
  nouns = PreprocessDefinition.preprocess_sentence(definition)
#  nouns = list(set(nouns))
  for synset in synsets:
    count = 0
    p = 0
    for noun in nouns:
      synset_max = get_greatest_synset_similarity_between(synset, noun)
      if synset_max is not None:
        count += 1
        sim = WordnetHandler.cal_similarity(synset, synset_max)
        if sim != None:
          p += sim

    if count != 0:
      p = p/count

    synsets_value.append(p)

  return synsets_value
Exemplo n.º 7
0
def get_definition_value_with_synsetwn(definition, synsets_wn):
  synsets_value = []
#  nouns = PreprocessDefinition.preprocess_sentence_to_nouns(definition)
  nouns = PreprocessDefinition.preprocess_sentence(definition)
#  nouns = list(set(nouns))
  for synset in synsets_wn:
    count = 0
    p = 0
    for noun in nouns:
      synset_max = get_greatest_synset_similarity_between([synset], noun)
      if synset_max is not None:
        count += 1
        sim = WordnetHandler.cal_similarity(synset, synset_max)
        if sim != None:
          p += sim

    if count != 0:
      p = p/count

    synsets_value.append(p)

  return synsets_value