Example #1
0
    def append_facts(self,facts,all_answers):
        if 'where' not in facts:
            facts['where'] = {}
        if 'guess_loc' not in facts:
            facts['guess_loc'] = {}
        if 'country' not in facts['where']:
            facts['where']['country'] = []
        if 'city' not in facts['where']:
            facts['where']['city'] = []

        if self.dataitem=='country':
            facts['where']['country'] = [{'item':parseCountry(self.answer), 'probability':1.0}]
        if self.dataitem=='city':
            prob = 0.0
            for con in facts['where']['country']:
                if con['probability']>prob:
                    country = con['item']
                    prob = con['probability']
            facts['where']['city'] = [{'item':(self.answer, country), 'probability':1.0}]
        if self.dataitem=='nearcity':
            if self.answer=='yes':
                country = parseCountry(self.detail['country'])
                facts['where']['city'] = [{'item':(self.detail['city'], country), 'probability':1.0}]
                facts['where']['country'] = [{'item':country, 'probability':1.0}]
                facts['guess_loc']['ip_wrong'] = False
            else: #"no" or "don't know"
                facts['guess_loc']['ip_wrong'] = True
Example #2
0
    def pick_question(cls, questions_asked, facts, target):
        maxp = 0
        country = ''
        if 'where' in facts:
            if 'country' in facts['where']:
                for con in facts['where']['country']:
                    if maxp < con['probability']:
                        maxp = con['probability']
                        country = con['item']
        if parseCountry(country) == 'gb':
            return 'postcode', ''
        if parseCountry(country) == 'us':
            return 'zipcode', ''

        return 'None', 'None'  #we can't ask this yet.
Example #3
0
    def pick_question(cls,questions_asked,facts,target):   
        maxp = 0
        country = ''
        if 'where' in facts:
            if 'country' in facts['where']:
                for con in facts['where']['country']:                    
                    if maxp<con['probability']:
                        maxp = con['probability']
                        country = con['item']
        if parseCountry(country)=='gb':
            return 'postcode', '', 9
        if parseCountry(country)=='us':
            return 'zipcode', '', 9

        return 'None', 'None',0 #we can't ask this yet.
Example #4
0
 def append_facts(self,facts,all_answers): #TODO Move all the census stuff into integrate_location maybe?        
     if (self.answer==None):
         return #nothing to append
     if (self.dataitem=='postcode'):
         self.append_facts_postcode(facts)
     if (self.dataitem=='zipcode'):
         self.append_facts_zipcode(facts)
     if (self.dataitem=='country'):
         country = parseCountry(self.answer)
         if country!=None:
             if 'where' not in facts:
                 facts['where'] = {}
             facts['where']['country'] = [{'item':country,'probability':1.}]
Example #5
0
 def append_facts(
     self, facts, all_answers
 ):  #TODO Move all the census stuff into integrate_location maybe?
     if (self.answer == None):
         return  #nothing to append
     if (self.dataitem == 'postcode'):
         self.append_facts_postcode(facts)
     if (self.dataitem == 'zipcode'):
         self.append_facts_zipcode(facts)
     if (self.dataitem == 'country'):
         country = parseCountry(self.answer)
         if country != None:
             if 'where' not in facts:
                 facts['where'] = {}
             facts['where']['country'] = [{
                 'item': country,
                 'probability': 1.
             }]