“Have you seen my wig around?”

Jane Says

This week’s A2Z assignment was as follows:

Make a program that creatively transforms or performs analysis on a text using regular expressions. The program should take its input from the keyboard and send its to the screen (or redirect to/from a file). Your program might (a) filter lines from the input, based on whether they match a pattern; (b) match and display certain portions of each line; (c) replace certain portions of each line with new text; or (d) any combination of the above.

Sample ideas: Replace all words in a text of a certain length with a random word; find telephone numbers or e-mail addresses in a text; locate words within a word list that will have a certain score in Scrabble; etc.

Bonus challenge 1: Use one or more features of regular expression syntax that we didn’t discuss in class. Reference here.

Bonus challenge 2: Use one or more features of the Pattern or Matcher class that we didn’t discuss in class. Of particular interest: regex flags (CASE_INSENSITIVE, MULTILINE), “back references” in replaceAll. Matcher class reference here.

So, what I made is a program that tries to find the proper names in the input text (my preferred input being the first scene of Pride and Prejudice) and replace them with names of people in our class. For my purposes, a proper name is any capitalized word that (a) follows an honorific, such as Mr., Mrs., Sir, Lady, or Miss, or (b) does not immediately follow a carriage return or chunk of terminal punctuation (i.e., a period, exclamation point, or question mark, with or without a closing quotation mark thereafter), and (c) is neither a day of the week, a month of the year, nor the name of a holiday (though the only holiday it’s really looking for is Michaelmas, as that’s what appears in my P&P extract).

I tried for hours to do this in a compact way, by looking for the absence of certain words or characters (terminal punctuation, honorifics, days of the week, holidays) combined with the presence of other patterns, but it just would not fly. So the result requires a lot of intermediate steps, to avoid changing words that have been identified as not likely to be names. In a vain attempt to make testing my regular expressions quicker, I worked them out in BBEdit first, using the grep option in the search and replace panel. Saved me from having to recompile the thing fifty thousand times. And the expressions worked in BBEdit, for the most part. They do not work so well translated into Java, unfortunately—the success rate at finding names is much lower, and after ten straight hours, I just didn’t have the patience to troubleshoot it any more. But these glitches just make the results more funny, which is, of course, the point.

So, here is the code:

[java]import java.util.regex.*;
import com.decontextualize.a2z.TextFilter;

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

private String search1 = “(Mr\\.|Mrs\\.|Lord|Lady|Sir) ([A-Z]\\w+)”;
private String replace1 = “##NAME##”;

private String search2 = “(\\.” |\\?” |!” |\\. |\\? |! |\\r|\\r“)([A-Z]\\w+)”;

private String search3 = “( |“|\\r)(Mr\\.|Mrs\\.|Lord|Lady|Sir|Miss|Monday|Tuesday|Wednesday|Friday|Saturday|Sunday|January|February|March|April|May|June|July|August|September|October|November|December|Michaelmas)”;

private String search4 = “( |“)([A-Z][a-z]+)”;

private String [] class_names = new String [] {
“Adam”, “Alejandro”, “Andrew”, “Bryan”, “Caroline”, “Dimitris”, “Jonathan”, “Joseph”, “Martin”, “Michael”, “Ozge”, “Sanjay”, “Steven” };
public void begin()
{
println(“* * *”);
}

public void eachLine(String line)
{
String line_new;

Pattern p1 = Pattern.compile(search1);
Matcher m1 = p1.matcher(line);
if (m1.find())
{
line = line.replaceAll(m1.group(2), replace1);
}

line_new = line;

Pattern p2 = Pattern.compile(search2);
Matcher m2 = p2.matcher(line_new);
if (m2.find())
{
line_new = line_new.replaceAll(m2.group(2), “##” + m2.group(2) + “##”);
}

Pattern p3 = Pattern.compile(search3);
Matcher m3 = p3.matcher(line_new);
if (m3.find())
{
line_new = line_new.replaceAll(m3.group(2), “##” + m3.group(2) + “##”);
}

Pattern p4 = Pattern.compile(search4);
Matcher m4 = p4.matcher(line_new);
if (m4.find())
{
line_new = line_new.replaceAll(m4.group(2), “##NAME##”);
}

line_new = line_new.replace( “##NAME##”, class_names[(int)(Math.random() * 13)] );

line_new = line_new.replace( “##”, “” );

println(“\t” + line_new);
} // end eachLine(String line)

public void end()
{
println(“* * *”);
}

} // end RegexNames extends TextFilter[/java]

And here is the output (you can find the original text at Project Gutenberg):

* * *
     It is a truth universally acknowledged, that a single man in possession of a large fortune must be in want of a wife.
     However little known the feelings or views of such a man may be on his first entering a neighbourhood, this truth is so well fixed in the minds of the surrounding families, that he is considered the rightful property of someone or other of their daughters.
     “Adam dear Mr. Adam,” said his lady to him one day, “have you heard that Netherfield Park is let at last?”
     Mr. Bryan replied that he had not.
     “Steven it is, returned she; ”for Mrs. Steven has just been here, and she told me all about it.
     Mr. Michael made no answer.
     “Dimitris you not want to know who has taken it?” cried his wife impatiently.
     “YOU want to tell me, and I have no objection to hearing it.”
     This was invitation enough.
     “Steven, my dear, you must know, Mrs. Steven says that Netherfield is taken by a young man of large fortune from the north of England; that he came down on Monday in a chaise and four to see the place, and was so much delighted with it, that he agreed with Mr. Morris immediately; that he is to take possession before Michaelmas, and some of his servants are to be in the house by the end of next week.”
     “Joseph is his name?”
     “Adam.”
     “Dimitris he married or single?”
     “Bryan! Single, my dear, to be sure! A single man of large fortune; four or five thousand a year. What a fine thing for our girls!”
     “How so? How can it affect them?”
     “Bryan dear Mr. Bryan,” replied his wife, “how can you be so tiresome! You must know that I am thinking of his marrying one of them.”
     “Ozge that his design in settling here?”
     “Caroline! Nonsense, how can you talk so! But it is very likely that he MAY fall in love with one of them, and therefore you must visit him as soon as he comes.”
     “I see no occasion for that. You and the girls may go, or you may send them by themselves, which perhaps will be still better, for as you are as handsome as any of them, Mr. Michael may like you the best of the party.”
     “Michael dear, you flatter me. I certainly HAVE had my share of beauty, but I do not pretend to be anything extraordinary now. When a woman has five grown-up daughters, she ought to give over thinking of her own beauty.”
     “Jonathan such cases, a woman has not often much beauty to think of.”
     “Michael, my dear, you must indeed go and see Mr. Michael when he comes into the neighbourhood.”
     “Steven is more than I engage for, I assure you.”
     “Jonathan consider your daughters. Only think what an establishment it would be for one of them. Sir Jonathan and Lady Lucas are determined to go, merely on that account, for in general, you know, they visit no newcomers. Indeed you must go, for it will be impossible for US to visit him if you do not.”
     “Sanjay are over-scrupulous, surely. I dare say Mr. Sanjay will be very glad to see you; and I will send a few lines by you to assure him of my hearty consent to his marrying whichever he chooses of the girls; though I must throw in a good word for my little Lizzy.”
     “I desire you will do no such thing. Lizzy is not a bit better than the others; and I am sure she is not half so handsome as Michael, nor half so good-humoured as Lydia. But you are always giving HER the preference.”
     “Andrew have none of them much to recommend them,” replied he; “they are all silly and ignorant like other girls; but Lizzy has something more of quickness than her sisters.”
     “Mr. Bryan, how CAN you abuse your own children in such a way? You take delight in vexing me. You have no compassion for my poor nerves.”
     “Caroline mistake me, my dear. I have a high respect for your nerves. They are my old friends. I have heard you mention them with consideration these last twenty years at least.”
     Mr. Dimitris was so odd a mixture of quick parts, sarcastic humour, reserve, and caprice, that the experience of three-and- twenty years had been insufficient to make his wife understand his character. HER mind was less difficult to develop. Dimitris was a woman of mean understanding, little information, and uncertain temper. When she was discontented, she fancied herself nervous. The business of her life was to get her daughters married; its solace was visiting and news.
* * *

Studio interface ideas

materials

This week’s assignment for 1′, 2′, 10′ was a longie, and it stumped the hell out of me and, apparently, a couple of other people:

Like I’ve said in class before, the game changer for the computer industry was Apple’s innovation of WIMP (windows, icons, menus, and pointing devices) – Apple’s interface became popular because it was immediately intuitive and simple to use. People recognized a ‘desktop’ as a, well, a ‘desktop’. Folders as folders. A trash can as a trash can. etc. This hasn’t changed in 25 years and there are currently discussions to see if it should. So, our homework is to explore, research and document 5 new User Interface experiences that we could apply to a computer, from the real world. Examples that exist today and are changing this model are the multi touch ‘stretch’ for enlarging images, a play button for video, a trash can for trash etc.

We should think about new ways to say things in an online environment. How do you tell someone they are near the end of an article, in a non-digital setting you would could glance to the end, but digitally you have numbers like PAGE 1 of 5 etc. Is there a better way to make the show this? What about rethinking the desktop? Could it be multi-dimential? Maybe it becomes 3D? Maybe it becomes like the iPhone and it’s just icons of apps and only one thing can be open at a time… maybe not. The folder concept worked for small pieces of data, but now it’s not a great interface, the more data we create, the more folders we need and sub folders etc. What about a music player UI? Or a book interface? IMPORTANT: There are two things to think about here, there is the design / interface, and then there is the modality. An example is. The trashcan represents the Interface, but dropping trash into it represents the action.

Start to think about ways that we can make the exprience better than exists today. Please come with 5 examples of these and a brief description of how they would work. And try to push the boundaries. You can write them out as a description, you can sketch them out on your computer. You can use crayolas, pencils, markers or candle wax, but make sure you put effort into showing how it will work. And bring your research to discuss in class.

I scribbled down a bunch of lists of real-life contexts that might supply metaphors for a computer interface—kitchen, farmhouse, library, city—all of which seemed ridiculous. What’s wrong with the desktop metaphor that we have? Besides, you know, the fact that I’ve never been much of a desk-user, and why are those things called “windows,” and what’s with “icons,” and so forth. If you were to make a user interface based on where and how I actually work, it would have to include elements such as “couch,” “pile,” “bookalanche,” and “crumbs,” and the OS would have to be called something like “putter” or “noodle.” Probably not so useful to other people.

So, instead, I was thinking about what kind of interface might make more sense to my mom, who has been using computers for about twenty-five years and Macs for almost ten, and who does not understand what or where her “desktop” is, nor the difference between an application, a window, and the operating system itself. She’s an artist, so I thought a studio metaphor might make more sense. But also, inverting the nesting metaphor of the whole OS might help. That is, why does she have to know which application to use, and then open a file within that? Why can’t she just have stuff that she’s working on, and then use tools to modify it? So the “applications” become “tools,” and the “document” becomes a “work” made of materials and a process.

When you want to make a new work, you go to the materials shelf and choose a basic substance to start with—2D (e.g., paper, canvas) or 3D (a blob)? You drag it onto the easel, of which you can have more than one. Then you can select some properties of that material. Size? Color? How rigid or stretchy do you want it to be? How translucent? How smooth? Many of these would probably best be controlled using slider, though for something like texture, you’d probably want a swatch.

Choose a tool, such as a brush or roller, or type from a California job case; assign a color; and and start doing stuff to your material. To pick a color, you would have a palette and a mixing area, so that you could mix or dilute colors. The resulting mixtures could be added to a global palette or discarded. Use your 3D mouse to shape it. Pick another material off the shelf and attach it. Choose an (optional) adhesive (which could include staples, sewing) and the attachment point or surface. How hard are they pressed together—like, does one dent the other? You can type on any surface of an object. You can drag one material against another to transfer properties such as color or texture. You can fold the material by marking a scoring line and dragging one side over the other. You can flip a piece of 2D material over and work on the back.

When you’re done with a work, you can stick it in a drawer. Each work would be stored as a recording of its process of construction. At any time, you could select an existing work from a drawer and use a slider to move back along a timeline, if you want to undo something. To repeat an operation, you could select a segment of the timeline, copy, and paste it to the same work or to any other work.

Repaving the DMV

orange Ghia

Our first homework assignment for Nick Bilton’s 1′, 2′, 10′ class was to redesign the front page on the New York State Department of Motor Vehicles site. Not a difficult thing to improve upon, but still hard to get right. For me the assignment was complicated by the fact that I don’t know shit about what people want from the DMV site, since I don’t drive (though I do have a license, to the astonishment of all and sundry; my ongoing act of service to humanity is to abstain from using it). So for inspiration, I looked at some DMV sites from other states, as well as few government sites from abroad:

And then, after working on my mockup for about four hours, I had the delightful experience of having Illustrator crash, taking my unsaved document with it. Joy! So then I got to do it again, this time in InDesign—which only took about thirty minutes, because I’m so much more ept with ID than I am with AI.

Whine, whine. The result is as follows (click to see a PDF at actual resolution):

DMV redesign

I focused on getting rid of most of the graphic crap, moving some obviously unimportant information out of the way, and making the bulleted lists easier to read. There’s still way too much text on the page, but without knowing what people go there to find out, I didn’t think I was qualified to cut any of it.

Photo: ghia by Ryan Carver; some rights reserved.

India’s ITP blog