Using WordLib to Analyze Papers
We'll create an application to help teachers target weak descriptions by importing student compositions and then displaying a warning if the word "nice" is used. (Some instructors adopt an unfriendly attitude toward this particular word in the hopes that more descriptive terms will fill its place.) OpenOffice is freely available, so I'll use it for the demonstration.
As with any project, first create a new stack. (File menu: New Mainstack.) Then drag in a scrolling text field and a button from the Tool palette onto your stack.
Let's name the field "Document" and the button "Import" using the Property Inspector. (While you're at it, make sure the "Fixed line height" property checkbox is unchecked for your text field in the Inspector.)
After a little arrangement, you'll have something similar to this:
Edit the script of the "Import" button, and use the importDocumentToField command to specify input to your text field:
That's all there is to it; WordLib automatically handles the details of prompting the user to choose a document file and placing content in the field. (Of course, there are advanced options for power users who want to handle these steps themselves.)
We could try import now, but while we're editing this script, why don't we go ahead and add another two statements for the analysis requirement? You can use in to search for the uncreative word and the hilite property to turn on a checkbox and alert the teacher if necessary:
(You'll notice that I'm referring to a "Nice" button that we haven't added to the stack yet, but RunRev is flexible; if you have a good idea for an extra control while you're writing a script, you can go ahead and write about it first and then add it before executing your code.)
Hit the Enter key twice to compile your script and close the editor, then drag in a checkbox and name it "Nice" in the Property Inspector. Right under the name property is a label property, and you may want to give your checkbox a more descriptive label, as I did:
Now the features of this simple application are complete. However, we still need to make sure your stack can access the WordLib library. Libraries are collections of code, and RunRev provides an elegant method to load them. For this, you can use the start using command, and a great place for it would be a preOpenStack handler in the card script (Object menu: Card Script) since preOpenStack is sent to the first card of a stack when it opens.
We also need to show RunRev where the WordLib library file is located. I'll assume that we are placing the wordlib.rev file in the same folder as our stack:
So, give your stack a name (Object menu: Stack Inspector) and then save it (File menu: Save) to your computer. Be sure to place the wordlib.rev file in the same folder.
This takes care of loading the library each time the stack opens, but this time, since the stack is already open and we need to load the library right now, I'm going to issue a preOpenStack message by right-clicking on an empty spot on the stack window and choosing the appropriate item in the contextual menu:
Now we simply need a couple of test documents, preferably one that contains "nice" and one that does not. I'm going to use OpenOffice to create mine, and I'll add some text styles and an image to test WordLib's import capabilities.
We're all ready for the test. Switch to the Run (browse) tool in the RunRev Tool palette, click the Import button to open a document, and keep an eye on the warning checkbox!
Note: The characters "nice" are not too common within larger unrelated words, so our current simple search might suffice for in-house purposes, but for a published application we would definitely want to improve the accuracy of the search by specifying that a match must contain the full word "nice" (or a word beginning with it, if desired) while ignoring any punctuation. This could be accomplished by any of several methods, including the use of regular expressions via the matchText function.
WordLib excels at importing MS Word 2007+ (.docx) and OpenOffice (.odt) files with extensive formatting, and also opens legacy MS Word (.doc) files.
If you enjoy importing word processing documents with WordLib, be ready for similar ease of use and powerful capabilities in the upcoming products WordReport (report creation using styled templates) and WordOut (document export)!
WordLib is available through RevSelect here.