Yql ans geo

Preview:

DESCRIPTION

 

Citation preview

http://www.flickr.com/photos/han_shot_first/6573340265/

YQL1 API to rule them all

http://www.flickr.com/photos/han_shot_first/6573340265/

What• YQL is Yahoo! Query Language

– Web service– SQL like syntax– SELECT * FROM internet;

WhatUnstructured data

Data via YQL

Console

Console

Tables are here

Console

Your query goes here

Console

Output is here

Console

Take-away URL here

Output• XML

– Human & machine readable

• JSON– Javascript object notation– A JS object {}

• Key, value pairs including arrays

– Callback supported• func_name({“json”:”object”})

Output

Unstructured data• Page scrapping

• select content from html where url="http://in.news.yahoo.com/murray-takes-two-set-lead-final-against-djokovic-153758871.html" and xpath='//*[@id="mediaarticlebody"]/div/p[29]’

• Xpath – path to a node in an XML document

Unstructured data• Reading google spreadsheets

• https://docs.google.com/spreadsheet/pub?key=0AgGxPO1AxEhldFZDNzAzQldLSGp2MzVGVXdlUnIxeUE&output=csv

• select * from csv where url = ””

Why• Unstructured data

– Yes, YQL is cool. But …

• Why use YQL– When webservices are already available

• Lets see why, via an example

Example – Profile, Flickr• !YQL

– Get a user profile• http://social.yahooapis.com/v1/user/{guid}/profile

– Search for photos in flickr• http://api.flickr.com/services/rest/?

method=flickr.photos.search&api_key=…&text=djokovic&format=rest

Example – Profile, Flickr• YQL

– Get a user profile• select * from social.profile where guid = me

– Search for photos in flickr• select * from flickr.photos.search where

api_key="..." and text="san francisco"

Examples – Content Analysis

Examples – Content Analysis

Unstructured data, easy api access. What else?

http://www.flickr.com/photos/brickultra/7178444546/

SQL like… JOINS?

• YQL does not support joins natively• Supports sub-selects

– Let’s look at an example

SQL like… JOINS?

1. Get content from a web page

SQL like… JOINS?

2. Identify entities in that content

SQL like… JOINS?

3. Search for photos with entity names

SQL like… JOINS?• A small demo

– http://doc1.ydn.gq1.yahoo.com/mybloglog_test/yqljoin.html

– JOINs doesn’t mean single API call• YQL still makes multiple calls

– Only one IN allowed per select• Sub-select can also have one IN

How? – Devil is in the details

http://www.flickr.com/photos/prodiffusion/8267223638/

How to use• PHP

$yql_query = "select * from answers.getbycategory where category_id=2115500137";$yql_url = "http://query.yahooapis.com/v1/public/yql?q=" . rawurlencode($yql_query) . "&format=json";

$session = curl_init($yql_url); curl_setopt($session, CURLOPT_RETURNTRANSFER,true); $json = curl_exec($session);

How to use• Javascript

Ask. Answer. Discover

Y! Answershttp://www.flickr.com/photos/funkyporcupine/8290971054/

Answers - Tables

http://developer.yahoo.com/answers/

Where, what’s there and how to reach

Geohttp://www.flickr.com/photos/carthalis/3562768042/

Current Location - Ask• Ask the user

Current Location - Ask• Ask the browser

Current Location - Ask

Current Location - Sniffhttp://isithackday.com/hacks/geo/js-location.html

Geocoding

Reverse geocoding

Woeid• Where-On-Earth-ID

WoeidSELECT placeTypeName, name FROM geo.places.ancestors WHERE descendant_woeid = "55925520”

SELECT placeTypeName, name FROM geo.places.ancestors WHERE descendant_woeid = "55925520”

Geoplanet

Placemaker

Geo Hacks• http://trendsmap.com/local/india• http://isithackday.com/hacks/geo/

Happy hacking!

Thank Youhttp://www.flickr.com/photos/brickaholicproductions/5177947158/