求救 关于我的一篇作业问题!
rooneypan
|
1#
rooneypan 发表于 2006-04-03 21:06
求救 关于我的一篇作业问题!
求救 关于我的一篇作业问题!
Important Notes Make sure you do this years version of this Assignment or Project, even if you have a version from last year! There are minor differences, and handing in last years assignment will get you zero marks! This year you must also include the completed plagiarism declaration form with your assignment: http://sciences.une.edu.au/f-sci/une_faculty_rules_index.asp The Faculty of Sciences plagiarism declaration form has been incorporated in both the web based assignment submission and the command line submit program. So now if you submit assignments by either of these methods, you will have to agree to the plagiarism declaration. Use the electronic submission facility only. No other submissions will be accepted. It is very easy (and foolproof) to submit directories rather than submit the assignment file by file. Here is the web page about using the submit facility: http://mcs.une.edu.au/dept/material/other/ugguide/Submitting_Assignments.html All programs must be compiled with the two pragmas use strict and use warnings. The latter replaces the ancient -w flag. Aims The aim of this project is to develop a useful little tool called ezpz. The tool is helpful in solving crosswords and other word puzzle, like the crickler http://www.washingtonpost.com/wp-srv/style/crosswords/crickler/crickler.html for example. As a starting point you should futz around with http://mcs.une.edu.au/~comp315/Lectures/Lecture_02/Examples/puzzle.pl on turing, or any Linux box, on windows you'll need to hard code in the dictionary, and probably steal it from turing. The tool we'll develop will be a little more robust and sophisticated than this example, but not too much. My solution is only 132 lines long, so we aren't dealing with a behemoth. The Tool ezpz In More Detail The ezpz tool will have three distinct modes. Normal mode, configuration mode, and addition mode. Usually one uses it in normal mode [comp315@serrano Project_01] ./ezpz Welcome to the ezpz word puzzle helper! spaces or _ match any letter . matches non-vowels , matches vowels (y, a semi-vowel, counts as a vowel) All searches are case insensitive. To use it in configuration mode one use the -c flag [comp315@serrano Project_01] ./ezpz -c Welcome to the ezpz word puzzle configurer! Currently you have 1 dictionary /usr/share/dict/words Feel free to specify a new dictionary (^D on Linux, ^Z on Windows, to exit): and to use it in addition mode one uses the -a flag [comp315@serrano Project_01] ./ezpz -a Feel free to add new words to you additions file (^D on Linux, ^Z on Windows, to exit): There is only one exception to this, when a user uses ezpz for the very first time it goes into configuration mode. Well see why in a moment. Lets look at the way it works first, then this feature will be easier to explain. The way ezpz works is that there are two files sitting in a directory in the user's home directory. The directory is called .ezpzrc, and the two files are dictionaries and additions. They are just ordinary plain text files. The first, dictionaries, contains a list of files to search, i.e. dictionaries. While the second, additions, just contains new words added by the user as they arise in the never ending puzzle solving endeavour. The reason that ezpz goes into configuration mode the very first time it is used by a user, is that this directory and the two files need to be made, and the user needs to supply at least one dictionary. Though if he doesn't add a dictionary the thing should still work in the manner described below. [comp315@serrano Project_01]$ rm -rf ~/.ezpzrc [comp315@serrano Project_01]$ ./ezpz Welcome to the ezpz word puzzle configurer! Currently you have 0 dictionaries On Linux /usr/share/dict/words is a good choice! Feel free to specify a new dictionary (^D on Linux, ^Z on Windows, to exit): The ezpz's Normal Mode OK so the gory implementation details are behind us, we can now just outline how the puppy should behave. The user should be able to specify a pattern, as described above. Spaces " " or undelines "_" match any letter, The full stop "." matches non-vowels, and the comma "," matches vowels (the letter "y", is a semi-vowel, and counts as a vowel). All searches are case insensitive. The search proceeds as follows. First the additions file is searched, then each file named in the dictionaries file. The results then should have any duplicates removed, and be sorted to be alphabetical. They should then be printed out. Welcome to the ezpz word puzzle helper! spaces or _ match any letter . matches non-vowels , matches vowels (y, a semi-vowel, counts as a vowel) All searches are case insensitive. aa_______ searching... Aaronical Aaronitic aardvarks aasvogels ...finished. Note that if the user didn't add a dictionary when the thing was fired up for the first time, searching will then boil down to looking in just the additions file. One last thing the file /usr/share/dict/words has gotten quite large recently. On turing it is a modest 400K. Whereas on my new laptop it is 4.8M. The ezpz's Configuraton Mode You use this mode to add dictionaries to your tool. [comp315@serrano Project_01] ./ezpz -c Welcome to the ezpz word puzzle configurer! Currently you have 0 dictionaries On Linux /usr/share/dict/words is a good choice! Feel free to specify a new dictionary (^D on Linux, ^Z on Windows, to exit): /usr/share/dict/words Great, I added /usr/share/dict/words to your list [comp315@serrano Project_01] It should do a modicum of checking: [comp315@serrano Project_01] ./ezpz -c Welcome to the ezpz word puzzle configurer! Currently you have 1 dictionary /usr/share/dict/words Feel free to specify a new dictionary (^D on Linux, ^Z on Windows, to exit): menoexistee Sorry menoexistee didn't look like an existing plain text file / Sorry / didn't look like an existing plain text file /usr/share/dict/words Great, I added /usr/share/dict/words to your list [comp315@serrano Project_01] The ezpz's Addition Mode The addition mode is pretty straightforward, it lets the user add words to the additions file. Thats it, not much to it at all. One last thing ezpz should complain if you try and use it in both addition and configuration mode at the same time. Hints & Suggestions perldoc -f grep may be advisable. I recommend that you use Getopt::Std module for parsing the command line switches that are used by ezpz. Try doing perldoc Getopt::Std, and then do some experiments. Even though it may take you longer in the short run, it will be better in the long run, and will maybe get you more marks. Platform independent file manipulation is possible using functions from the module File::Spec::Functions. Constants can be defined using the use constant pragma. The home directory of the user can be found in the environment. Google is your friend. Deleteing repetitions from a list is two very short lines of code. Try googling! Deliverables You should simply submit one single file: ezpz which contains the Perl code (make sure the file is executable before you submit it). |