author | blanchet |
Tue, 20 Aug 2013 14:36:22 +0200 | |
changeset 53100 | 1133b9e83f09 |
parent 50951 | e1cbaa7d5536 |
child 53115 | e08a58161bf1 |
permissions | -rwxr-xr-x |
53100 | 1 |
#!/usr/bin/env python |
2 |
# Title: HOL/Tools/Sledgehammer/MaSh/src/mash |
|
50222 | 3 |
# Author: Daniel Kuehlwein, ICIS, Radboud University Nijmegen |
53100 | 4 |
# Copyright 2012 - 2013 |
50222 | 5 |
# |
6 |
# Entry point for MaSh (Machine Learning for Sledgehammer). |
|
7 |
||
50220 | 8 |
''' |
9 |
MaSh - Machine Learning for Sledgehammer |
|
10 |
||
11 |
MaSh allows to use different machine learning algorithms to predict relevant fact for Sledgehammer. |
|
12 |
||
13 |
Created on July 12, 2012 |
|
14 |
||
15 |
@author: Daniel Kuehlwein |
|
16 |
''' |
|
17 |
||
53100 | 18 |
import socket,sys,time,logging |
19 |
||
20 |
from spawnDaemon import spawnDaemon |
|
21 |
||
22 |
||
23 |
import logging,string,os,sys |
|
24 |
||
25 |
||
50619
b958a94cf811
new version of MaSh, with theory-level reasoning
blanchet
parents:
50482
diff
changeset
|
26 |
from theoryStats import TheoryStatistics |
b958a94cf811
new version of MaSh, with theory-level reasoning
blanchet
parents:
50482
diff
changeset
|
27 |
from theoryModels import TheoryModels |
50220 | 28 |
from dictionaries import Dictionaries |
29 |
from predefined import Predefined |
|
30 |
||
53100 | 31 |
from parameters import init_parser |
50840 | 32 |
|
53100 | 33 |
def communicate(data,host,port): |
34 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
35 |
try: |
|
36 |
sock.connect((host,port)) |
|
37 |
sock.sendall(data) |
|
38 |
received = sock.recv(262144) |
|
39 |
except: |
|
40 |
logger = logging.getLogger('communicate') |
|
41 |
logger.warning('Communication with server failed.') |
|
42 |
received = -1 |
|
43 |
finally: |
|
44 |
sock.close() |
|
45 |
return received |
|
50220 | 46 |
|
50951 | 47 |
def mash(argv = sys.argv[1:]): |
50220 | 48 |
# Initializing command-line arguments |
53100 | 49 |
args = init_parser(argv) |
50951 | 50 |
|
50388 | 51 |
# Set up logging |
50220 | 52 |
logging.basicConfig(level=logging.DEBUG, |
53 |
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', |
|
54 |
datefmt='%d-%m %H:%M:%S', |
|
55 |
filename=args.log, |
|
50951 | 56 |
filemode='w') |
53100 | 57 |
logger = logging.getLogger('mash') |
58 |
||
50220 | 59 |
if args.quiet: |
60 |
logger.setLevel(logging.WARNING) |
|
50951 | 61 |
#console.setLevel(logging.WARNING) |
62 |
else: |
|
63 |
console = logging.StreamHandler(sys.stdout) |
|
64 |
console.setLevel(logging.INFO) |
|
65 |
formatter = logging.Formatter('# %(message)s') |
|
66 |
console.setFormatter(formatter) |
|
67 |
logging.getLogger('').addHandler(console) |
|
68 |
||
50220 | 69 |
if not os.path.exists(args.outputDir): |
70 |
os.makedirs(args.outputDir) |
|
71 |
||
53100 | 72 |
# If server is not running, start it. |
73 |
try: |
|
74 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
75 |
sock.connect((args.host,args.port)) |
|
76 |
sock.close() |
|
77 |
except: |
|
78 |
logger.info('Starting Server.') |
|
79 |
spawnDaemon('server.py') |
|
80 |
# TODO: Make this fault tolerant |
|
81 |
time.sleep(0.5) |
|
82 |
# Init server |
|
83 |
data = "i "+";".join(argv) |
|
84 |
received = communicate(data,args.host,args.port) |
|
85 |
logger.info(received) |
|
86 |
||
87 |
if args.inputFile == None: |
|
88 |
return |
|
89 |
logger.debug('Using the following settings: %s',args) |
|
90 |
# IO Streams |
|
91 |
OS = open(args.predictions,'w') |
|
92 |
IS = open(args.inputFile,'r') |
|
93 |
count = 0 |
|
94 |
for line in IS: |
|
95 |
count += 1 |
|
96 |
#if count == 127: |
|
97 |
# break as |
|
98 |
received = communicate(line,args.host,args.port) |
|
99 |
if not received == '': |
|
100 |
OS.write('%s\n' % received) |
|
101 |
#logger.info(received) |
|
102 |
OS.close() |
|
103 |
IS.close() |
|
50619
b958a94cf811
new version of MaSh, with theory-level reasoning
blanchet
parents:
50482
diff
changeset
|
104 |
|
53100 | 105 |
# Statistics |
106 |
if args.statistics: |
|
107 |
received = communicate('avgStats',args.host,args.port) |
|
108 |
logger.info(received) |
|
50827 | 109 |
|
50388 | 110 |
|
53100 | 111 |
if __name__ == "__main__": |
50951 | 112 |
sys.exit(mash()) |