160 likes | 173 Views
Factual.com. Location Information. Temporal and Spatial Information. Information can have temporal and spatial aspects Examples The nearest XXX (xxx = restaurant, shoe store, …) Directions can be thought of as: Given that I’m here now, what do I do next?
E N D
Factual.com Location Information
Temporal and Spatial Information • Information can have temporal and spatial aspects • Examples • The nearest XXX (xxx = restaurant, shoe store, …) • Directions can be thought of as: Given that I’m here now, what do I do next? • You are at an office door, the person is out. We can represent the information that the person in this office is out until 1pm • The building to the west is Gore Hall • The history of here (where here is where you are) • Self guided tour • Local news • Nearest party (at this moment, or planned in the future) • Found art/found sound • Music composers use found sound in their compositions. Examples include John Cage, Nicolas Collins, Art of Noise, The Slant (band), Robin Rimbaud AKA Scanner and The Books. – wikipedia “found art” • Joe frank • Law enforcement / military intelligence • A bad guy lives in that house, but is at his mother’s on Sundays, and today is Sunday. • More? • Information can be relevant only when you are at the location, when you are planning to go to the location, or for browsing • Browsing e.g., getting information about what is going on at different places throughout a city
Factual.com • Several datasets of locations • SimpleGeo.com had a large dataset and gave it to factual.com • This dataset is called Places • Factual has other datasets • Restaurants • We’ll explore this one after we finish with places • Entertainment • Health • education
Start sample app • Get source • From http://repo1.maven.org/maven2/com/factual/factual-java-driver/1.0/ • See link for non-maven users at https://github.com/Factual/factual-java-driver • Decompress source • Note: there are some minor bugs in the source. So we cannot import the libraries. Instead, we will import the source code and correct these minor bugs • Documentation is as • http://www.jarvana.com/jarvana/view/com/factual/factual-java-driver/1.0/factual-java-driver-1.0-javadoc.jar!/com/factual/Factual.html • Make new application • TestFactual • Add permissions for (don’t skip this step like I did!) • Internet • Location (course and fine) • Wifi access and change • Make packages for the factual source • Right click on src-> new -> package • Package name: com.factual.data_science_toolkit • Make another package • Package name: com.factual.driver • Open a file browser and go to directory where you decompressed the factual source code • Drag files in com/fractual/data_science_toolkit to package com.factual.data_science you just made • Drag files in com/fractual (the files, not the directory /data_science) to the com.factual.driver package you just made
Get and import a many libraries • Get guava • http://code.google.com/p/guava-libraries/ • Get guave-xx.x.jar • Save, add library • In eclipse, right click on your project FractualTest • Select Build Path -> Configure Build Path • Dialog opens • Select Libraries tab • Click Add External Jar button • Locate and select the jar file you just downloaded • In the Java Build Path dialog, select Order and Export tab • Find the library you just added. Make sure the check box is checked • Get google-api-java-client • http://code.google.com/p/google-api-java-client/downloads/detail?name=google-api-java-client-1.6.0-beta.zip&can=2&q= • Get google-api-java-client-1.6.0-beta.zip • Save in directory googleJavaClient • Decompress • There are many libraries. Just import • google-http-client-XXX.jar • google-oauth-client-xxx.jar • Get codehaus.jackson • http://wiki.fasterxml.com/JacksonDownload • Scroll down to Download. Look for deployable jars. Get Jackson all. It should be called something like jackson-all-XXX.jar • Save in directory codehaus/jackson • Import jackson-all-XXX.jar • Get JSON.org • http://mvnrepository.com/artifact/org.json/json/20090211 • Download jar • Save in directory JSON • import • Get juint • https://github.com/KentBeck/junit/downloads • Get juint-4.10.jar • Save in file juint • import • Get apache commons.io • http://commons.apache.org/io/download_io.cgi • Get binaries (e.g., zip) • Save in directory ApacheCommons/io • Decompress • The jar commons-io-xx.jar is in the commons-io-xx directory • Import • Note, this is a lot of libraries. It will make the executable large. • ProGuard (http://developer.android.com/guide/developing/tools/proguard.html) can be used to make you code smaller
Eclipse memory problems • Will need to allow eclipse to use more memory. • To fix the problem, see http://docs.oseems.com/application/eclipse/fix-gc-overhead-limit-exceeded • I set • -Xms1024 • -Xmx2048
Get some basic data from factual • Make function: public void getFactualData • Add • Log.e("factual","starting"); • Factual factual = new Factual("9uEYTRbG1gizXlePqU3ZqM3cJqQUADoADiJQxii1", "vgagHeXbsnQ05rCyCYBCrWyTr3VeCGZW095LE6xc"); • Query query = new Query().within(new com.factual.Circle(34.06018, -118.41835, 5000)).limit(10).sortAsc("name"); • // gets up to 10 items that are in the 5000m circle around the lat-long point 34.06018, -118.41835. and these are sorted by name • Log.e("factual","made query. Now fetching"); • ReadResponsereadResponse = factual.fetch("places", query); • showResponse(readResponse); // need to make this function
showResponse(readResponse); • public void showResponse(ReadResponsereadResponse) { • List<Map<String,Object>> data = readResponse.getData(); • System.out.println("num items: "+data.size()); • for(Map<String,Object> item : data) { • System.out.println("************new item***************"); • // see http://developer.factual.com/display/docs/Places+API+-+Global+Place+Attributes for schema • Double latitude = (Double)item.get("latitude"); • if (latitude==null) • System.out.println("latitude does not exist"); • else • System.out.println("latitude: "+latitude); • Double longitude = (Double)item.get("longitude"); • if (longitude==null) • System.out.println("longitude does not exist"); • else • System.out.println("longitude: "+longitude); • String name = (String)item.get("name"); • if (name==null) • System.out.println("name does not exist"); • else • System.out.println("name: "+name); • String category = (String)item.get("category"); • if (category==null) • System.out.println("category does not exist"); • else • System.out.println("category: "+category);
Show Address of place • String address = (String)item.get("address"); • if (address==null) • System.out.println("address does not exist"); • else • System.out.println("address: "+address); • String address_extended = (String)item.get("address_extended"); • if (address_extended==null) • System.out.println("address_extended does not exist"); • else • System.out.println("address extended: "+address_extended); • String locality = (String)item.get("locality"); • if (locality==null) • System.out.println("locality does not exist"); • else • System.out.println("locality: "+locality); • String village = (String)item.get("village"); • if (village==null) • System.out.println("village does not exist"); • else • System.out.println("village: "+village); • String regency = (String)item.get("regency"); • if (regency==null) • System.out.println("regency does not exist"); • else • System.out.println("regency: "+regency); • String region = (String)item.get("region"); • if (region==null) • System.out.println("region does not exist"); • else • System.out.println("region: "+region); • String admin_region = (String)item.get("admin_region"); • if (admin_region==null) • System.out.println("admin_region does not exist"); • else • System.out.println("admin_region: "+admin_region); • String post_town = (String)item.get("post_town"); • if (post_town==null) • System.out.println("post_town does not exist"); • else • System.out.println("post_town: "+post_town); • String postcode = (String)item.get("postcode"); • if (postcode==null) • System.out.println("postcode does not exist"); • else • System.out.println("postcode: "+postcode); • String country = (String)item.get("country"); • if (country==null) • System.out.println("country does not exist"); • else • System.out.println("country: "+country);
Show other things • String tel = (String)item.get("tel"); • if (tel==null) • System.out.println("tel does not exist"); • else • System.out.println("tel: "+tel); • String fax = (String)item.get("fax"); • if (fax==null) • System.out.println("fax does not exist"); • else • System.out.println("fax: "+fax); • String website = (String)item.get("website"); • if (website==null) • System.out.println("website does not exist"); • else • System.out.println("website: "+website); • String status = (String)item.get("status"); • if (status==null) • System.out.println("status does not exist"); • else • System.out.println("status: "+status); • String email = (String)item.get("email"); • if (email==null) • System.out.println("email does not exist"); • else • System.out.println("email: "+email); • String factual_id = (String)item.get("factual_id"); • if (factual_id==null) • System.out.println("factual_id: does not exist"); • else • System.out.println("factual_id: "+item.get("factual_id"));
In onCreate • In onCreate, call getFactualData • Run it. • Crashed? Why?! • StrictMode … onNetwork • Don’t use network from UI thread. Especially when starting (i.e., onCreate) • Use threads • Won’t crash on older phones, only android version>=4
Simple thread • Android has several simple ways to make theads • In onCreate • new Thread(new Runnable() { • public void run() { • getFactualData(); • }}).start(); • // this runs the run function from a thread • // communicating back to the UI thread is a bit tricky. (that is, do not call any UI elements from this thread!) • So another threading mechanism
AsyncTask • At the end of public class FactualTestActivity extends Activity {, add • private class runFactualQuery extends AsyncTask<Void, Void, Boolean> {} • Let eclipse add unimplemented functions. • In doInBackground, add • getFactualData(); • Return true; • Add member function • @Override • protected void onPostExecute(Boolean results) { • // UI thread is accesible here • Log.e("factual","finished thread"); • }
In onCreate, add • new runFactualQuery().execute();
Other query types • recall • Query query = new Query().within(new com.factual.driver.Circle(34.06018, -118.41835, 5000)).limit(10).sortAsc("name"); • // gets up to 10 items that are in the 5000m circle around the lat-long point 34.06018, -118.41835. and these are sorted by name • Get the next 10 items • Change .limit(10) to .limit(10).offset(10) • Full text search • Query query = new Query().search("newarkdelaware").limit(10); • Searches for newark and delaware anywhere in the data • Restrict data • Query query = new Query().field("locality").beginsWith("Newark").field("region").equal("DE").limit(10); • // for other options besides equals, see QueryBuilder. Options include: in, notIn, beginsWith