Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Stream of Consciousness

by beretboy (Chaplain)
on Jun 27, 2003 at 19:03 UTC ( #269708=CUFP: print w/ replies, xml ) Need Help??

Word association has long been used as a phsycoanalytic tool, as has it's visual counterpart, the Rorschach Inkblot test. I have adapted this idea from serious tool to amusing distraction. Sorry about the embedded HTML, this was just a quick hack. Every now and then, it will have a broken image, and I can think of a few ways to fix it but for now, c'est la vie. Here is how it works. You will be presented with a word and a picture, and asked to enter the first word that comes to mind. Remember to enter only one word, otherwise the script will ignore you. The word you enter will then be used to fetch a new image (via Google) which the next person will then respond to. You can do this as many times as you want with one exception, you cannot respond to your own word/picture. The neat part is the subroutine "image", which scrapes http://images.google.com
The Demo is Here: Stream of Consciousness
#!/usr/bin/perl use strict; use CGI qw( param header ); sub image { # Give it a word, it gives you an image! use LWP::UserAgent; my $word = shift; my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/2525010 +1'); my $request = HTTP::Request->new('GET','http://images.google.com/i +mages?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&q=' . $word); my $response = $ua->request($request); my $data = $response->content; my @urls = ($data =~ m/\?imgurl=(.*?)&/g); my $url = $urls[rand @urls]; $url = 'http://' . $url; } print header; my $word = param("word"); $word =~ s/<(.*?)>//g; $word =~ s/\+//g; !($word =~ / /) || die "ONE WORD ONLY"; if ($word) { print <<HEAD; <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" +> <title>The Stream</title> <head> <body text="#ffffff" bgcolor="#000000" link="#ffffff" alink="#ffffff" +vlink="#ffffff"> <center><font size=+8>The Stream</font><center> <hr size=1 width=35%> HEAD my $ip = $ENV{"REMOTE_ADDR"}; open(RLASTIP,"lastip") || die "File Open Failed: $!"; my $lastip = <RLASTIP>; close(RLASTIP); if (!($ip eq $lastip)) { my $url = image($word); open(WLIST,">>list"); print WLIST "$word $url\n"; close WLIST; open(WLASTIP,">lastip") || die "File Open Failed: $!"; print WLASTIP "$ip"; close(WLASTIP); } else { print "<script>alert(\"Your association was not added because you +did the last one. You cannot respond to your own.\\n Try again later +when someone has responded to your thought.\");</script>"; } open(RLIST,"list"); my @list = <RLIST>; close(RLIST); foreach $_(@list) { my ($link,$linkurl); ($link,$linkurl) = split(" ", $_); print "<center><A HREF=\"$linkurl\">$link</A></center>"; } print "<hr size=1 width=35%>\n</body>\n</html>"; } else { open(RLIST,"list") || die "File Open Failed: $!";; my $lastline; $lastline = $_ while <RLIST>; close(RLIST); my ($lastword,$lasturl); ($lastword,$lasturl) = split(" ", $lastline); print <<MONKEY; <html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" +> <title>Stream of Consciousness</title> <head> <body text="#ffffff" bgcolor="#000000" link="#ffffff" alink="#ffffff" +vlink="#ffffff6"> <center><font size=+8>Stream of Consciousness</font><center> <hr size=1 width=55%> <br> <center><img src="$lasturl"><center> <center><font size=+5>$lastword</font></center> <center> <hr size=1 width=55%> <br> <b>Enter The First Word That Comes To Mind</b> <form method="post" action="stream.cgi"> <center><input type="text" name="word" style="background:#000000; colo +r:#ffffff"></center> <br> <center><input type="Submit" name="submit" value="submit" class="butto +n" style="background:#000000; color:#ffffff"></center> </form> </center> </body> </html> MONKEY }


"Sanity is the playground of the unimaginative" -Unknown

Comment on Stream of Consciousness
Download Code
Re: Stream of Consciousness
by diotalevi (Canon) on Jun 28, 2003 at 13:16 UTC

    This would be even nicer if there was some sort of indication that other people are using the program too. Sort of a 'other users' without usernames. Or an inline view of the last few keywords. Perhaps with responses.

Re: Stream of Consciousness
by gjb (Vicar) on Jun 28, 2003 at 20:06 UTC

    Uhm, you may want to be careful with this. Google doesn't like user agents.

    A while ago when a worked for a company we had a prototype running that used Google's web search capabilities. Since it was just a prototype, we didn't bother to contact Google about it until we were sure we'd start using it in production.

    One morning I got to work, and my colleagues were complaining about the network: they couldn't reach Google, so apparently there was some wrong somewhere. I got a little worried and started running some tests and found out pretty soon that only Google was unreachable.

    Yeah, right. They'd noticed that some automated user agents was submitting queries and had blocked that IP-address. Unfortunately all the company's internet traffic was routed via one and the same proxy, and its IP address was blacklisted.

    I had to write a very humble letter to Google to request them to please take that address from their blacklist. Fortunately Google is not mission-critical for that company and I was backed by my boss who knew quite well what I was doing, but it earned me a certain reputation nevertheless ;-)

    To return to the facts, I think you should have a look at their "terms of use" document, it clearly states that they don't like what your script is doing.

    Best regards, -gjb-

      How can they tell if it's an automated request?

      "Sanity is the playground of the unimaginative" -Unknown
        By pattern. A human being probably won't be submitting requests at the exact same interval for a long series of requests. Or he won't be submitting requests for 48 hours straight, or every 2 ms. In other words, human requests should have less regularity and volumn.

        It was probably mostly the volume since I had a random number generator for intervals (not to disguise, just out of courtesy). It was not exactly a lot of traffic (compared to what they receive anyway, but it must have been too long and (still) too regular.

        Oh well, best regards, -gjb-

Re: Stream of Consciousness
by chunlou (Curate) on Jun 29, 2003 at 17:07 UTC
    A practical use of "stream of conscious" would be design of user interface. Present user with an icon, ask him to either type a word/command or choose one from a dropdown list he thinks "associated" with the icon. For instance, when people see a printer icon, they usually think of "print" document.

    Another use would be to measure "attention span." It could be more difficult because of the need to measure semantic proximity--by use of some thesaurus or algorithm. Simplity put, if the consecutive words are in close proximity, you will be plotting a series of near-zero on your graph. When attention breaks, you may observe a spike. The spacing between spikes measure attention span, which could be more quantitatively done by time series (or fourier) analysis.
Re: Stream of Consciousness
by beretboy (Chaplain) on Jun 30, 2003 at 01:21 UTC
    Here is why it won't be identified (and why I don't feel guilty):
    1. The google request is made right after the users presses submit, so the timing depends on when the user arrives.
    
    2. The site is not wildly popular, I don't even get 1000 requests per day (which is googles limit for non-paying customers).
    
    3. My school sends everyone through a proxy, and I wouldn't be suprised if they got 6000 requests per day, and google hasn't blocked them.
    


    "Sanity is the playground of the unimaginative" -Unknown
Re: Stream of Consciousness
by John M. Dlugosz (Monsignor) on Jul 11, 2003 at 16:24 UTC
    Browsing the word-list, it needs a next/prev button.

    The word it's means “it is”. None of the set qw/his hers its/ has an apostrophe.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://269708]
Approved by Mr. Muskrat
Front-paged by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-07-26 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls