Ejemplo n.º 1
0
def clauses_by_sense(bwnid):
    synset = bwn.get_synset(bwnid)
    occurrences = synset.get_occurrences(rendered=False)
    word_numbers = []
    for tkn_obj in occurrences:
        word_numbers.extend(tkn_obj.get_wns())
    clauses = cl.Clause.objects.filter(verb_word_number__wn__in=word_numbers) if word_numbers else None
    return clauses
Ejemplo n.º 2
0
import django; django.setup()
import codecs
import logos.bwn.models as bwn
import logos.wn.models as wn

data = []
f = codecs.open("C:/tmp/antonym_interactive_test.txt", "r", "utf-16")

for line in f.readlines():
    line_data=line.split("\t")
    if line_data[1] == "antonym":
        data.append(line_data)

for item in data:
    ss1 = bwn.get_synset(item[0])
    ss2 = bwn.get_synset(item[2])
    if ss1 != None and ss2 != None:
        ss1_tokens = [token.get_wn_token() for token in ss1.get_occurrences(rendered=False)]
        refs = [token.milestone for token in ss1_tokens]
        for ref in refs:
            words = [word for word in ref.get_word_numbers()]
            for word in words:
                try:
                    wn_obj = wn.WordNumber.objects.get(wn=word)
                    check_sense = bwn.get_sense_at_wordnumber_id(wn_obj.id)
                    if check_sense == ss2:
                        print("{0}: {1} - {2}".format(ref.get_renderedreference(), ss1.get_label(), ss2.get_label()))
                    else:
                        check_sense = None
                except:
                    pass
Ejemplo n.º 3
0
__author__ = 'jeremy.thompson'

import django; django.setup()

from fuzzywuzzy import fuzz

import logos.bwn.models as bwn

fig_symbol = bwn.get_synset("hurt_crush.v.05").label.strings.filter(language="en")[0].string.split(" ")[2]
figs = bwn.Synset.objects.filter(label__strings__string__contains=fig_symbol)

for fig in figs:
	wns = [occ for occ in fig.get_occurrences(rendered=False)]
	fig_label = fig.get_label()
	try:
		source = fig_label.split(fig_symbol)[1].lstrip(" ")
		target = fig_label.split(fig_symbol)[0].replace("to ", "")
		for word in wns:
			try:
				import pdb; pdb.set_trace()
				gloss = word.wordnumber.token_set.filter(database=1)[0].get_gloss().gloss
				source_ratio = fuzz.partial_ratio(source, gloss)
				target_ratio = fuzz.partial_ratio(target, gloss)
				print word.wordnumber.token_set.filter(database=1)[0].milestone.reference, \
					source, source_ratio, target, target_ratio
			except: pass
	except IndexError:
		print fig_label, " is bad"