Data Abstraction UW CSE 190p Summer 2012. Recap of the Design Exercise You were asked to design a module – a set of related functions. Some of these functions.

Slides:



Advertisements
Similar presentations
Haskell Lets review some of the Haskell concepts you have been learning on your own. The answers are included, but try it yourself first.
Advertisements

From use cases to classes (in UML). A use case for writing use cases Use case: writing a use case Actors: analyst, client(s) Client identifies and write.
MapReduce.
Exercises – don’t use built in functions for these as we want the practice Write a recursive function to add up all the numbers in a list "flatten" a list.
Customizing the MOSS 2007 Search Results November 2007 Rafael Perez.
Microsoft Excel Working with Excel Lists, Subtotals and Pivot Tables.
Forms cs105. More Interactive web-pages So far what we have seen was to present the information. (Ex: tables. Lists,….). But it is not enough. We want.
SiS Technical Training Development Track Day 7. Agenda  Understand Component Interface  Understand Excel to CI  Practice Data Loading using ECI (Instructor.
Chapter 2 Querying a Database
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Information systems and databases Database information systems Read the textbook: Chapter 2: Information systems and databases FOR MORE INFO...
Business Computer Information Systems Microsoft Office XP Access Review Lessons 1 through 5.
 Computer Science 1MD3 Introduction to Programming Michael Liut Ming Quan Fu Brandon.
Page 1 ISMT E-120 Desktop Applications for Managers Introduction to Microsoft Access.
 1 String and Data Processing. Sequential Processing Processing each element in a sequence for e in [1,2,3,4]: print e for c in “hello”: print c for.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
MapReduce: Simplified Data Processing on Large Clusters Jeffrey Dean and Sanjay Ghemawat.
Invitation to Computer Science, Java Version, Second Edition.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
More Data Abstraction UW CSE 190p Summer Recap of the Design Exercise You were asked to design a module – a set of related functions. Some of these.
Data Abstraction UW CSE 140 Winter What is a program? – A sequence of instructions to achieve some particular purpose What is a library? – A collection.
Basics of Information Retrieval Lillian N. Cassel Some of these slides are taken or adapted from Source:
(Chapter 10 continued) Our examples feature MySQL as the database engine. It's open source and free. It's fully featured. And it's platform independent.
Design Exercise UW CSE 140 Winter Exercise Given a problem description, design a module to solve the problem 1) Specify a set of functions – For.
Relational Operator Evaluation. Overview Index Nested Loops Join If there is an index on the join column of one relation (say S), can make it the inner.
1 CSC 222: Computer Programming II Spring 2004 See online syllabus at: Course goals:
More about Databases. Data Entry through Forms Table View (Data sheet view) is useful for data entry of new records But sometimes customization would.
Database Systems Microsoft Access Practical #3 Queries Nos 215.
Cohesion and Coupling CS 4311
1 CSC 321: Data Structures Fall 2013 See online syllabus (also available through BlueLine2): Course goals:  To understand.
More On Classes UW CSE 160 Spring Classes define objects What are objects we've seen? 2.
Introduction to Computing Using Python Data Storage and Processing  How many of you have taken IT 240?  Databases and Structured Query Language  Python.
Database Applications – Microsoft Access Lesson 4 Working with Queries 36 Slides in Presentation.
Reports and Queries Chapter 3 – Access text Reports – Page Queries – Page
Histograms: Summarizing Data 1. SUMMARIZING DATA Raw data, such as company records, often contains a wealth of information that would be of use in making.
DATABASE MANAGEMENT SYSTEM ARCHITECTURE
Chapter 9 Dictionaries and Sets.
Design Exercise UW CSE 190p Summer 2012 download examples from the calendar.
©2007 Austin Troy Lecture 7: Introduction to GIS 1.Queries and table operations for a single layer in Arc GIS 2.Intro to queries in Access Lecture by Austin.
Design Exercise UW CSE 160 Spring Exercise Given a problem description, design a module to solve the problem 1) Specify a set of functions – For.
GE3M25: Computer Programming for Biologists Python, Class 5
CPSC 404, Laks V.S. Lakshmanan1 Evaluation of Relational Operations – Join Chapter 14 Ramakrishnan and Gehrke (Section 14.4)
Ranking of Database Query Results Nitesh Maan, Arujn Saraswat, Nishant Kapoor.
Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at
Compsci 101.2, Fall Plan for October l Structuring Data and Code for Efficiency  Computer time, how expensive is it?  Data storage, how.
Access Module Implementing a Database with Microsoft Access A Great Module on Your CD.
Data Abstraction UW CSE 160 Spring What is a program? – A sequence of instructions to achieve some particular purpose What is a library? – A collection.
CSC 205 Java Programming II Abstract Data Type. Abstraction The meaning of abstraction Abstraction arises from a recognition of similarities between certain.
Apache Solr Dima Ionut Daniel. Contents What is Apache Solr? Architecture Features Core Solr Concepts Configuration Conclusions Bibliography.
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
Today… Files from the Web! Dictionaries. Lists of lists. Winter 2016CISC101 - Prof. McLeod1.
SQL – Python and Databases
Advanced Python Idioms
Computing and Data Analysis
Containers and Lists CIS 40 – Introduction to Programming in Python
Design Exercise UW CSE 140 Winter 2014.
Design Exercise UW CSE 160 Winter 2017.
Chapter 2: Database System Concepts and Architecture
Data Abstraction UW CSE 160 Winter 2017.
Data Abstraction UW CSE 160 Winter 2016.
Python I/O.
CISC101 Reminders Slides have changed from those posted last night…
Design Exercise UW CSE 160 Spring 2018.
Data Abstraction UW CSE 160 Spring 2018.
Advanced Python Idioms
Design Exercise UW CSE 160 Winter 2016.
Advanced Python Idioms
Data Abstraction UW CSE 160.
Presentation transcript:

Data Abstraction UW CSE 190p Summer 2012

Recap of the Design Exercise You were asked to design a module – a set of related functions. Some of these functions operated on the same data structure – a list of tuples of measurements – a dictionary associating words with a frequency count Both modules had a common general form – One function to create the data structure from some external source – Multiple functions to query the data structure in various ways – This kind of situation is very common

What we’ve learned so far data structure – a collection of related data – the relevant functions are provided for you – Ex: list allows append, sort, etc. – What if we want to make our own kind of “list,” with its own special operations? module – a named collection of related functions – but shared data must be passed around explicitly – What if we want to be sure that only our own special kind of list is passed to each function?

What if we want to make our own kind of collection of data, with its own special operations? What if we want to be sure that only our own special kind of list is passed to each function? First attempt: Write several fn

Text Analysis def read_words(filename): “””Return a dictionary mapping each word in filename to its frequency””” words = open(filename).read().split() wordcounts = {} for w in words: cnt = wordcounts.setdefault(w, 0) wordcounts[w] = cnt + 1 return wordcounts def wordcount(wordcounts, word): “””Return the count of the given word””” return wordcounts[word] def topk(wordcounts, k=10): “””Return top 10 most frequent words””” scores_with_words = [(s,w) for (w,s) in wordcounts.items()] scores_with_words.sort() return scores_with_words[0:k] def totalwords(wordcounts): “””Return the total number of words in the file””” return sum([s for (w,s) in wordcounts]) # program to compute top 10: wordcounts = read_words(filename) result = topk(wordcounts, 10)

Quantitative Analysis import matplotlib.pyplot as plt def read_measurements(filename): “””Return a dictionary mapping column names to data. Assumes the first line of the file is column names.””” datafile = open(filename) rawcolumns = zip(*[row.split() for row in datafile]) columns = dict([(col[0], col[1:]) for col in rawcolumn return columns def STplot(measurements): “””Generate a scatter plot comparing salinity and temperature””” xs = tofloat(measurements, “salt”) ys = tofloat(measurements, “temp”) plt.plot(xs, ys) plt.show() def minimumO2(measurements): “””Return the minimum value of the oxygen measurement””” return min(tofloat(measurements, “o2”)) def tofloat(measurements, columnname): “””Convert each value in the given iterable to a float””” return [float(x) for x in measurements[columnname]]

Abstraction: Emphasis on exposing a useful interface. Encapsulation: Emphasis on hiding the implementation details. Information Hiding: The process by which you achieve encapsulation. Your job: Choose which details to hide and which details to expose. Terms of Art

Abstraction and encapsulation are complementary concepts: abstraction focuses on the observable behavior of an object... encapsulation focuses upon the implementation that gives rise to this behavior... encapsulation is most often achieved through information hiding, which is the process of hiding all of the secrets of object that do not contribute to its essential characteristics. Grady Booch

Data abstraction Data structures can get complicated We don’t want to have to say “a dictionary mapping strings to lists, where each list has the same length and each key corresponds to one of the fields in the file.” We want to say “FieldMeasurements” Why?

Tools for abstraction: Default Values As you generalize a function, you tend to add parameters. Downsides: – A function with many parameters can be awkward to call – Existing uses need to be updated

def twittersearch(query): ""”Return the responses from the query””” url = " + query remote_file = urllib.urlopen(url) raw_response = remote_file.read() response = json.loads(raw_response) return [tweet["text"] for tweet in response["results"]] def twittersearch(query, page=1): ""”Return the responses from the query for the given page””” resource = “ qs = “?q=" + query + “&page=“ + page url = resource + qs remote_file = urllib.urlopen(url) raw_response = remote_file.read() response = json.loads(raw_response) return [tweet["text"] for tweet in response["results"]]

We now come to the decisive step of mathematical abstraction: we forget about what the symbols stand for....[The mathematician] need not be idle; there are many operations which he may carry out with these symbols, without ever having to look at the things they stand for. Hermann Weyl, The Mathematical Way of Thinking

Procedural Abstraction: