Making Bush Speak Honestly
Using Regular Expressions and "replace word," I added a little phrase every time Bush says "I." There was one place where it didn't quite work but overall I think it was effective. Now Bush is being honest when he talks about himself. Here's the new text followed by the code:
Good afternoon. I, the worst President ever,'d like to, first, thank Prime Minister Olmert and President Abbas for their hospitality during my trip here to the Holy Land. We had very good meetings, and now is the time to make difficult choices.
I, the worst President ever, underscored to both Prime Minister Olmert and President Abbas that progress needs to be made on four parallel tracks. First, both sides need to fulfill their commitments under the road map. Second, the Palestinians need to build their economy and their political and security institutions. And to do that, they need the help of Israel, the region, and the international community. Third, I, the worst President ever, reiterate my appreciation for the Arab League peace initiative, and I, the worst President ever, call upon the Arab countries to reach out to Israel, a step that is long overdue.
In addition to these three tracks, both sides are getting down to the business of negotiating. I, the worst President ever, called upon both leaders to make sure their teams negotiate seriously, starting right now. I, the worst President ever, strongly supported the decision of the two leaders to continue their regular summit meetings, because they are the ones who can, and must, and -- I, the worst President ever, am convinced -- will lead.
I, the worst President ever, share with these two leaders the vision of two democratic states, Israel and Palestine, living side by side in peace and security. Both of these leaders believe that the outcome is in the interest of their peoples and are determined to arrive at a negotiated solution to achieve it.
The point of departure for permanent status negotiations to realize this vision seems clear: There should be an end to the occupation that began in 1967. The agreement must establish Palestine as a homeland for the Palestinian people, just as Israel is a homeland for the Jewish people. These negotiations must ensure that Israel has secure, recognized, and defensible borders. And they must ensure that the state of Palestine is viable, contiguous, sovereign, and independent.
It is vital that each side understands that satisfying the other's fundamental objectives is key to a successful agreement. Security for Israel and viability for the Palestinian state are in the mutual interests of both parties.
Achieving an agreement will require painful political concessions by both sides. While territory is an issue for both parties to decide, I, the worst President ever, believe that any peace agreement between them will require mutually agreed adjustments to the armistice lines of 1949 to reflect current realities and to ensure that the Palestinian state is viable and contiguous. I, the worst President ever, believe we need to look to the establishment of a Palestinian state and new international mechanisms, including compensation, to resolve the refugee issue.
I, the worst President ever, reaffirm to each leader that implementation of any agreement is subject to implementation of the road map. Neither party should undertake any activity that contravenes road map obligations or prejudices the final status negotiations. On the Israeli side that includes ending settlement expansion and removing unauthorized outposts. On the Palestinian side that includes confronting terrorists and dismantling terrorist infrastructure.
I, the worst President ever, know Jerusalem is a tough issue. Both sides have deeply felt political and religious concerns. I, the worst President ever, fully understand that finding a solution to this issue will be one of the most difficult challenges on the road to peace, but that is the road we have chosen to walk.
Security is fundamental. No agreement and no Palestinian state will be born of terror. I, the worst President ever, reaffirm America's steadfast commitment to Israel's security.
The establishment of the state of Palestine is long overdue. The Palestinian people deserve it. And it will enhance the stability of the region, and it will contribute to the security of the people of Israel. The peace agreement should happen, and can happen, by the end of this year. I, the worst President ever, know each leader shares that important goal, and I, the worst President ever, am committed to doing all I, the worst President ever, can to achieve it.
Thank you.
Code:
// Reverse Words
// Daniel Shiffman
// Programming from A to Z, Spring 2007
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.util.regex.*;
public class ReplaceWords3 {
public static void main (String[] args) throws IOException {
// Create an input stream and file channel
// Using first arguemnt as file name to read in
FileInputStream fis = new FileInputStream("Bushy.txt");
FileChannel fc = fis.getChannel();
// Read the contents of a file into a ByteBuffer
ByteBuffer bb = ByteBuffer.allocate((int)fc.size());
fc.read(bb);
fc.close();
// Convert ByteBuffer to one long String
String content = new String(bb.array());
// public static void main(String[] args) {
String regex = "\\bI\\b"; // Use any "non-word character" as a delimiter
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(content);
String output = m.replaceAll("I, the worst President ever,");
//System.out.println(input);
//System.out.println("running replace regex. . . ");
System.out.println(output);
// This line uses a regular expression which we haven't learned yet
// '\\b' means split the text along word boundaries
// We will cover this in more detail next week
//String[] words = content.split("\\b");
//System.out.println("Read " + words.length + " words from " + "Bushy.txt");
//StringBuffer reverse = new StringBuffer();
//for (int i = words.length-1; i >= 0; i--) {
// String word = words[i];
//reverse.append(word);
//}
// String output = reverse.toString();
// Create an output stream and file channel to write out a report
// (Also print out report to screen)
FileOutputStream fos = new FileOutputStream("ReplaceBushy3.txt");
FileChannel outfc = fos.getChannel();
// Convert content String into ByteBuffer and write out to file
bb = ByteBuffer.wrap(output.getBytes());
outfc.write(bb);
outfc.close();
System.out.println("Reversed text written to " + "ReplaceBushy3.txt");
}
}