Sixth Sense - Social Car Pooling With NLP and GeoSpatial Data
Introduction
What is the easiest thing to do on earth, NOW? My answer would be : Updating my Facebook status. What if your status updates could bring you smart benefits and relevant real-world deals around your friends circle? This is a Facebook application that could read and process the user status update and also allow user to update the status from within the application. Your status messages regarding travelling are identified and interpreted using Natural Language Processing techniques. The source (post origin by default) , destination and time are stored in the database.If one of your friends are updating their status with travel-related content and if its related to your travel, bingo! You and your friend get a travel deal notification. As Ultrabooks are more mobile, long batter backup that supports traveling and have acceleration measurements, it would be an ideal platform to run the application.Example:
James Status update: Gonna have a drive from Bangalore to Chennai next Monday 12 pm.
Sam (Facebook friend of James ) Status update : Wanna travel to Chennai this 29/10/2012 (Monday) 1 pm.
We process both these statuses with their geo-spatial data (with html5) and Natural language processing and sends a notification to both the guys informing that they could share the drive since they have a common source, destination and start-time.
Optionally, if a status is relevant the application could send notification to two people who are not directly friends. This way the application will stand as a mediator to pass relevant information without sharing too much personal information or personal connection.
Background
I plan to use Java + HTML5 for coding and to host it in Google App Engine. Eventually I would love to make this an application easily available in Ultrabooks and all mobile platforms. Google App Engine is a cloud hosting that would seamlessly support this.I began Experimenting on making Facebook applications in Google App Engine over a year ago. But at that time there was no consistent solution as facebook tweaked there requirements very frequently. It was almost 10 months later IBM published the article : Building a Facebook Application on Google App Engine - Tutorial From IBM
Its an excellent source to get started with Facebook application development in Google App Engine.
Other useful links:
- Getting Geo-Spatial Data using HTML5
- How Social Applications add People to the Trusted Group - The Psychology behind it - Facebook Video: This video explains exactly why/how the application will build good connections over time.
Using the code
Code to ask permission to read the Facebook Status of a User
A sample jsp page for a facebook application that gets the permission to read users posts and friends details. The application id and application name supplied here are just sample values. The code works if they're given real values.<%@ page import="java.util.*,org.apache.commons.codec.binary.*,
java.net.*, org.json.simple.*, com.akhilanil.*,java.io.PrintWriter" %>
<html>
<head>
<title>Status Message Authorization</title>
<script type="text/javascript">
window.onload = function WindowLoad(event) {
<%
PrintWriter writer = response.getWriter();
FacebookSignedRequest facebookSR = null;
facebookSR = FacebookSignedRequest
} catch (Exception e) {
e.printStackTrace();
String oauthToken = facebookSR.getOauth_token();
response.setContentType("text/html");
+ "&redirect_uri=https://apps.facebook.com/Constants." +
"APP_NAME/&scope=user_about_me, user_activities,user_birthday," +
"user_checkins,user_education_history,user_events,user_groups," +
"user_hometown,user_interests,user_likes, user_location,user_notes," +
"user_photos,user_questions,user_relationships, " +
"user_relationship_details,user_religion_politics," +
"user_status,user_subscriptions,user_videos,user_website," +
"user_work_history,email,read_stream,publish_stream," +
"read_friendlists,friends_birthday,friends_location";
+ "'</script>");
}
%>
}
</script>
</head>
<body>
<p>Authorization </p>
<form method="POST" action="/storemytoken">
<p> Click on the button below to authorize any one person to read your status.</p>
<p><br>Your current token id is : <%=request.getParameter("signed_request")%></p>
<p><input type="submit" value="Authorize" name="b1"></p>
<input type="hidden" name="signed_request" id="signed_request"
value="<%=request.getParameter("signed_request")%>" />
</form>
</body>
</html><%@ page import="java.util.*,org.apache.commons.codec.binary.*, java.net.*,
org.json.simple.*, com.akhilanil.*,java.io.PrintWriter" %>
<html>
<head>
<title>Status Message Authorization</title>
<script type="text/javascript">
window.onload = function WindowLoad(event) {
<%
PrintWriter writer = response.getWriter();
FacebookSignedRequest facebookSR = null;
facebookSR = FacebookSignedRequest
} catch (Exception e) {
e.printStackTrace();
String oauthToken = facebookSR.getOauth_token();
response.setContentType("text/html");
+ "&redirect_uri=https://apps.facebook.com/akhilfbfriends"
+ "/&scope=user_about_me, user_activities,user_birthday,user_checkins,"
+ "user_education_history,user_events,user_groups,user_hometown,"
+ "user_interests,user_likes, user_relationship_details,"
+ "user_religion_politics,user_status,user_subscriptions,"
+ "user_videos,user_website,user_work_history,email,read_stream,"
+ "publish_stream,read_friendlists,friends_birthday,friends_location";
+ "'</script>");
}
%>
}
</script>
</head>
<body>
<p>Authorization </p>
<form method="POST" action="/storemytoken">
<p> Click on the button below to authorize.</p>
<p><br>Your current token id is : <%=request.getParameter("signed_request")%></p>
<p><input type="submit" value="Authorize" name="b1"></p>
<input type="hidden" name="signed_request" id="signed_request"
value="<%=request.getParameter("signed_request")%>" />
</form>
</body>
</html>
Code to fetch geographical location using HTML 5
<script>var x=document.getElementById("demo");function getLocation()
{ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); }
else{x.innerHTML="Geolocation is not supported by this browser.";} }function showPosition(position)
{ x.innerHTML="Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude; }</script>
The Secret Code I Used to Make RestFB work with Google App Engine
Code snippet after we get the oauthToken from the JSP and use it to get the user details and friends details from Facebook and use the PersistenceManager from Google App Engine to store it on Google Datastore. The world class BigTable of Google help us to search through the database using keywords from NLP as fast as Google.com does and provide relevant results.oauthToken = facebookSR.getOauth_token();
Connection<User> myFriends = facebookClient.fetchConnection(
User me = facebookClient.fetchObject("me", User.class);
Key memProfileKey = KeyFactory.createKey(
PersistenceManager pm = PMF.get().getPersistenceManager();
m.setKey(memProfileKey);
myDob = me.getBirthdayAsDate();
m.setName(me.getName());
m.setGender(myGender);
m.setLastName(me.getLastName());
NamedFacebookType hmeTwn = me.getHometown();
m.setHometown(hmeTwn.getName());
m.setHometown(me.getHometownName());
m.setLastName(me.getLastName());
m.setPolitical(me.getPolitical());
m.setToken(oauthToken);
pm.makePersistent(m);
pm.close();
fetchFriends = new FetchFriends();
List<User> listUser2 = fetchFriends.getFriendsData(myFriends);
Points of Interest
This concept of combining 'NLP and Geo Spatial data to decode the Status Updates ' is vastly Expandable and Rewarding
I found that reading and interpreting the statuses using NLP combined with Geo-Spatial data have great potential. We could display relevant status results of friends when one person makes a status update. It could be related to any subject like workouts, meals, want to go for the same movie/conferences, buying a book etc. This concept could span over every domain. They could both eventually benefit from the status updates. That's what something Facebook doesn't do. They focus on exposing what others do and doesn't matter if its relevant to the current users status.The Status Update Source Could Be Expanded
All of the major social networks provide their APIs. The application can be integrated with other social networking applications like Twitter and LinkedIn also to get retrieve status updates.Surprise Discovery! Google App Engine could be used to host a Java Facebook Application
I found that it's possible to build a Facebook java application with restfb framework and deploy it in Google App Engine. That is a gold mine of opportunities because initial java hosting is free in Google App Engine. It's hard to get non-paid Java hosting usually.License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Comments
Post a Comment