Message Boards Message Boards

[WSC 2016] Generating Guidebooks utilizing API Data

Mathematica has the wondrous capability of connect to APIs such as Factual, Yelp, Flickr, and Wikipedia, and is able to extract huge amounts of data from these websites. This project utilizes that very data to get GeoPositions of tourist attractions, restaurants, and other locations in and around the user's location. The user inputs a location, and a query for each Factual, Yelp and Flickr. Factual takes food-based queries, while Yelp can take entertainment locations and many other queries. Once the queries are identified by the functions, the location query is used to pull a GeoPosition of the location. This coordinate then locates Wikipedia pages that contain a GeoPosition near the given position. Then, Factual, Yelp, and Flickr receive the position, and are instructed to extract locations (or pictures) that match the given query and are near the coordinates. Then, all the found locations and pictures are plotted with a tooltip to show the title of the location when moused over.

This project is similar in use to Google Maps, and it contains a more broad functionality for the user.

The Initialization for the Service Connect.

The function requires the user to have an Factual, Yelp, and Flickr API account, and to input the API Keys to initialize the Services.

factual = ServiceConnect["Factual"]

yelp = ServiceConnect["Yelp"]

flickr = ServiceConnect["Flickr"]

The Initialization for the Map Pins.

These pins are used in the project to label locations for Factual and Yelp.

mypinorange = Graphics[
   GraphicsGroup[{FaceForm[Orange], 
     FilledCurve[{{Line[
         Join[{{0, 0}}, ({Cos[#1], 3 + Sin[#1]} &) /@ 
           Range[-((2 \[Pi])/20), \[Pi] + (2 \[Pi])/20, \[Pi]/
            20], {{0, 0}}]]}, {Line[(0.5 {Cos[#1], 6 + Sin[#1]} &) /@ 
          Range[0, 2 \[Pi], \[Pi]/20]]}}]}]];
mypinblue = Graphics[GraphicsGroup[
    {FaceForm[Blue], 
     FilledCurve[{{Line[
         Join[{{0, 0}}, ({Cos[#1], 3 + Sin[#1]} &) /@ 
           Range[-((2 \[Pi])/20), \[Pi] + (2 \[Pi])/20, \[Pi]/
            20], {{0, 0}}]]}, {Line[(0.5 {Cos[#1], 6 + Sin[#1]} &) /@ 
          Range[0, 2 \[Pi], \[Pi]/20]]}}]}]];

The Function.

The function "nearby" accepts one, two, or three inputs. The input fields are "Location", "Factual Query", and "Yelp Query", in respective order.

nearby[loc_String] := 
 With[{data = WikipediaData[loc, "GeoNearbyDataset"]},
  Block[
   {centro},
   centro = data[[All, {"Title", "Position"}]][[1]][[2]];
   DynamicGeoGraphics[{Tooltip[
        GeoMarker[#[["Position"]]], #[["Title"]]] & /@ (data)},
    GeoCenter -> centro, GeoRange -> Quantity[1, "Miles"]]]]

nearby[loc_String, fquery_String] := 
 With[{data = WikipediaData[loc, "GeoNearbyDataset"]},
  Block[
   {centro, facts, flick},
   centro = data[[All, {"Title", "Position"}]][[1]][[2]]; 
   facts = factual[
      "PlacesDataset", {"Location" -> centro, 
       "Radius" -> Quantity[1000, "Yards"], "Query" -> fquery, 
       MaxItems -> 20}][All, {"Location", "Name"}];
   flick = 
    ServiceExecute["Flickr", 
      "ImageSearch", {"Location" -> centro, 
       "Elements" -> {"FullData"}, "ImageSize" -> "Small", 
       MaxItems -> 10}][All, {"Thumbnail", "Title", "Location"}];
   DynamicGeoGraphics[{Tooltip[
        GeoMarker[#[["Position"]]], #[["Title"]]] & /@ (data), 
     Tooltip[
        GeoMarker[#[[1]], mypinorange, "Alignment" -> Bottom], #[[
         2]]] & /@ (facts),
     Tooltip[
        GeoMarker[#[[3]], #[[1]], "Alignment" -> Bottom], #[[
         2]]] & /@ (flick)},
    GeoCenter -> centro, GeoRange -> Quantity[1, "Miles"]]]]

nearby[loc_String, fquery_String, yquery_String] := 
 With[{data = WikipediaData[loc, "GeoNearbyDataset"]},
  Block[
   {centro, facts, yellah, flick, box},
   centro = data[[All, {"Title", "Position"}]][[1]][[2]]; 
   facts = factual[
      "PlacesDataset", {"Location" -> centro, 
       "Radius" -> Quantity[1000, "Yards"], "Query" -> fquery, 
       MaxItems -> 20}][All, {"Location", "Name"}]; 
   yellah = 
    yelp["BusinessDataset", {"Categories" -> yquery, 
       "Location" -> centro, "Radius" -> Quantity[.6, "Miles"]}][
     All, {"Name", "Coordinate"}];
   flick = 
    ServiceExecute["Flickr", 
      "ImageSearch", {"Location" -> centro, 
       "Elements" -> {"FullData"}, "ImageSize" -> "Small", 
       MaxItems -> 10}][All, {"Thumbnail", "Title", "Location"}];
   DynamicGeoGraphics[{Tooltip[
        GeoMarker[#[["Position"]]], #[["Title"]]] & /@ (data), 
     Tooltip[GeoMarker[#[[1]], mypinorange, 
         "Alignment" -> Bottom], #[[2]]] & /@ (facts), 
     Tooltip[GeoMarker[#[[2]], mypinblue, "Alignment" -> Bottom], #[[
         1]]] & /@ (yellah),
     Tooltip[
        GeoMarker[#[[3]], #[[1]], "Alignment" -> Bottom], #[[
         2]]] & /@ (flick)},
    GeoCenter -> centro, GeoRange -> Quantity[1, "Miles"]]]]

The Manipulate.

The Manipulate accepts any location, any type of food, and any place in to the location query, factual query, and yelp query, respectively. The manipulate works best with quotes around the queries, but it can work without as well. The location will work for any location that has a Wikipedia page.

Manipulate[
 nearby[ToString[location], ToString[factualquery], 
  ToString[yelpquery]],
 {{location, "Boston", "Location (Wiki Locations-Red)"}, 
  ControlType -> InputField}, {{factualquery, "Coffee", 
   "Factual Query (Food-Orange)"}, 
  ControlType -> InputField}, {{yelpquery, "Italian", 
   "Yelp Query (Places-Blue)"}, ControlType -> InputField}, 
 SynchronousUpdating -> False, Deployed -> True]

The Inputs.

Input fields can be used to take individual options.

Location = "Boston";
FactualQuery = "Coffee";
YelpQuery = "Italian";

nearby[Location, FactualQuery, YelpQuery]

The Output gives the Wikipedia pages in Red, Pictures from Flickr in Thumbnails, the Factual Query in Blue, and the Yelp Query in Orange.

Image Outputted for Coffee or Italian food in Boston

Future goals include trying to draw a path between two user selected points. This project was completed at the Wolfram Research Summer Camp 2016. Shyam Sai.

POSTED BY: Shyam Sai

enter image description here - you have earned "Featured Contributor" badge, congratulations !

This is a great post and it has been selected for the curated Staff Picks group. Your profile is now distinguished by a "Featured Contributor" badge and displayed on the "Featured Contributor" board.

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract