Exemplo n.º 1
0
        
    print features.prep_features(sys.argv[1:])

    f = sys.stdin
    while True:
        line = f.readline()
        if line == '':
            break
        if line == '\n':
            continue
        try:
            k, tag = line.strip().split("\t")
        except:
            break  ## can finish earlier
         print k, tag
        k = int(k)
        best_w = None
        for j in xrange(k):
            logprob = float(f.readline().strip())
            parse = f.readline().strip()
            tree = Tree.parse(parse)
            ##print tree

            if j < maxk:
##                print tree
                features.evaluate(tree, tree.get_sent(), j)
                ##print features.pp_fv(fvector, j)
                ##fvector = features.extract(tree, tree.get_sent())
                
                
Exemplo n.º 2
0
import copy, time

class Fortify_Evaluator():
    def __init__(self):
        pass

    # action = (source_territory, destination_territory, num_armies)
    def evaluate_action(self, action, map_layout, player_status, enemy_status):
        (sim_player_status, sim_enemy_status) = self._simulate(action, player_status, enemy_status)
        return features.evaluate_fortify(map_layout, sim_player_status, sim_enemy_status)

    def _simulate(self, action, player_status, enemy_status):
        ''' Takes away num_armies from source, and add num_armies to the destination '''
        source, destination, num_armies = action
        sim_player_status = copy.deepcopy(player_status)
        sim_source = get_territory_by_id(source['territory'], sim_player_status['territories'])
        sim_source['num_armies'] -= num_armies
        sim_dest = get_territory_by_id(destination['territory'], sim_player_status['territories'])
        sim_dest['num_armies'] += num_armies
        return (sim_player_status, enemy_status)

if __name__ == "__main__":
    import EvaluatorAI
    b = EvaluatorAI.EvaluatorAI()
    time.sleep(2)
    r = Fortify_Evaluator()
    b._refresh_state()
    source, dest = b._create_set_of_legal_fortifications()[0]
    possible_action = (source, dest, source['num_armies'] - 1)
    print features.evaluate(b.map_layout, b.player_status, b.get_enemy_status())
    print r.evaluate_action(possible_action, b.map_layout, b.player_status, b.get_enemy_status())
Exemplo n.º 3
0
        (sim_player_status,
         sim_enemy_status) = self._simulate(action, player_status,
                                            enemy_status)
        return features.evaluate_fortify(map_layout, sim_player_status,
                                         sim_enemy_status)

    def _simulate(self, action, player_status, enemy_status):
        ''' Takes away num_armies from source, and add num_armies to the destination '''
        source, destination, num_armies = action
        sim_player_status = copy.deepcopy(player_status)
        sim_source = get_territory_by_id(source['territory'],
                                         sim_player_status['territories'])
        sim_source['num_armies'] -= num_armies
        sim_dest = get_territory_by_id(destination['territory'],
                                       sim_player_status['territories'])
        sim_dest['num_armies'] += num_armies
        return (sim_player_status, enemy_status)


if __name__ == "__main__":
    import EvaluatorAI
    b = EvaluatorAI.EvaluatorAI()
    time.sleep(2)
    r = Fortify_Evaluator()
    b._refresh_state()
    source, dest = b._create_set_of_legal_fortifications()[0]
    possible_action = (source, dest, source['num_armies'] - 1)
    print features.evaluate(b.map_layout, b.player_status,
                            b.get_enemy_status())
    print r.evaluate_action(possible_action, b.map_layout, b.player_status,
                            b.get_enemy_status())
Exemplo n.º 4
0
        [1,2,3,4],      #text + tweet + user + time
        [1,2,3,5],      #text + tweet + user + time2
        [1,3],          #text + user + time
        [1,3,4],        #text + user + time
        [1,3,5],        #text + user + time
        ]

threshold = int(len(tweets)*0.8)
 
print(len(tweets))
   
    # Training 
for i in range(len(result)):    
    featuresets = map_async(get_features,tweets,[screen_names,hashtags,words,links,users,result[i]])
    classifier = nltk.NaiveBayesClassifier.train(featuresets[:threshold])
    x = evaluate(classifier, featuresets[threshold:])
    classifier.show_most_informative_features(n=10)
    result[i] = x   
    
for i in result:
    print(i)    
   
# mostrare features più interessanti

#==============================================================================
# Prova su 6000 sconosciuti
#==============================================================================