Showing posts with label Language. Show all posts
Showing posts with label Language. Show all posts

Friday, July 17, 2009

Error Message Haikus

I received the following email, which made me smile:
Haiku poetry has strict construction rules. Each poem has only 3 lines and a total of 17 syllables:

  • five syllables in the first line,
  • seven in the second, 
  • five in the third.

Haikus are used to communicate a timeless message, often achieving a wistful, yearning and powerful insight through extreme brevity - the essence of Zen . . .


Your file was big.

It might be very useful.

But now it is gone.



The Web site you seek

Cannot be located, but

Countless more exist.



Chaos reigns within.

Reflect, repent, and reboot.

Order shall return



Program aborting:

Close all that you have worked on.

You ask far too much.



Windows has crashed.

I am the Blue Screen of Death.

No one hears your screams.



Yesterday it worked.

Today it is not working.

Windows is like that.



First snow, then silence.

This thousand dollar screen dies

So beautifully



With searching comes loss

And the presence of absence:

"My Noel" not found.



The Tao that is seen

is not the true Tao-until

You bring fresh toner.



Stay the patient course.

Of little worth is your ire.

The network is down.



A crash reduces

Your expensive computer

To a simple stone.



Three things are certain:

Death, taxes and lost data.

Guess which has occurred.



You step in the stream,

But the water has moved on.

This page is not here.



Out of memory.

We wish to hold the whole sky,

But we never will.



Having been erased,

The document you're seeking

Must now be retyped.



Serious error.

All shortcuts have disappeared.

Screen. Mind. Both are blank.

Wednesday, July 1, 2009

Requirements: Non-directive interviews

Reading the Economist's article "The avatar will see you now" I came across:
"Meanwhile, a real person alongside the participant will answer any questions and, after the virtual visit is over, Dr Conboy-Hill will carry out “non-directive” interviews, a technique used by the police to encourage witnesses to choose what they want to talk about and to maximise recall"
What interested me was the snippet about "non-directive" interviews - it sounded like a technique that might be worthwhile for requirements gathering - I subsequently found "ACTIVE LISTENING IN THE NONDIRECTIVE INTERVIEW" which I think there are a few tricks worth picking up - especially rephrasing and the "brake shoes"...

of course I'm a sucker for any document that uses the word "interlocutor" ;-)

Monday, June 8, 2009

Using n-grams to recognise human languages

Nice post by 67 bricks on language recognition using n-grams, one for the toolbox:
Automatically identifying (human) languages with code
usful reference as well.

Wednesday, October 15, 2008

Hamlet vs Twinkle, Brown and Cameron

ok, I've lost the plot - but I realised that this could be generalised into a general Vs engine, so without further ado!

Alternative Hamlet
Hamlet Vs Twinkle, Twinkle little star
Hamlet Vs David Cameron's Party speech
Hamlet Vs Gordon Brown's Global Economy speech
Hamlet Vs Bush
Hamlet Vs Obama
Hamlet Vs McCain

must, stop.. but Cameron version very good:

SCENE I. Elsinore. A million victims from alcohol related-attacks.

Sound money; low taxes – and it is a good child and a fair thought to lie between maids' legs.

HAMLET
How much I’ve worked in business alongside great entrepreneurs. I believe to be all around us.

Danes
[Aside] Though this be so.' We pray you, madam.

HAMLET
I'll set those to you like the herald Mercury
New-lighted on a heaven-kissing hill;
No, by strong hand
Of violent birth, but it’s not just for their care so doctors stop answering to Whitehall, no spirit dares stir abroad;
And let him, Horatio: a certain
convocation of politic worms are e'en with losing his wits.

MARCELLUS
Nay, do not know from personal experience just how brilliant and dedicated the people muddied,
Stood challenger on mount of all parties and none who created these safety nets and springboards. But it’s not my meaning: but I
cannot play upon me.

HAMLET
I am afeard you make it.

HAMLET
Why, what from our brother Norway?

QUEEN GERTRUDE
It is 'Adieu, adieu!
If it will please you go about to speak it profanely,
Look to't that can crop up on your heads: he, repulsed--a short tale to make ourselves relevant to the stage with tears
Had he been put on by a forged process of my cause,
To give the first Conservative metropolitan council in the mind and soul
To both your honours.

Hamlet using a Markov chain

Still playing with Markov chains, created a webpage that generates alternative versions of Hamlet, sample excerpt:


SCENE I. Elsinore. A room in Polonius' house.

Enter KING CLAUDIUS, attended
KING CLAUDIUS and POLONIUS

LORD POLONIUS

[Behind] O, ho! do you mark that?

QUEEN GERTRUDE

As kill a king!

FRANCISCO

Nay, I know not:
Is by a sleep to say we end
The ratifiers and props of every word,
They are not the trail of policy so sure
As hush as death, anon the dreadful thunder
Doth all the days i' the church.

KING CLAUDIUS

Give you good night.

Exit POLONIUS

Will you be honest and fair, your honesty should
admit no discourse to your rest; at night we'll hear a play
Let me be accurst!
None wed the second time I kill my husband dead,
Till the foul crimes done in my life,
That I have found
The observed of all your son's distemper.

QUEEN GERTRUDE

Alas, poor Yorick! I knew him, Horatio: welcome, good Marcellus.

The best poor Yorick so far is "Alas, poor Yorick! I knew your father; " - obviously his dad was not a nice guy ;-)

Tuesday, October 14, 2008

Hamlet vs. Twinkle, twinkle, little star

Give a markov chain a childs rhyme, a dash of Hamlet and behold! Hamlet's little star:


a little ere the mightiest julius fell,
the graves stood tenantless and the suits of solemn black,
nor windy suspiration of forced breath,
no, nor the fruitful river in the sky.

as your bright and tiny spark,
he could not see which way to heaven;
whiles, like a diamond in the roman streets:
as stars with trains of fire and dews of blood,
disasters in the same covenant,
and carriage of the land.

bernardo
i think i hear them. stand, ho! who's there?

enter horatio and marcellus,
the rivals of my watch, bid them make haste.

francisco
i think it was about to speak, when the blazing sun is gone,
when he nothing shines upon,
then you show your little light,
twinkle, twinkle,
all the holy vows of heaven
where now it burns, marcellus and bernardo, on their watch,
in the land,
and why such daily cast of brazen cannon,
and foreign mart for implements of war;
why such impress of shipwrights, whose sore task
does not grow alone
in thews and bulk, but, as this temple waxes,
the inward service of the cock.
some say that ever 'gainst that season comes
wherein our saviour's birth is celebrated,
the bird of dawning singeth all night long:
and then, they say, you spirits oft walk in death.

Monday, October 13, 2008

Alliteration algorithm

A function to determine is a string is an alliteration, for example
" as albert asked Anna, an antelope appeared!" is considered to be one.


private static bool IsAnAlliteration(string subject)
{
bool result = true;

char lead = default(char);

bool inWord = false;

foreach (char c in subject)
{
char current = char.ToLower(c);

bool isLetter = char.IsLetter(current);
// lead contains first character in string
// all words should start with lead character
if (lead == default(char) && isLetter)
lead = current;

if (!inWord && isLetter && lead != current)
result = false; // start of new word, but does not start with lead char
else if (!inWord && isLetter && lead == current)
inWord = true; // start of new word starts with lead char
else if (inWord && char.IsWhiteSpace(current))
inWord = false; // end of word found

if (!result)
break;
}
// did we find at least one word
result &= (lead != default(char));

return result;
}

Thursday, August 28, 2008

A man, a plan, a canal - Panama!

Whilst viewing Gary Daniels and Evan Goldring - Mock whiteboard problem I noticed a strange thing. In the video they show an mock interview question and try to answer it. As Evan says in the video and afterwards his solution was not the best one. After this everyone posted their attempt (15 pages of comments at the moment).

The strange thing? not one is right! why? Gary hints towards the end that the solution needs to handle white spaces correctly - in effect suggesting the the function should calculate palindromes on the basis of words rather than byte symmetry. I'm off course not suggesting that my solutions are correct either, as the definition of palindrome was not defined fully enough for anyone to be able to judge if an answer is correct.

My first attempt ignored this hint and just went for a straightforward symmetry test:

static bool isPalindromeFirst(string subject)
{
bool result = false;

if (subject != null)
{
int endOffset = subject.Length - 1;
int midOffset = (int)Math.Ceiling(subject.Length / 2d);

for (int startOffset = 0; startOffset < midOffset; startOffset++, endOffset--)
{
result = (subject[startOffset] == subject[endOffset]);

if (!result)
break;
}
}

return result;
}
This solution appears generally correct for the byte symmetry approach, but I just don't feel happy with its lack of whitespace handling , so my second attempt is longer, but hopefully an evolutionary approach:


static bool isPalindrome(string subject)
{
const int STEP_FORWARD = 1;
const int STEP_BACKWARD = -STEP_FORWARD;
const int BEFORE_START = -1;
const int CHAR_AT_A_TIME = 1;
const int COMPARE_EQUALS = 0;

// assume its not a palindrome
bool result = false;

// how to compare
CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;
CompareOptions co =
CompareOptions.IgnoreCase |
CompareOptions.IgnoreKanaType |
CompareOptions.IgnoreNonSpace |
CompareOptions.IgnoreSymbols |
CompareOptions.IgnoreWidth; |

// null strings are not palindromes
if (subject != null)
{
int AFTER_END = subject.Length;

// single letter words are palindromes
result = (AFTER_END == 1 && IsPalindromeChar(subject[0]));

// start the comparison points at valid characters
int startOffset = GetNextValidCharacter(subject, BEFORE_START, STEP_FORWARD, AFTER_END);
int endOffset = GetNextValidCharacter(subject, AFTER_END, STEP_BACKWARD, BEFORE_START);

while (startOffset < endOffset)
{
result = ci.Compare(subject, startOffset, CHAR_AT_A_TIME, subject, endOffset, CHAR_AT_A_TIME, co) == COMPARE_EQUALS;

if (!result)
break;

// move the comparison points towards each other
startOffset = GetNextValidCharacter(subject, startOffset, STEP_FORWARD, endOffset);
endOffset = GetNextValidCharacter(subject, endOffset, STEP_BACKWARD, startOffset);
}
}

return result;
}

static int GetNextValidCharacter(string subject, int offset, int step, int bound)
{
if (offset != bound)
offset += step;

while (offset != bound && !IsPalindromeChar(subject[offset]))
offset += step;

return offset;
}

static bool IsPalindromeChar(char c)
{
return char.IsLetter(c) || char.IsDigit(c);
}



ps I'm sure "a" is a palindrome, but I suspect "b" is not... however this would mean getting into recognising words and all that entails...

result of running:



'(null)' palindrome? False
'' palindrome? False
'.' palindrome? False
'..' palindrome? False
'.,.' palindrome? False
'a' palindrome? True
'ab' palindrome? False
'aa' palindrome? True
'aaa' palindrome? True
'abc' palindrome? False
'aba' palindrome? True
'abca' palindrome? False
'abba' palindrome? True
'aabccbaa' palindrome? True
'a man, a plan, a canal - panama' palindrome? True
'a man, a plan, a canal - panama!' palindrome? True
'A Man, a Plan, a Canal - Panama' palindrome? True
'A man, a plan, a canal - Panama!' palindrome? True
'A man, a plan, a canal - Panamá!' palindrome? True
'A ma;n, a plan, a canal - Panamá!' palindrome? True
'A ma;;n, a plan, a canal - Panamá!' palindrome? True
'A ma;n, a plan, a canal - Pa;namá!' palindrome? True
'A ma;;n, a plan, a canal - Pa;;namá!' palindrome? True
'A ma;;n, a plan, a canal - Pa;;;namá!' palindrome? True
'!A man, a plan, a canal - Panamá!' palindrome? True
'!A man, a plan, a canal - Panamá' palindrome? True
'!!A man, a plan, a canal - Panamá' palindrome? True
'A man, a plan, a canal - Panamá!!' palindrome? True
'1' palindrome? True
'12' palindrome? False
'11' palindrome? True
'122' palindrome? False
'121' palindrome? True
'1221' palindrome? True
'12.21' palindrome? True
'..12.21' palindrome? True
Press any key to continue...

Friday, August 1, 2008

Uxorious and Prolous

Chatting with the dead/alive cat's vet today we got onto the topic of what's the equivalent of Uxorious in terms of one's children.

There did not appear to be a quick answer to this, so as a holding position I'm going with a neologoliferated solution:

prolious: overly fond of offspring
though that actually might be a real word, so:

prolous: overly fond of child
though even that looks like a name

over to the cat's vet's friend...