-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
181ebcd
commit f187580
Showing
34 changed files
with
3,501 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* ajax-er.js -- provides ajax interface for the frontend to connect to the backend. | ||
* basic work is to propagate sensor data from client to server. | ||
* | ||
* written by samar -- 060321011 | ||
* | ||
*/ | ||
debug = true; | ||
|
||
function sensorRequestHandler(sensorName,dataString) | ||
{ | ||
//which sensor said ? sensorName | ||
//what did it say ? dataString | ||
|
||
//make proper url | ||
|
||
url = "/appy/engine/AJAXSensor.py?sensorName="+sensorName+"&q="+dataString; | ||
|
||
//create ajax request object | ||
var sensorRequest; | ||
if (window.XMLHttpRequest) { // Mozilla, Safari, ... | ||
sensorRequest = new XMLHttpRequest(); | ||
if (sensorRequest.overrideMimeType) { | ||
sensorRequest.overrideMimeType('text/xml'); | ||
// See note below about this line | ||
} | ||
} | ||
else if (window.ActiveXObject) { // IE | ||
try { | ||
sensorRequest = new ActiveXObject("Msxml2.XMLHTTP"); | ||
} | ||
catch (e) { | ||
try { | ||
sensorRequest = new ActiveXObject("Microsoft.XMLHTTP"); | ||
} | ||
catch (e) {} | ||
} | ||
} | ||
|
||
if (!sensorRequest) { | ||
alert('Giving up :( Cannot create an XMLHTTP instance! AppY won\'t work'); | ||
return false; | ||
} | ||
|
||
sensorRequest.onreadystatechange = function() | ||
{ | ||
if (sensorRequest.readyState == 4) | ||
{ | ||
if (sensorRequest.status == 200) | ||
{ | ||
response = sensorRequest.responseXML; | ||
if (debug) alert(response); | ||
var element = response.getElementsByTagName('root').item(0); // Read the first element | ||
document.ajax.dyn.value = element.firstChild.data; // Assign the content to the form | ||
|
||
exec(actuator(sensorRequestHandler.responseText)); | ||
} else { | ||
alert('There was a problem with the request.'); | ||
} | ||
} | ||
}; | ||
|
||
//send request | ||
sensorRequest.open('GET', url, true); | ||
sensorRequest.send(''); | ||
|
||
|
||
|
||
//attach actuator | ||
|
||
} | ||
|
||
//this is the beginning of all things | ||
function beginGame() | ||
{ | ||
//get status from server | ||
//if working | ||
//ask to start game | ||
//get user details | ||
getUserDetails() | ||
//get the number of words in the movie title | ||
//create guessBoxes | ||
createGuessBoxes() | ||
//hand-over control to the GameController | ||
//else | ||
//say the error | ||
//give contact details | ||
} | ||
|
||
function userEnteredWordSensor(word) | ||
{ | ||
//what word ? | ||
alert(word); | ||
sensorRequestHandler("userEnteredWordSensor",word); | ||
} | ||
|
||
function userIdleForLongTimeSensor(idle_time) | ||
{ | ||
//how much time was the user idle for ? | ||
} | ||
|
||
function userEnteredNonPerformedWordSensor() | ||
{ | ||
//which word did he enter ? | ||
} | ||
|
||
function userGuessedtheMovieTitle() | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<!-- | ||
This is the front end for the appy. | ||
Created By : Deepak Shakya | ||
AJAXified and Sensifed by : samar - 060321011 | ||
This file is under Apache License. | ||
--> | ||
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
|
||
<head> | ||
<title>AppY/dumb_charades_ai </title> | ||
<meta http-equiv="content-type" content="text/html;charset=utf-8" /> | ||
<meta name="generator" content="Geany 0.14" /> | ||
<script language='javascript' src='ajax-er.js'></script> | ||
<style type="text/css"> | ||
body | ||
{ margin:5px; | ||
background:#F5F5F5; | ||
} | ||
|
||
#main_container | ||
{ border:1px solid black; | ||
width:100%; | ||
background:white; | ||
overflow:auto; | ||
} | ||
|
||
#header | ||
{ border:1px solid black; | ||
width:95%; | ||
margin:5px; | ||
height:50px; | ||
} | ||
|
||
#appy | ||
{ float:left; | ||
border:1px solid black; | ||
width:60%; | ||
margin:5px; | ||
height:200px; | ||
} | ||
|
||
#response_log | ||
{ float:right; | ||
border:1px solid black; | ||
width:35%; | ||
margin:5px; | ||
height:200px; | ||
overflow-y:scroll; | ||
} | ||
|
||
#input_area | ||
{ width:95%; | ||
margin:5px; | ||
text-align:left; | ||
} | ||
|
||
#input_area .input_enabled,#input_area .input_enabled:focus,#input_area .input_enabled:hover | ||
{ font:bold 24px 'Dejavu Sans Mono'; | ||
margin:5px; | ||
padding:3px; | ||
border:1px solid black; | ||
background:#FBFFB2; | ||
} | ||
|
||
#input_area .input_disabled | ||
{ font:bold 24px 'Dejavu Sans Mono'; | ||
margin:5px; | ||
padding:3px; | ||
background:#F9F9F9; | ||
border:1px solid black; | ||
} | ||
|
||
#footer | ||
{ | ||
background:#8D6565; | ||
border:1px dotted green; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="main_container"> | ||
<center> | ||
<div id="header"> | ||
<h2 align='center'>AppY -- A Person in pYthon playing dumb-charades-ai</h2> | ||
</div> | ||
<div style="overflow:auto"> | ||
<div id="appy"></div> | ||
<div id="response_log"></div> | ||
</div> | ||
<div id="input_area"> | ||
<form action="test" method="post"> | ||
<fieldset id="inputbox"></fieldset> | ||
<script type="text/javascript" language="javascript"> | ||
words = 2; | ||
word_length = new Array(5,10); | ||
inputbox = document.getElementById("inputbox"); | ||
inputbox.innerHTML = "<legend style=\"margin-left:10px;\">Type your guesses for each word</legend>"; | ||
for(i=0; i<words; i++) | ||
{ | ||
inputbox.innerHTML = inputbox.innerHTML + "<input id=\"word"+i+"\" type=\"text\" name=\"word"+1+"\" class=\"input_enabled\" size=\""+(word_length[i]+2)+"\" maxlength=\""+word_length[i]+"\" onChange='userEnteredWordSensor(this.value);' />"; | ||
} | ||
</script> | ||
<b>Press TAB to submit your guess.</b> | ||
</form> | ||
</div> | ||
<div id='footer'> | ||
<p align='center'> | ||
<a href='about.html'>About AppY</a> | ||
<a href='../documentation/'>Documentation</a> | ||
<a href='http://dumb-charades-ai.googlecode.com'>Project site and Contact Details</a> | ||
</p> | ||
</div> | ||
</center> | ||
|
||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#AJAXSensor.py -- | ||
# handles the sensor requests from the front-end and propages it to the proper sensor on the backend | ||
# then responds back to the client with the response in XML form. | ||
|
||
# written by samar - 060321011 | ||
# This file is under Apache License. | ||
|
||
#uses the mod_python libraries for all cgi dealings | ||
from mod_python import util, apache, Session; | ||
from urllib import unquote; | ||
from sensors import *; | ||
|
||
debug = True; | ||
|
||
|
||
def handler(req): | ||
'''this is sort of main(char args[]) in C -- req is the request object''' | ||
global debug #refer to the global instance | ||
|
||
session = Session.Session(req); | ||
try: | ||
if session.is_new(): | ||
session['user_name'] = req. | ||
session['type'] | ||
session['waypoint_info'] | ||
session['uid'], | ||
session['wordid'] | ||
|
||
req.content_type = "text/html"; | ||
query_string = util.parse_qs(req.parsed_uri[7]); | ||
|
||
req.write(str(query_string)); | ||
sensorName = query_string['sensorName'][0]; | ||
if debug: req.write("Sensor = " + sensorName); | ||
senseString = query_string['q'][0]; | ||
|
||
#dynamic calls implemented for the first time in history of SICSR! | ||
if (len(q.strip())) == 0: | ||
prepareandsendResponse('Error: You need to enter something!'); | ||
else: | ||
call = "responseDict = %s(req,'%s')" % (sensorName,senseString); | ||
exec(call); #call the right function and stores the response in responseList; | ||
req.write("You said %s and the response is %s" % senseString, responseList ); | ||
return apache.OK; | ||
|
||
def prepareandsendResponse(responseDict): | ||
response = """ | ||
<controller-response> | ||
<sensor-name>%s</sensor-name> | ||
<actuator-name>%s</actuator-name> | ||
<actuator-commands> | ||
<command type='action_sequence'>{path}</command> | ||
<command type='image_sequence'>{paths-seperated-by-semicolon}</command> | ||
<command type='word_info'>{word_info}</command> | ||
</actuator-commands> | ||
</controller-response>"""; |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import re; | ||
import nltk; | ||
from functions import *; | ||
|
||
###take the movie title | ||
#movie_title = raw_input("Enter Movie Title ==>") | ||
file = open("../test_data/movie_250","r") #take it from the top 250 db of IMDB | ||
#read the movie title | ||
movie_title = file.readline() | ||
|
||
###start processing. | ||
print 'Shh! I am going to enact-->', movie_title; | ||
|
||
#where is the user from ? -- take this from client.html | ||
user_location = raw_input("Where are you from ?"); | ||
|
||
#have we already performed this movie title ? | ||
|
||
#start individual word processing | ||
while True: | ||
#get the intividual words | ||
word_list = nltk.word_tokenize(movie_title) | ||
|
||
#remove the extraApostrophes | ||
word_list = removeExtraApostropheS(movie_title,word_list); | ||
print "After removeExtraApostropheS -->", word_list | ||
|
||
#scan the list for determining the EASIEST one and so on... -- the order of performance | ||
#this is an ordered tuple(word, priority(default 0), action_seq_id) | ||
ordered_list = [] | ||
t = 0; | ||
|
||
ordered_list = determineOrder(word_list) | ||
for w in ordered_list: | ||
#convert to singular --> no need, nltk CAN process plurals as well. | ||
print "Processing %s" % w | ||
|
||
#do we have a corresponding action sequence in db ? | ||
|
||
#database search -- | ||
#somethign like --> if x in databaseList(): | ||
#if yes, assign +1 | ||
#if no, assign -1 | ||
|
||
|
||
inDatabase, action_seq_id, length = findinDatabase(w) #tuple unpacking | ||
|
||
if inDatabase: | ||
ordered_list += [w, +1, action_seq_id, length] | ||
else: | ||
ordered_list += [w, -1, None, None] | ||
|
||
#sort on the basis of length of action sequence | ||
|
||
print ordered_list; | ||
break; | ||
|
||
print "Done" |
Oops, something went wrong.