import turtle import document class DrawCircle(document.Document): def __init__(self, radius, pos_x, pos_y): super(pos_x, pos_y) self.__radius = radius def show(self): turtle.tracer(False) turtle.penup() turtle.goto(self._pos_x, self._pos_y) turtle.pendown() turtle.circle(self.__radius) turtle.exitonclick() turtle.penup() turtle.update() def setRadius(self, radius): self.__radius = radius def getRadius(self): return self.__radius a=document(DrawCircle(100)) a.show()
def __init__(self): self.options = options().parse() self.doc = document()
import sys, time from document import * from apriori import * if __name__ == '__main__': start = time.time() f = open(sys.argv[1], 'r') doc = document(f) apr = apriori(doc.txns) apr.train() end = time.time() print 'Time taken for Training: {}'.format(end - start) start = time.time() apr.evaluate(doc.txns) end = time.time() print 'Time taken for Testing: {}'.format(end - start)
class fileOperations: "Contains file system operations for NotQuitePad." doc = document() def New(self): "Creates a new file within NotQuitePad." if self._CheckIfFileIsDirty() == True: msg = MessageBox.Show( "Do you want to save the changes to your file?", "NotQuitePad", MessageBoxButtons.YesNo) if msg == DialogResult.Yes: return False else: return True else: return True def _CheckIfFileIsDirty(self): "Call the document class to find out if a document has been marked dirty and needs to be saved." return self.doc.IsDirty() def SetDirty(self, value): "Call the document class to set the dirty property of a document." self.doc.SetDirty(value) def Open(self): "Handles the Open dialog window." dialog = OpenFileDialog() dialog.Title = "Load File" if dialog.ShowDialog() == DialogResult.OK: contents = self._OpenFileFromDisk(dialog.FileName) return contents def _OpenFileFromDisk(self, fileName): "Opens a connection to the file system." file = File.OpenText(fileName) data = file.ReadToEnd().ToString() file.Close() return data def Save(self, fileContents): "Handles the Save dialog window." dialog = SaveFileDialog() dialog.Title = "Save File" if dialog.ShowDialog() == DialogResult.OK: self._WriteFileToDisk(dialog.FileName, fileContents) return True def _WriteFileToDisk(self, fileName, fileContents): "After executing the Save method, write the file and contents to the desired location." file = File.CreateText(fileName) file.Write(fileContents) file.Close() def Print(self, fileContents): "Handles the Print dialog window." dialog = PrintDialog() if dialog.ShowDialog() == DialogResult.OK: doc = PrintDocument() dialog.Document = doc self._PrintDocument(doc) def _PrintDocument(self, printDocument): "Sends a document to the selected printing device." printDocument.Print()
def main(argv): # parse input arguments accountKey = sys.argv[1] precisionTarget = float(sys.argv[2]) queryList = sys.argv[3].split() # loop of getting user feedback and improving results while True: # map of all returned documents: url->document documents = {} print "\nParameters:" print "Client Key = ", accountKey print "Query = ", ', '.join(queryList) print "Precision = ", precisionTarget # retrieve top-10 results from query using Bing API result = bing_api.search(queryList, accountKey) # print results and getting user-rated relevance relevantResult = 0 totalResult = len(result) # exit if fewer than 10 results overall if totalResult < 10: print "Fewer than 10 results returned, exit" break print "\nTotal no of results : ", totalResult print "Bing Search Results:" print "======================" for i in range(totalResult): print "\nResult ", i+1 print "[" print " URL: ", result[i]["Url"] print " Title: ", result[i]["Title"] print " Summary: ", result[i]["Description"] print "]" choice = raw_input("Relevant (Y/N)?").lower() if choice == "yes" or choice == "y": result[i]["Relevant"] = True relevantResult = relevantResult + 1 else: result[i]["Relevant"] = False # calculate precision precision = relevantResult / float(totalResult) print "======================" print "FEEDBACK SUMMARY" print "Query ", ', '.join(queryList) print "Precision ", precision # exit if no relevant results if relevantResult == 0: print "No relevant results, exit" break # exit if achieve target precision, append query if not if precision >= precisionTarget: print "Desired precision reached, done" break else: print "Still below the desired precision of ", precisionTarget for r in result: doc = document(r) documents[r["Url"]] = doc # compute one new query using rocchio algorithms newQuery = rocchio().compute(queryList, documents) queryList.append(newQuery) print "Augmenting by", newQuery # reorder query using bigram queryList = queryReorder().reorder(queryList, documents)