Crawl my website and produce an "index" of the pages, lectures, and images that you find there. Web pages have the extensions .htm and .html, images are one of .gif, .jpg, and .png, and lectures are .ppt or .pptx.
When I refer to the "name" of a file, I mean everything after the last slash in the URL. When I refer to "the URL", I mean everything after the http:// -- in the case of a relative URL, this means reconstructing the absolute URL.
The absolute URL can be formed by taking URL of the page you are at, removing everything after the last slash (if there is anything after the last slash), and appending the relative URL to it.
Here's a suggested program structure that I think will work fairly well. Feel free to deviate from it, as long as you are using Actors in a reasonably appropriate fashion.
Manager object06-methods.ppt), the digits and hyphen should be omitted from the name, but not from the complete URL.One actor should collect URLs of all the images that are reported to it. Since images are often reused, only one image with a given name should be kept. You do not need to check if images are the "same."
One actor should collect URLs of all the lectures that are reported to it. I usually prefix each lecture with one or two digits and a hyphen. Since I rearrange lectures each year, the prefix should be ignored when comparing the names of lectures to see whether they are the same. Since I reuse lectures but also frequently update them, the most recent lecture with a given name should be the one whose URL is kept. (Since most of my URLs contain a year number, you can use this.)
One actor should collect URLs of the web pages that are reported to it. The following URLs should be discarded:
# character; these are links into the middle of some page.? character; these are searches... or /); these are links to somewhere on this site, but not in this subdirectory.Every time a new web page is encountered, a new actor should be created to process it.
Processing consists of
You probably need to check for cycles in the links, as these could cause your program to run forever. Since you will be discarding URLs that begin with .., this will prevent many, but not all, cycles.
The point of this assignment is to learn to use Actors (and to use them appropriately). The above structure is basically a Map-Reduce style structure, and I think it should work out okay; but if you think there's a better way to use lots of Actors, go ahead and do things differently.
However you structure your program, the output should be one file, containing three clearly labeled sections, for pages, lectures, and images. Each section should be alphabetical by name (not by URL), with no duplicate names.
A very brief introduction to HTMLHTML is what web pages are written in. HTML contains elements; each element consists of a tag with zero or more attributes, enclosed in angle brackets. Tags and attributes are not case sensitive. Attributes may occur in any order. An attribute consists of a name, an equals sign, and a value. The value is supposed to be in quotes, either single or double, but often isn't. When a value isn't in quotes, it is terminated by a blank or by the closing angle bracket. The relevant tags and attributes are:
If you need to know more, visit w3schools. |
I believe the following code bits to be correct, as far as they go; but use at your own risk.
| Reading from a URL | val url = new java.net.URL(from) |
| Writing to a file | val file = new java.io.File(to) |
| Choosing a directory | val chooser = new FileChooser() |
| Creating a directory | val newDirectory = new File(fullPathName) |
| Regular expression to match a link to an HTML page | val HtmlPattern = |
| Regular expression to match a link to an image | val ImgPattern = |
| Using the regular expression to get the tag and URL. | string match { |
The program should work as specified.
The first Scala assignment encouraged you to do things "the Scala way" by avoiding vars, not using a loop where a recursion would do, not using a recursion where a call to a higher-order function would do, using pattern matching, etc.
You should continue to try to do things the Scala way. You may use vars, while loops, etc., when they are appropriate, but also use the Scala features. I reserve the right to take off significant points if it looks like you made no effort whatsoever to write in Scala, rather than writing a Java program using Scala syntax. I will probably not ever do this, so there's no need to be paranoid, but I reserve that right.