NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

public class Magpie4 {
/**
* Get a default greeting
* @return a greeting
*/
public String getGreeting() {
return "Hey, let's have a conversation with each other.";
}


public String getResponse(String statement) {
String response = "";

// Look for a two word (you <something> me) pattern
int youPsn = findKeyword(statement, "you", 0);
int iPsn = findKeyword(statement, "I", 0);

if (statement.length() == 0) {
response = "You do know that having a conversation requires you to speak.";
} else if (findKeyword(statement, "no") >= 0) {
response = "Why so negative?";
} else if (findKeyword(statement, "mother") >= 0
|| findKeyword(statement, "father") >= 0
|| findKeyword(statement, "sister") >= 0
|| findKeyword(statement, "siblings") >= 0
|| findKeyword(statement, "Parents") >= 0
|| findKeyword(statement, "Grandmother") >= 0
|| findKeyword(statement, "Grandfather") >= 0
|| findKeyword(statement, "Grandparents") >= 0
|| findKeyword(statement, "brother") >= 0) {
response = "Tell me more about your family.";
}

// Responses which require transformations
else if (youPsn >= 0 && findKeyword(statement, "me", youPsn) >= 0) {
response = transformYouMeStatement(statement);
} else if (iPsn >= 0 && findKeyword(statement, "you", iPsn) >= 0) {
response = transformIYouStatement(statement);
} else if (findKeyword(statement, "I want to", 0) >= 0) {
response = transformIWantToStatement(statement);
} else if (findKeyword(statement, "I want", 0) >= 0) {
response = transformIWantStatement(statement);
} else {
response = getRandomResponse();
}

return response;
}


private String transformIWantToStatement(String statement) {
statement = statement.trim();
String lastChar = statement.substring(statement
.length() - 1);
if (lastChar.equals(".") || lastChar.equals("!"))
{
statement = statement.substring(0, statement
.length() - 1);
}
int psn = findKeyword (statement, "I want to", 0);
String restOfStatement = statement.substring(psn + 9).trim();
return "What would it mean to " + restOfStatement + "?";
}

private String transformIWantStatement(String statement) {
statement = statement.trim();
String lastChar = statement.substring(statement.length() - 1);
if (lastChar.equals(".") || lastChar.equals("!"))
{
statement = statement.substring(0, statement.length() - 1);
}
int psn = findKeyword (statement, "I want", 0);
String restOfStatement = statement.substring(psn + 6).trim();
return "Would you really be happy/ At peace if you had " + restOfStatement + "?";
}

private String transformYouMeStatement(String statement) {
// Remove the final period, if there is one
statement = statement.trim();
String lastChar = statement.substring(statement.length() - 1);
if (lastChar.equals("."))
{
statement = statement.substring(0, statement.length() - 1);
}

int psnOfYou = findKeyword (statement, "you", 0);
int psnOfMe = findKeyword (statement, "me", psnOfYou + 3);

String restOfStatement = statement.substring(psnOfYou + 3, psnOfMe).trim();
return "What makes you think that I " + restOfStatement + " you?";
}

private String transformIYouStatement(String statement) {
// Remove the final period, if there is one
statement = statement.trim();
String lastChar = statement.substring(statement.length() - 1);
if (lastChar.equals("."))
{
statement = statement.substring(0, statement.length() - 1);
}

int psnOfI = findKeyword (statement, "I", 0);
int psnOfYou = findKeyword (statement, "you", psnOfI + 1);

String restOfStatement = statement.substring(psnOfI + 1, psnOfYou).trim();
return "Why do you " + restOfStatement + " me?";
}

private int findKeyword(String statement, String goal, int startPos) {
String phrase = statement.trim();
int psn = phrase.toLowerCase().indexOf(goal.toLowerCase(), startPos);

while (psn >= 0)
{

String before = " ", after = " ";
if (psn > 0)
{
before = phrase.substring (psn - 1, psn).toLowerCase();
}
if (psn + goal.length() < phrase.length())
{
after = phrase.substring(psn + goal.length(), psn + goal.length() + 1).toLowerCase();
}

if (((before.compareTo ("a") < 0 ) || (before.compareTo("z") > 0)) // before is not a letter
&& ((after.compareTo ("a") < 0 ) || (after.compareTo("z") > 0)))
{
return psn;
}

psn = phrase.indexOf(goal.toLowerCase(), psn + 1);

}

return -1;
}


private int findKeyword(String statement, String goal) {
return findKeyword (statement, goal, 0);
}


private String getRandomResponse() {
final int NUMBER_OF_RESPONSES = 7;
double r = Math.random();
int whichResponse = (int) (r * NUMBER_OF_RESPONSES);
String response = "";

if (whichResponse == 0) {
response = "I personally don't care for what you say.";
} else if (whichResponse == 1) {
response = "And How does it make you feel?";
} else if (whichResponse == 2) {
response = "K.";
} else if (whichResponse == 3) {
response = "Bet.";
} else if (whichResponse == 4) {
response = "Interesting...";
} else if (whichResponse == 5) {
response = "I know this is off topic but I really like Fried Chicken and Cheese fries";
} else if (whichResponse == 6) {
response = "I have this teacher, his name is bajcz and hes amazing";
}

return response;
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.