Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I would like to set up a webpage that takes a number of Facebook status updates via the Javascript API and sorts them into an array. Then I'd like to send this array to a Python script, which can specifically do language analysis with NLTK. After I get a suitable result in Python, I'd like to return the result from that script to Javascript for displaying to the user, etc. Does this sound possible?

share|improve this question
2  
Why don't you just use json? – Matti John Apr 25 at 14:56
Use json for what? With NLTK? Does that work? – subyraman Apr 25 at 14:58
Use json for communicating between Python and JavaScript. – kindall Apr 25 at 15:02
I meant you can simply parse the Javascript API result using the json module in the standard library, which will return a python object which you can then presumably use in NLTK – Matti John Apr 25 at 15:02
Any resources showing how to do that with an array would be helpful. – subyraman Apr 25 at 15:13

2 Answers

Yes, totally. Check out Google App Engine to build this sort of functionality. In particular check out these links:

NLTK on App Engine: Using the Python NLTK (2.0b5) on the Google App Engine and http://code.google.com/p/nltk-gae/

Facebook API on App Engine: https://developers.google.com/appengine/articles/shelftalkers

I assume that you want to make it interactive because you mentioned the word "user".

share|improve this answer
You don't need to use the App Engine for this sort of thing - although it's one possibility. Fundamentally, this is a very common problem and can be summed up by considering the NLTK part of the process as an API. You could then call it using Ajax – Basic Apr 25 at 15:44
True; I listed one of the most common options. – Xaranke Apr 25 at 16:12

Calling a service from Javascript is a very common problem. One way of solving it is to write a specific type of website known as a Webservice which would make the process flow something like...

  • Javascript uses Ajax (Asynchronous Javascript and XML) to send an HTTP Request to your Webservice containing the information you want to process.
  • The Webservice receives the request and performs the requested processing (eg by invoking the NLTK)
  • The resulting data is sent back over the same Http connection
  • A javascript function is called and passed the results of the data

The easiest way to send a request is using jQuery. The easiest way to format the data to be passed back and forth is JSON (JavaScript Object Notation).

An example call would look something like this...

$.json({
  url: "/url/of/Webservice",
  data: {
         "SomeKey": "SomeValue",
         "SomeList": ["Item1", "Item2", "Item3"]
         /*... etc */
        }
}).done(function(response) {
  //Assuming a response that looks like this: {"Result": "Some Result"}
  alert("The Webservice said: " + response.Result);
});

It's up to you how you'd implement the Webservice. If you want to use Python, Django is one of many good frameworks to get you started

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.