def main(): updated_count = 0 for raw in RawAssertion.objects.filter( predicate__id__isnull=True)[:1000].iterator(): try: concept1 = Concept.get(raw.text1, raw.language_id) concept2 = Concept.get(raw.text2, raw.language_id) assertions = list( Assertion.objects.filter(stem1=concept1, stem2=concept2, predtype__id=raw.predtype_id)) if len(assertions) == 0: no_assertion.add(raw.id) elif len(assertions) == 1: updated_count += 1 raw.predicate = assertions[0] raw.save() else: nonunique.add(raw.id) except: failed.add(raw.id) print 'Updated', updated_count, 'assertions' print 'No assertion for', len(no_assertion), 'assertions' print 'Non-unique assertion for', len(nonunique), 'assertions' print len(failed), 'failed.'
def run_eval(concept): normalized_concept = Concept.get(concept, en).text yes = [] no = [] maybe = [] n = 0 while n < lim: n += 1 feature = questioner.get_question_stateless(yes, no, maybe, threshold=.5) response = does_concept_have_feature(concept, feature) print '%s%s' % ({True: '+', False: '-', None: '?'}[response], feature) if response is True: yes.append(feature) elif response is False: no.append(feature) else: maybe.append(feature) if n % 5 == 0: # Make a guess #print yes, no, maybe concepts_weighted = aspace_questioner.get_likely_concepts(5, yes, no, maybe) concepts = [c[0] for c in concepts_weighted] print concepts if normalized_concept in concepts: print 'Got it in', n return n return False
def does_concept_have_feature(concept, feature): relation, other, slot = v.from_feature(feature) if slot == 1: c1, c2 = concept, other else: c1, c2 = other, concept c1_obj = Concept.get_raw(c1, 'en') c2_obj = Concept.get_raw(c2, 'en') data = list(a.filter(concept1=c1_obj, relation__name=relation, concept2=c2_obj)) if len(data) > 0: return data[0].score > 0 if (concept, feature) not in feature_cache: ans = raw_input('%s %s? ' % (concept, feature)) res = dict(y=True, n=False, m=None)[ans[0].lower()] add_to_feature_cache(concept, feature, res) return feature_cache[concept, feature]
def main(): updated_count = 0 for raw in RawAssertion.objects.filter(predicate__id__isnull=True)[:1000].iterator(): try: concept1 = Concept.get(raw.text1, raw.language_id) concept2 = Concept.get(raw.text2, raw.language_id) assertions = list(Assertion.objects.filter(stem1=concept1, stem2=concept2, predtype__id=raw.predtype_id)) if len(assertions) == 0: no_assertion.add(raw.id) elif len(assertions) == 1: updated_count += 1 raw.predicate = assertions[0] raw.save() else: nonunique.add(raw.id) except: failed.add(raw.id) print 'Updated', updated_count, 'assertions' print 'No assertion for', len(no_assertion), 'assertions' print 'Non-unique assertion for', len(nonunique), 'assertions' print len(failed), 'failed.'
def concept(request, lang, concept_name): '''View for displaying a concept, specified by text.''' language = get_language(lang) try: concept = Concept.get(concept_name, language) except Concept.DoesNotExist: return respond_with('commonsense/concept_noinfo.html', request, {'lang': lang, 'concept_name': concept_name}) queryset = concept.raw_assertions_no_dupes().select_related('surface1', 'surface2', 'frame') return respond_with('commonsense/concept.html', request, dict( concept_name=concept_name, concept=concept, lang=lang, user=request.user, language=language, raw_assertions=queryset ))
def concept_lookup(concept, lang): return Concept.get_raw(concept, lang)
# This is a dummy python file for getting the next question. import random import pdb from csc.conceptnet.models import Concept, Relation LANG = 'en' import pdb #pdb.set_trace() DUMMIES = [(Relation.get("HasProperty"), Concept.get("fuzzy", LANG), True), (Relation.get("HasProperty"), Concept.get("shiny", LANG), True), (Relation.get("Causes"), Concept.get("weariness", LANG), True), (Relation.get("UsedFor"), Concept.get("battle", LANG), True), (Relation.get("IsA"), Concept.get("frog", LANG), True)] DefaultQuestionBlob = (Relation.get("CausesDesire"), Concept.get("eat cake", LANG), True) VALID = [True, False] def get_question(state): # state is a dictionary of features to truth values next = DUMMIES[int(random.random() * len(DUMMIES))] if not next in state: return next else: return DEFAULT