-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathloadData.py
115 lines (93 loc) · 3.77 KB
/
loadData.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import numpy as np
from BeautifulSoup import *
from Symbol import *
from Trace import *
import pdb
class loadData:
def __init__(self):
pass
def loadInkml(self, fileName):
'''
The function is used to loadinkml files
'''
soup = BeautifulSoup(open(fileName))
# To store floating point numbers
points_str=[]
trace_obj_dict={}
# Will loop through all the trace ids
loop_all_trace = soup.findAll('trace')
for trace in loop_all_trace:
points_float = []
points_str = trace.string.strip("\n").split(",")
for pt in points_str:
coord = pt.split()
points_float.append((float(coord[0]),float(coord[1])))
# Gets the trace id
trace_id = int(trace.attrs[0][1])
#print ("\nTrace id is : %s") % (trace_id)
#print ("****************************")
#print (points_float)
# create an object for every trace and store in the dictionary
trace_object=Trace(trace_id,points_float)
trace_obj_dict[ trace_id] = trace_object
trace_object.normalization()
return soup,trace_obj_dict
def get_symbol(self,soup,trace_obj_dict):
'''
The function is used to get symbol information and traceObjects
'''
flag = True # to ignore the first tracegroup
symbols=[] # This will store the objects for every symbol in the file.
# pdb.set_trace()
for trace_g in soup.findAll('tracegroup'):
if flag==True:
flag=False
continue
else:
symbol_class = trace_g.annotation.text
# Get symbol id
try:
symbol_id = int(trace_g.attrs[0][1])
except:
#Conversion to int nit possible
symbol_id = int(trace_g.attrs[0][1].split(":")[0])
symbol_list=[]
#print ("Symbol_id: %d" ) % (symbol_id)
trace_view = trace_g.findAll('traceview')
#pdb.set_trace()
for i in xrange(len(trace_view)):
trace_id = int(trace_view[i]['tracedataref'])
symbol_list.append(trace_obj_dict[trace_id])
symbol_obj = Symbol(symbol_id,symbol_list,symbol_class)
symbols.append(symbol_obj)
return symbols
def get_symbol_test(self,soup,trace_obj_dict):
flag = True # to ignore the first tracegroup
symbols=[] # This will store the objects for every symbol in the file.
# pdb.set_trace()
for trace_g in soup.findAll('tracegroup'):
if flag==True:
flag=False
continue
else:
# symbol_class = trace_g.annotation.text # No ground truth available
# Get symbol id
try:
symbol_id = int(trace_g.attrs[0][1])
except:
#Conversion to int nit possible
symbol_id = int(trace_g.attrs[0][1].split(":")[0])
symbol_list=[]
#print ("Symbol_id: %d" ) % (symbol_id)
trace_view = trace_g.findAll('traceview')
#pdb.set_trace()
for i in xrange(len(trace_view)):
trace_id = int(trace_view[i]['tracedataref'])
symbol_list.append(trace_obj_dict[trace_id])
symbol_obj = Symbol(symbol_id,symbol_list,symbol_class)
symbols.append(symbol_obj)
return symbols
if __name__=="__main__":
loadInkml()
else:
pass