Changeset 3571:954d167a710c in orange
 Timestamp:
 04/23/07 11:49:57 (7 years ago)
 Branch:
 default
 Convert:
 4db34bbad8c45580f78a4903406f1240b6f9026d
 Location:
 orange/OrangeWidgets/Visualize
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

orange/OrangeWidgets/Visualize/OWCorrAnalysis.py
r3561 r3571 27 27 28 28 def checkFromText(data): 29 29 30 if not isinstance(data, orange.ExampleTable): 30 return False 31 return False 31 32 if len(data.domain.attributes) < 10 and len(data.domain.getmetas()) > 15: 32 33 return True … … 423 424 424 425 if __name__=="__main__": 425 from orngTextCorpus import *426 import cPickle 426 #from orngTextCorpus import * 427 import cPickle, orngText 427 428 ## os.chdir("/home/mkolar/Docs/Diplomski/repository/orange/OrangeWidgets/Other/") 428 appl = QApplication(sys.argv) 429 ow = OWCorrAnalysis() 430 appl.setMainWidget(ow) 429 appl = QApplication(sys.argv) 430 ow = OWCorrAnalysis() 431 432 #owb = OWBagofWords.OWBagofWords() 433 t = orngText.loadFromXML(r'c:\test\msnbc.xml') 434 #owb.data = t 435 #owb.show() 436 print 'Done with loading' 437 t1 = orngText.bagOfWords(t) 438 print 'Done with bagging' 439 t2 = orngText.FSS(t1, 'TF', 'MIN', 0.9) 440 print 'Done with feature selection' 441 appl.setMainWidget(ow) 442 ow.dataset(t2) 443 print 'Done' 431 444 ow.show() 432 445 ## dataset = orange.ExampleTable('/home/mkolar/Docs/Diplomski/repository/orange/doc/datasets/iris.tab') … … 437 450 ## a = TextCorpusLoader('/home/mkolar/Docs/Diplomski/repository/orange/OrangeWidgets/Other/reutersexchangessmall.xml', lem = lem) 438 451 439 #a = orange.ExampleTable('../../doc/datasets/smokers_ct.tab') 440 f=open('../../CDFSallDataCW', 'r') 441 a =cPickle.load(f) 442 f.close() 443 ow.dataset(a) 444 appl.exec_loop() 452 ## #a = orange.ExampleTable('../../doc/datasets/smokers_ct.tab') 453 ## f=open('../../CDFSallDataCW', 'r') 454 ## a =cPickle.load(f) 455 ## f.close() 456 ## ow.dataset(a) 457 458 appl.exec_loop() 
orange/OrangeWidgets/Visualize/OWCorrAnalysisGraph.py
r3552 r3571 221 221 side = left 222 222 if not text: continue 223 223 print right, left 224 224 if x < posX: 225 225 #pokusaj lijevo 226 if self.checkPerc(left, len(text)) > 0: 226 #if self.checkPerc(left, len(text)) > 0: 227 if self.place(left, len(text), 'left') == True: 227 228 newMark.append((left, self.invTransform(QwtPlot.yLeft, topL), text, Qt.AlignLeft, x, y)) 228 229 topL = topL + self.labelSize … … 232 233 else: 233 234 #pokusaj desno 234 if self.checkPerc(right, len(text)) < 70: 235 #if self.checkPerc(right, len(text)) < 70: 236 if self.place(right, len(text), 'right') == True: 235 237 newMark.append((right, self.invTransform(QwtPlot.yLeft, topR), text, Qt.AlignRight, x, y)) 236 238 topR = topR + self.labelSize 237 else: 239 else: 240 newMark.append((left, self.invTransform(QwtPlot.yLeft, topL), text, Qt.AlignLeft, x, y)) 238 241 topL = topL + self.labelSize 239 newMark.append((left, self.invTransform(QwtPlot.yLeft, topL), text, Qt.AlignLeft, x, y))240 242 241 243 # if not (i & 1): … … 252 254 # newMark.append((left, self.invTransform(QwtPlot.yLeft, top), text, Qt.AlignLeft, x, y)) 253 255 # top = top + 10 254 prevYR = prevYL = 666 255 prevIndL = prevIndR = 1 256 prevXL = prevXR = 0 257 i = 0 258 259 while i <= len(newMark)  1: 260 y = newMark[i][1] 261 if newMark[i][3] == Qt.AlignLeft: 262 if abs(prevYL  y) < abs(prevXL  newMark[i][0]): 263 t = newMark[i] 264 newMark[i] = newMark[prevIndL] 265 newMark[prevIndL] = t 266 prevYL = y 267 prevXL = newMark[i][0] 268 prevIndL = i 269 if newMark[i][3] == Qt.AlignRight: 270 if abs(prevYR  y) < abs(prevXR  newMark[i][0]): 271 t = newMark[i] 272 newMark[i] = newMark[prevIndR] 273 newMark[prevIndR] = t 274 prevYR = y 275 prevXR = newMark[i][0] 276 prevIndR = i 277 i = i + 1 256 again = True 257 swapCounter = 0 258 while again: 259 #don't take too long 260 if swapCounter > 100: 261 break 262 again = False 263 prevIndL = prevIndR = 1 264 topR = topL = top 265 #prevXL = prevXR = 0 266 i = 0 267 268 while i <= len(newMark)  1: 269 if newMark[i][3] == Qt.AlignLeft: 270 #compute line parameters 271 if prevIndL == 1: 272 prevIndL = i 273 #topL += self.labelSize 274 i += 1 275 continue 276 #print 'looking %s and %s' %(newMark[i][2], newMark[prevIndL][2]) 277 k1 = (newMark[i][1]  newMark[i][5]) / (newMark[i][0]  newMark[i][4]) 278 l1 = k1 * newMark[i][4] + newMark[i][5] 279 k2 = (newMark[prevIndL][1]  newMark[prevIndL][5]) / (newMark[prevIndL][0]  newMark[prevIndL][4]) 280 l2 = k2 * newMark[prevIndL][4] + newMark[prevIndL][5] 281 if k1 == k2: 282 i += 1 283 continue 284 intersection = (l2  l1) / (k2  k1) 285 intersection = intersection 286 #print intersection, left, min(newMark[i][4], newMark[prevIndL][4]) 287 if intersection > left and intersection < min(newMark[i][4], newMark[prevIndL][4]): 288 #swap labels 289 #print "swapping %s and %s " %(newMark[i][2], newMark[prevIndL][2]) 290 #t = (left, self.invTransform(QwtPlot.yLeft, topL + self.labelSize), newMark[i][2], newMark[i][3], newMark[i][4], newMark[i][5]) 291 t = (left, newMark[prevIndL][1], newMark[i][2], newMark[i][3], newMark[i][4], newMark[i][5]) 292 #newMark[i] = (left, self.invTransform(QwtPlot.yLeft, topL), newMark[prevIndL][2], newMark[prevIndL][3], newMark[prevIndL][4], newMark[prevIndL][5]) 293 newMark[i] = (left, newMark[i][1], newMark[prevIndL][2], newMark[prevIndL][3], newMark[prevIndL][4], newMark[prevIndL][5]) 294 newMark[prevIndL] = t 295 again = True 296 swapCounter += 1 297 prevIndL = i 298 topL += self.labelSize 299 300 if newMark[i][3] == Qt.AlignRight: 301 #compute line parameters 302 if prevIndR == 1: 303 prevIndR = i 304 #topR += self.labelSize 305 i += 1 306 continue 307 #print 'looking %s and %s' %(newMark[i][2], newMark[prevIndR][2]) 308 k1 = (newMark[i][1]  newMark[i][5]) / (newMark[i][0]  newMark[i][4]) 309 l1 = k1 * newMark[i][4] + newMark[i][5] 310 k2 = (newMark[prevIndR][1]  newMark[prevIndR][5]) / (newMark[prevIndR][0]  newMark[prevIndR][4]) 311 l2 = k2 * newMark[prevIndR][4] + newMark[prevIndR][5] 312 if k1 == k2 or newMark[i][4] == newMark[prevIndR][4]: 313 i += 1 314 continue 315 intersection = (l2  l1) / (k2  k1) 316 #print intersection, right, min(newMark[i][4], newMark[prevIndR][4]) 317 intersection = intersection 318 if intersection < right and intersection > max(newMark[i][4], newMark[prevIndR][4]): 319 #swap labels 320 t = (right, newMark[prevIndR][1], newMark[i][2], newMark[i][3], newMark[i][4], newMark[i][5]) 321 newMark[i] = (right, newMark[i][1], newMark[prevIndR][2], newMark[prevIndR][3], newMark[prevIndR][4], newMark[prevIndR][5]) 322 newMark[prevIndR] = t 323 again = True 324 swapCounter += 1 325 prevIndR = i 326 topR += self.labelSize 327 i = i + 1 328 329 330 ## while i <= len(newMark)  1: 331 ## y = newMark[i][1] 332 ## if newMark[i][3] == Qt.AlignLeft: 333 ## if abs(prevYL  y) < abs(prevXL  newMark[i][0]): 334 ## t = newMark[i] 335 ## newMark[i] = newMark[prevIndL] 336 ## newMark[prevIndL] = t 337 ## prevYL = y 338 ## prevXL = newMark[i][0] 339 ## prevIndL = i 340 ## if newMark[i][3] == Qt.AlignRight: 341 ## if abs(prevYR  y) < abs(prevXR  newMark[i][0]): 342 ## t = newMark[i] 343 ## newMark[i] = newMark[prevIndR] 344 ## newMark[prevIndR] = t 345 ## prevYR = y 346 ## prevXR = newMark[i][0] 347 ## prevIndR = i 348 ## i = i + 1 278 349 279 350 … … 284 355 285 356 286 def checkPerc(self, x, textLen): 357 ## def checkPerc(self, x, textLen): 358 ## div = self.axisScale(QwtPlot.xBottom) 359 ## if x  textLen < div.lBound(): 360 ## return 1 361 ## elif x + textLen > div.hBound(): 362 ## return 101 363 ## else: 364 ## return (x  div.lBound()) / (div.hBound()  div.lBound()) 365 366 def place(self, x, textLen, prefered): 367 """Tries to determine where to place the label. Returns True or False.""" 287 368 div = self.axisScale(QwtPlot.xBottom) 288 if x < div.lBound(): 289 return 1 290 elif x > div.hBound(): 291 return 101 292 else: 293 return (x  div.lBound()) / (div.hBound()  div.lBound()) 369 textLen = textLen / 16. 370 if prefered == 'left': 371 if x  textLen < div.lBound(): 372 return False 373 return True 374 else: 375 if x + textLen > div.hBound(): 376 return False 377 return True 378 379
Note: See TracChangeset
for help on using the changeset viewer.