Assignment 8: xml parsing?

Europe ? #
Polska http://pl.engadget.com
Deutschland http://de.engadget.com
Asia ? #
???? http://chinese.engadget.com
???? http://cn.engadget.com
??? http://japanese.engadget.com/
???? http://kr.engadget.com/
Español http://es.engadget.com
HD http://www.engadgethd.com
Mobile http://www.engadgetmobile.com
Engadget http://www.engadget.com/
Engadget #
Web http://search.aol.com/aol/search?invocationType=wl-gadget&query=
Images http://search.aol.com/aol/image?invocationType=wl-gadget&query=
Video http://search.aol.com/aol/video?invocationType=wl-gadget&query=
News http://search.aol.com/aol/news?invocationType=wl-gadget&query=
Local http://local.aol.com/aol/local?invocationType=wl-gadget&query=
RSS Feed /rss.xml
Contact us /contact/comment/
Tip us on news! /contact/tips/
http://www.monoprice.com/products/subdepartment.asp?c_id=104&cp_id=10428
Permalink http://www.engadget.com/2009/03/30/mini-displayport-adapters-now-available-for-20/
Email this /forward/1502779/
31 Comments http://www.engadget.com/2009/03/30/mini-displayport-adapters-now-available-for-20/#comments
http://www.businesswire.com/portal/site/google/?ndmViewId=news_view&newsId=20090330006184&newsLang=en
Permalink http://www.engadget.com/2009/03/30/intels-xeon-3500-5500-series-officially-unveiled-for-servers-a/
Email this /forward/1502788/
17 Comments http://www.engadget.com/2009/03/30/intels-xeon-3500-5500-series-officially-unveiled-for-servers-a/#comments

For this assignment I tried to get engadget headlines and mix up the links so that it doesn’t make sense, but all i could parse was some links and some crap. I tried to use the Getter.java and Homework.java to make this work. Later i found that Homework.java was used to parse HTML and not XML. So instead of feeding the rss.xml link for engadget I fed in the direct html link. Since the source for the HTML was very messy I could not seperate out the elements required.

code:

import org.dom4j.Document;
import org.dom4j.DocumentFactory;
import org.dom4j.io.SAXReader;
import org.dom4j.Element;
import org.xml.sax.XMLReader;
import java.util.List;
import java.util.HashMap;
import java.util.regex.*;

public class Getter1 {
public static void main(String[] args) throws Exception {
// String url = args[0];

HashMap<String, String> map = new HashMap<String, String>();
map.put(”xhtml”, “http://www.w3.org/1999/xhtml”);
DocumentFactory factory = DocumentFactory.getInstance();
factory.setXPathNamespaceURIs(map);

XMLReader tagsoup = new org.ccil.cowan.tagsoup.Parser();
SAXReader reader = new SAXReader(tagsoup);
EasyHTTPGet getter1 = new EasyHTTPGet (”http://www.engadget.com”);

Document document = reader.read(getter1.responseAsInputStream());
List listItems = document.selectNodes(”//xhtml:li”);

for (Object o: listItems) {
Element elem = (Element)o;
String[] parts = elem.getText().split(”/”);

Element anchor = (Element)elem.selectSingleNode(”xhtml:a”);
String project = anchor.getText();
String href = anchor.attributeValue(”href”);
System.out.println(project + ” ” + href);

}

}
}

Context Free Grammar:

I decided to make a prescription/disease identifier. This script automatically allocates a disease and prescribes medication for a patient. For this i made use of the context free grammer code and changed the grammar.

o/p:

Too bad you are dying from Mucormycosis- Zygomycosiss Neurontin

Im sorry you are suffering from Mucormycosis- Zygomycosiss take Gabapentin

Too bad you are dying from Lymphogranuloma venereum take Gabapentin

Im sorry you are suffering from Lymphogranuloma venereum take Wellbutrin SR (Bupropion Hydrochloride Sustained-Release)

Im sorry you are suffering from Lymphogranuloma venereum take Gabapentin

Congratulations you are free from Lymphogranuloma venereum take Wellbutrin SR (Bupropion Hydrochloride Sustained-Release)

Im sorry you are suffering from Mucormycosis- Zygomycosiss take dog food laced with Imitrex Nasal Spray

Midterm :

My midterm project was a made making use of the word cloud code and a little PHP. Since this class deals with text i thought i will make use of the twitter API to pull tweets from twitter and use that as input for the word cloud program.

For pulling the tweets I used PHP. Since the word cloud program requires a text file as input I had to parse the xml feed of twitter and then save it to a txt file on the server and feed that text file as input for the word cloud.

$file = “http://twitter.com/statuses/public_timeline.xml?count=200″; is the link for the public timeline of twitter in xml.

The php code is as follows :

<html>
<head>
<META HTTP-EQUIV=”refresh” CONTENT=”15; URL=http://www.sanjaypapinazath.com/a2z/twit_pull6.php”>
</head>
<body>
<?php

ini_set(’display_errors’, true);
ini_set(’display_startup_errors’, true);
error_reporting(E_ALL);

$file = “http://twitter.com/statuses/public_timeline.xml?count=200″;

//$fp1=fopen(’/home/sanjaypa/public_html/a2z/twit_pull.txt’,'w’);

$currentTag = “”;

function contents($parser, $data){
$fp1=fopen(’/home/sanjaypa/public_html/a2z/twit_pull.txt’,'a ‘);
global $currentTag;
if ($currentTag == ‘TEXT’ || $currentTag == ‘NAME’) {
echo “$data<br/>”;
fwrite($fp1, $data);
fclose($fp1);

}
}

function startTag($parser, $name){
global $currentTag;
$currentTag = $name;
// echo “<b>”;
}

function endTag($parser, $data){
// echo “</b><br />”;
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, “startTag”, “endTag”);
xml_set_character_data_handler($xml_parser, “contents”)
$fp = fopen($file, “r”);
$data = fread($fp, 80000);
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die(”Error on line ” . xml_get_current_line_number($xml_parser));
}

xml_parser_free($xml_parser);
fclose($fp);
?>
</body>
</html>

In the processing sketch i made use of the SMS library which makes use of the accelerometer in the laptop.

So when the sketch is running and the laptop is tilted upwards the words used more will go up.

o/p :picture-1.png

Assignment #4:

wordclloud

My lame attempt to use the word cloud code. Took text from Edgar Allen Poe’s Dreamland and tried to make it a palindrome.

This code takes splits the text into words and then makes the more commonly used words bigger and less used smaller.

Processing App

Assignment #3:

For assignment #3 i was attempting to make use of the random lines code and the Negative space code. What i wanted to do was to get then empty spaces in a piece of text and then replace the blanks with random characters and then randomize the lines so that I would get some abstract patterns.

import java.util.regex.*;
import java.util.ArrayList;
import com.decontextualize.a2z.TextFilter;

public class NegativeSpace2 extends TextFilter {
public static void main(String[] args) {
new NegativeSpace2().run();
}

private int longestLineLength = 0;

private ArrayList<String> lines = new ArrayList<String>();

private String[] chars = { “3″, “*”, “o”, “0″ };

//private char[] chars = new char[]{’3′,’*',’o',’0′};
int r = (int)(Math.random()*chars.length);

String randomChar = chars[r];

public void eachLine(String line) {
if (line.length() > longestLineLength) {
longestLineLength = line.length();
}
lines.add(line);
}

public void end() {
for (String line: lines) { while (lines.size() > 0) {
int randomIndex = (int)(Math.random() * lines.size());

}

line = line.replaceAll(”\\W”, chars[r]);
line = line.replaceAll(”\\w”, ” “);
println(line);
}
}
}

When i compile i get no errors . But when i execute it (ctrl d) i get nothing. All i get is a ^D on the screen and it doesn’t do anything else.

Assignment #2:

Assignment 2 was to use java to play around with text.

My aim was to censor Biggie’s Hypnotized , so i changed the n-word to cupcakes and $h*t to dozer and sort it. Code is really simple all i did was use the replace function.

o/p:

(Take that, take that, take that, haha!)
All Philly hoes, dough and Moschino (c’mon)
And I just love your flashy ways
And I just love your flashy ways
And I just love your flashy ways
And I just love your flashy ways
And I just love your flashy ways
And I just love your flashy ways (uh-huh)
And I just love your flashy ways (uh-huh)
And I just love your flashy ways (uh-huh)
And I just love your flashy ways (uh-huh)
At last, a nigga rappin bout blunts and broads
At my arraignment, note for the plantiff
Bang every MC easily, busily
Biggie Biggie Biggie (uh-huh) can’t you see (huh)
Biggie Biggie Biggie (uh-huh) can’t you see (uh)
Biggie Biggie Biggie (uh-huh) can’t you see (uh)
Biggie Biggie Biggie (uh-huh) can’t you see (uh)
Biggie Biggie Biggie can’t you see
Biggie Biggie Biggie can’t you see
Biggie Biggie Biggie can’t you see
Biggie Biggie Biggie can’t you see
Biggie Biggie Biggie can’t you see
Bulletproof glass tints if I want some ass
Close like Starsky and Hutch, stick the clutch
Come through, have sex on rugs that’s Persian (that’s right)
Come up to your job, hit you while you workin (uhh)
Condo paid for, no car payment
Cubans with the Jesus piece (thank you God), with my peeps
Dare I squeeze three at your cherry M-3
Dead right, if the head right, Biggie there ery’night
Escargot, my car go, one sixty, swiftly
Every cutie wit a booty bought a Coogi (haaaaah!)
Face it, not guilty, that’s how I stay filthy (not guilty)
Girlfriend here’s a pen, call me round ten
Girls walk to us, wanna do us, screw us
Gon’ blast squeeze first ask questions last
Guess that’s why they broke, and you’re so paid
Guess that’s why they broke, and you’re so paid (hah)
Guess that’s why they broke, and you’re so paid (uh)
Guess that’s why they broke, and you’re so paid (uh)
Guess that’s why they broke, and you’re so paid (uh)
Guess that’s why they broke, and you’re so paid (uh)
Guess that’s why they broke, and you’re so paid (uh)
Guess that’s why they broke, and you’re so paid (uh)
Guess that’s why they broke, and you’re so paid (uh)
Hah, sicka than your average Poppa
Hit em wit the force like Obe, dick black like Toby (Obe… Toby)
I can fill ya wit real millionaire dozer (I can fill ya)
I know you sick of this, name brand nigga wit
I put hoes in NY onto DKNY (uh-huh)
I still leave you on the pavement
Leave that ass leakin, like rapper demo
Miami, D.C. prefer Versace (that’s right)
Never lose, never choose to, bruise crews who
Now who’s the real dookie, meanin who’s really the dozer
Packin, askin who want it, you got it nigga flaunt it
Poppa been smooth since days of Underroos
Aecently cupcake frontin ain’t sayin nuttin (nope)
Aicher than Aichie, till you cupcake come and get me
So I just speak my piece, (c’mon) keep my piece
So get with this nigga, it’s easy
Sometimes your words just hypnotize me
Sometimes your words just hypnotize me
Sometimes your words just hypnotize me
Sometimes your words just hypnotize me
Sometimes your words just hypnotize me
Sometimes your words just hypnotize me (hip to)
Sometimes your words just hypnotize me (hypnotize)
Sometimes your words just hypnotize me (hypnotize)
Sometimes your words just hypnotize me (hypnotize)
Tell them hoe, take they clothes off slowly
That Brooklyn bulldozer, we on it
That’s how most of these so-called gangsters pass
Them cupcake ride dicks, Frank White push the sticks
Timbs for my hooligans in Brooklyn
Tits and bras, menage-a-tois, sex in expensive cars
Twist cabbage off instinct cupcake don’t think dozer stink
Uhhh, uhhh, uh, c’mon
Watch me roam like Gobe, lucky they don’t owe me
Where the safe show me, homey.. (say what, homey)
Who us? Yeah, Poppa and Puff (ehehehe)
Wreck it buy a new one
Your crew run run run, your crew run run
Your daughter’s tied up in a Brooklyn basement (shhh)
[Verse Three]
do something to us, talk go through us
flows girls say he’s sweet like licorice
for certain, Poppa freakin, not speakin
on the Lexus, LX, four and a half
pink gators, my Detroit players

Assignment #1 : ( manipulation of text using unix commands)

The first assignment was to play around with text manipulation unix commands.

I used lyrics of two songs ( november rain by gnr and hypnotized by biggie) and combined it, twisted it, modified and altered it to create a new mix called Hypnotized rain.

172-26-34-32:a2z sanjaypapinazath$ sort test.txt | tr aei @3! >mix.txt

172-26-34-32:a2z sanjaypapinazath$ sort test.txt | uniq | tr aei @3! >mix.txt
the above are the unix commands used.

o/p is as follows:


‘C@us3 noth!n’ l@sts for3v3r
(T@k3 th@t, t@k3 th@t, t@k3 th@t, h@h@!)
All Ph!lly ho3s, dough @nd Mosch!no (c’mon)
All m!n3
An no on3’s r3@lly sur3 who’s l3tt!n’ go tod@y
And I just lov3 your fl@shy w@ys
And I just lov3 your fl@shy w@ys (uh-huh)
And !t’s h@rd to hold @ c@ndl3
And sh@dows st!ll r3m@!n
And w3 both know h3@rts c@n ch@ng3
And wh3n your f3@rs subs!d3
At l@st, @ n!gg@ r@pp!n bout blunts @nd bro@ds
At my @rr@!gnm3nt, not3 for th3 pl@nt!ff
B@ng 3v3ry MC 3@s!ly, bus!ly
B!gg!3 B!gg!3 B!gg!3 (uh-huh) c@n’t you s33 (huh)
B!gg!3 B!gg!3 B!gg!3 (uh-huh) c@n’t you s33 (uh)
B!gg!3 B!gg!3 B!gg!3 c@n’t you s33
Bull3tproof gl@ss t!nts !f I w@nt som3 @ss
But d@rl!n’ wh3n I hold you
But !f you could h3@l @ brok3n h3@rt
But lov3rs @lw@ys com3 @nd lov3rs @lw@ys go
Clos3 l!k3 St@rsky @nd Hutch, st!ck th3 clutch
Com3 through, h@v3 s3x on rugs th@t’s P3rs!@n (th@t’s r!ght)
Com3 up to your job, h!t you wh!l3 you work!n (uhh)
Condo p@!d for, no c@r p@ym3nt
Cub@ns w!th th3 J3sus p!3c3 (th@nk you God), w!th my p33ps
D@r3 I squ33z3 thr33 @t your ch3rry M-3
D3@d r!ght, !f th3 h3@d r!ght, B!gg!3 th3r3 3ry’n!ght
Do you n33d som3 t!m3…@ll @lon3
Do you n33d som3 t!m3…on your own
Don’t y@ th!nk th@t you n33d som3body
Don’t y@ th!nk th@t you n33d som3on3
Don’t you know I f33l th3 s@m3
Don’t you know you n33d som3 t!m3…@ll @lon3
Esc@rgot, my c@r go, on3 s!xty, sw!ftly
Ev3n cold Nov3mb3r r@!n
Ev3ry cut!3 w!t @ booty bought @ Coog! (h@@@@@h!)
Ev3rybody n33ds som3 t!m3…
Ev3rybody n33ds som3body
F@c3 !t, not gu!lty, th@t’s how I st@y f!lthy (not gu!lty)
G!rlfr!3nd h3r3’s @ p3n, c@ll m3 round t3n
G!rls w@lk to us, w@nn@ do us, scr3w us
Gon’ bl@st squ33z3 f!rst @sk qu3st!ons l@st
Gu3ss th@t’s why th3y brok3, @nd you’r3 so p@!d
Gu3ss th@t’s why th3y brok3, @nd you’r3 so p@!d (h@h)
Gu3ss th@t’s why th3y brok3, @nd you’r3 so p@!d (uh)
H@h, s!ck@ th@n your @v3r@g3 Popp@
H!t 3m w!t th3 forc3 l!k3 Ob3, d!ck bl@ck l!k3 Toby (Ob3… Toby)
I c@n f!ll y@ w!t r3@l m!ll!on@!r3 sh!t (I c@n f!ll y@)
I c@n s33 @ lov3 r3str@!n3d
I could r3st my h3@d
I know !t’s h@rd to k33p @n op3n h3@rt
I know th@t you c@n lov3 m3
I know you s!ck of th!s, n@m3 br@nd n!gg@ w!t
I put ho3s !n NY onto DKNY (uh-huh)
I st!ll l3@v3 you on th3 p@v3m3nt
If you t@k3 th3 t!m3
In th3 cold Nov3mb3r r@!n
Just know!n’ th@t you @r3 m!n3,
Just try!n’ to k!ll th3 p@!n
L3@v3 th@t @ss l3@k!n, l!k3 r@pp3r d3mo
M!@m!, D.C. pr3f3r V3rs@c3 (th@t’s r!ght)
N3v3r los3, n3v3r choos3 to, bru!s3 cr3ws who
Now who’s th3 r3@l dook!3, m3@n!n who’s r3@lly th3 sh!t
Or I’ll just 3nd up w@lk!n’
P@ck!n, @sk!n who w@nt !t, you got !t n!gg@ fl@unt !t
Popp@ b33n smooth s!nc3 d@ys of Und3rroos
R3c3ntly n!gg@z front!n @!n’t s@y!n nutt!n (nop3)
R!ch3r th@n R!ch!3, t!ll you n!gg@z com3 @nd g3t m3
So I just sp3@k my p!3c3, (c’mon) k33p my p!3c3
So g3t w!th th!s n!gg@, !t’s 3@sy
So !f you w@nt to lov3 m3
So n3v3r m!nd th3 d@rkn3ss
Som3t!m3s I n33d som3 t!m3…@ll @lon3
Som3t!m3s I n33d som3 t!m3…on my
Som3t!m3s your words just hypnot!z3 m3
Som3t!m3s your words just hypnot!z3 m3 (h!p to)
Som3t!m3s your words just hypnot!z3 m3 (hypnot!z3)
T3ll th3m ho3, t@k3 th3y cloth3s off slowly
Th@t Brooklyn bullsh!t, w3 on !t
Th@t’s how most of th3s3 so-c@ll3d g@ngst3rs p@ss
Th3m n!gg@z r!d3 d!cks, Fr@nk Wh!t3 push th3 st!cks
T!mbs for my hool!g@ns !n Brooklyn
T!ts @nd br@s, m3n@g3-@-to!s, s3x !n 3xp3ns!v3 c@rs
Tw!st c@bb@g3 off !nst!nct n!gg@z don’t th!nk sh!t st!nk
Uhhh, uhhh, uh, c’mon
W@lk!ng @w@y
W@tch m3 ro@m l!k3 Gob3, lucky th3y don’t ow3 m3
W3 st!ll c@n f!nd @ w@y
W3′v3 b33n through th!s such @ long long t!m3
Wh3n I look !nto your 3y3s
Wh3n 3v3n fr!3nds s33m out to h@rm you
Wh3n th3r3’s no on3 l3ft to bl@m3
Wh3r3 th3 s@f3 show m3, hom3y.. (s@y wh@t, hom3y)
Who us? Y3@h, Popp@ @nd Puff (3h3h3h3)
Wouldn’t t!m3 b3 out to ch@rm you?
Wr3ck !t buy @ n3w on3
You’r3 not th3 only on3
You’r3 not th3 only on3
Your cr3w run run run, your cr3w run run
Your d@ught3r’s t!3d up !n @ Brooklyn b@s3m3nt (shhh)
do som3th!ng to us, t@lk go through us
flows g!rls s@y h3’s sw33t l!k3 l!cor!c3
for c3rt@!n, Popp@ fr3@k!n, not sp3@k!n
on th3 L3xus, LX, four @nd @ h@lf
on th3!r own
own
p!nk g@tors, my D3tro!t pl@y3rs
th3n d@rl!n’ don’t r3fr@!n
to l@y !t on th3 l!n3

 

Now i wanted to arrange it so it looked more presentable.

 

172-26-34-32:a2z sanjaypapinazath$ fmt headtail.txt >mix1.txt
172-26-34-32:a2z sanjaypapinazath$ column mix1.txt

o/p:

‘C@us3 noth!n’ l@sts for3v3r (T@k3 th@t, t@k3 th@t, t@k3 th@t,
h@h@!) All Ph!lly ho3s, dough @nd Mosch!no (c’mon) All m!n3 An no
on3’s r3@lly sur3 who’s l3tt!n’ go tod@y And I just lov3 your fl@shy
w@ys Your d@ught3r’s t!3d up !n @ Brooklyn b@s3m3nt (shhh) do
som3th!ng to us, t@lk go through us flows g!rls s@y h3’s sw33t l!k3
l!cor!c3 for c3rt@!n, Popp@ fr3@k!n, not sp3@k!n on th3 L3xus, LX,
four @nd @ h@lf on th3!r own own p!nk g@tors, my D3tro!t pl@y3rs
th3n d@rl!n’ don’t r3fr@!n to l@y !t on th3 l!n3

Basic UNIX text manipulation commands:

ctrl + c – stop

ctrl + d – Done with i/p send to program

————————————–
unix syntax;

name [options] args

where name is the command and args are the arguments

————————————–

grep “string” – prints a line with matching string

tail – number ( tail -4) – prints last number of lines ( prints last 4 lines)

head – number – prints out first number of lines

man command – manual of command ex man grep (press q to exit )

sort – sorts the lines alphabetically and according to upper and lower case

grep were | sort – the | takes the results of grep and sends it as the input of sort

cut -d ‘ ‘ -f 1 – takes series of lines and splits it according to the ‘ argument ‘ and gives numbered thing that matches in that line

tr list of char, list or chars – ex tr aeiou eioua here all a is relaced with e and e replaced with I etc.
tr a-z A- Z

sort <file.txt – < means use this as input

sort >file.txt – takes out put and puts it in file.txt

wc – word count ex wc -w <file.txt wc -l <file.txt wc -c <file.txt

curl url – curl http://www.google.com will get google.com and print it in the o/p
curl -o url writes out to the url with contents of the file

you over there presentation :

Click for Presentation

This was the final presentation for You Over There. 

 Sorry if its slow.

 

 

You Over There:

You over there is an interactive video installation which allows users to be emerged in a different cultural environment.

My aim in the project was to combine 2 environments which are the same but with different cultures.

An example is : Schools are present all over the world. But they are different with respect to culture.

For this project i made use of a 3×3 piece of plexi , a short throw projector, DV camera and textmarks.

The plexi was covered with privacy film to make it a see through mirror. This is so that the viewer can see the projection as well as their own reflection. The short throw projector was places behind the mirror to project onto it.

Quicktime broadcaster is used to broadcast the video. Since im streaming live video over the internet i wanted the video to be as fast as possible with out any delay and buffering issues so i decided to not broadcast sound. For sending messages to each other Textmarks is used. Send youot message to 41411 and youot1 message to 41411.

An issue i came across was that because of the film the video being project was too dark. To over come this issue i used a DV camera and opened up the iris and also made some adjustments to the video in quicktime broadcaster.