********** NOTE CHANGE OF MIDTERM DATE ON COURSE PAGE **********
I don't want to lose momentum with Ruby, so will ask you to complete a couple of problems.
My overall goal on the Ruby side is to get to a place where we can explore RK's conjecture that the Internet is a vast knowledge base that some strong AI could use. We won't be attempting to build a strong AI in class. More like a really wimpy AI. But still one that accesses information on the web.
To do this, we will need to do several things. First, we will need to get information off of the web. This is not too difficult in Ruby. Second, we will need to take the raw information we get and break it into pieces. This is also not too difficult in Ruby. Third, we need to take the pieces and make sense of it. This is way hard in any language. It's really what makes an AI "strong". We will work mainly with steps one and two for now.
Below is some code that pulls some information off the web. In particular, it accesses a page on the web and puts it in a Ruby string.
Copy the code above into your playground (fxri). Now let's try it out. Type this in the playground (or copy and paste it from this page):
What you see is the raw html for the homework 4 page. Much of the web is written in html. So if we want to use the web, we will have to figure out how to deal with html. And to do that, we will have to learn some ways to take a large, ugly string like what is in h, and break it into digestible pieces. Ruby has a large number of methods for manipulating strings, so it is a good fit for our problem of pulling stuff off the web and then digesting it. For instance, copy the definition below into your playground:
The first line makes use of a "regular expression": the text between the two forward slashes, i.e., /.../m. This is a pattern that can match against a string. The pattern between the slashes says find all occurences in raw_html that start with <xmp id='rules'> and end with <xmp>. The (.*) matches everything in between. The m at the end says search over multiple lines.
The next line makes use of a "dot method". It has the form of a variable name followed by a dot (period), followed be a method name. You should read this as "apply the method delete to the data in the variable rules." Given that the variable rules holds an html string, the dot-method delete will remove all tabs (denoted by \t) from that string.
Let's see if it works. Type/copy the code below into the playground and see what you get.
Cool, huh. You've managed to pull out the raw rules from the giant ugly string. (Note that the \n represents a newline/enter/carriage-return.) Eventually we will see if we can stick the rules in the cloud. Kind of our first wimpy AI: a program that can find rules on the web and then download them to its own "brain".
Stay in the playground to answer the following questions. Your turn-in will be the results from the playground. You can use control-c to copy from fxri and then paste that into a text document that you turn-in as homework.
These questions assume you have a variable r that holds the string shown above. You can test this out by typing r enter/return and checking you get the string with rules.
When you get the right answer, turn-in your just_rule.each_line code.
In summary, you have two turn-ins which you should perfect in the playground and then copy and paste the code into a text document and turn-in.
For the curious, if I were going to follow our examples above to conclusion, I would work on the idea that I could build up the $cloud container by something along the lines of: