Example #1
0
    def get_similar_word_array(self, tag):
        formatted_word = db_tools.wordnet_formatted(tag)

        # pprint_object(formatted_word)

        alternative_words = db_tools.list_wordnet_links(formatted_word[1]['synset'])

        # pprint_object(alternative_words)

        word_list = []
        for word in alternative_words:
            word_list.append(word[0])

        # self.pprint_object(word_list)

        return word_list
Example #2
0
def alt_tags(tag_text, image, user):
    tag_synset = None

    if len(tag_text) == 1:
        return

    synsets = catch_edge_cases(tag_text)

    if synsets is None:
        stem = wn.morphy(tag_text.lower())
        if stem is not None:
            tag_text = stem

        synsets = db_tools.wordnet_formatted(tag_text)

        print tag_text
        for synset in synsets:
            if synset['label'] == tag_text.lower() and synset['sensenum'] == 1 and '.n.' in synset['synset']:
                print pprint.pformat(synset)
                tag_synset = synset['synset']

    else:
        if len(synsets) > 0:
            tag_synset = synsets[0]['synset']

    if tag_synset is not None:

        alternative_words = db_tools.list_wordnet_links(tag_synset)[::-1]

        for index, weighted_word in enumerate(alternative_words):
            word = weighted_word[0]
            print word

            tag_order = str((int(clean(str(0), strip=True)) + 1) * 100)

            tag_hyp_dist = int(weighted_word[1][0]) + 1
            tag_syn_val = int(weighted_word[1][1]) + 1
            tag_order += str(tag_hyp_dist * 100) + str(tag_syn_val * 100)
            print tag_order

            write_tag(word, image, user, tag_order=tag_order)