-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvectormain.py
More file actions
59 lines (48 loc) · 1.62 KB
/
Copy pathvectormain.py
File metadata and controls
59 lines (48 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python
# -*- coding: utf-8 -*-
import argparse
from chavector import *
import os
'''
参数全是字符串
'''
parser = argparse.ArgumentParser()
parser.add_argument("urlfile",help="the first argument is filepath")
parser.add_argument("task",help="the second argument is taskname")
args = parser.parse_args()
if os.path.exists(args.urlfile):
print 'start vector get'
record=[]
weight=[]
dictdata=dict()
value=0.0
with open('trainresult.txt', 'r') as f:
read_data = f.readlines()
for data in read_data:
temp=data.strip().split()
weight.append(map(float,temp))
#print weight[0][0]
with open(args.urlfile, 'r') as f:
read_data = f.readlines()
for data in read_data:
data2=data.strip()
#print data2
if data2:
#print data.decode('utf-8')
splitdata=data2.split()
if len(splitdata)==1:
test=chavector(splitdata[0])
vector=test.getvector()
if len(vector)==8:
value=weight[0][0]*vector[0]+weight[0][1]*vector[1]+weight[0][2]*vector[2]+weight[0][3]*vector[3]+weight[0][4]*vector[4]+weight[0][5]*vector[5]+weight[0][6]*vector[6]+weight[0][7]*vector[7]
print value
dictdata[splitdata[0]]=value
print dictdata
with open(args.task, 'w') as f:
for k,v in dictdata.iteritems():
tmp=k+' '+str(v)
f.write(tmp)
f.write('\n')
print 'end vector get'
else:
print 'the file path is error'