public AdjacencyPairPrefab_greeting_questionExchange(AdjacencyPair parent, ConversationalParamaters conversationalParamaters, PairParamaters q) { //init preset paramaters, then pass them up to the base class /*describe purpose of paramaters * nothing special * * 1. initiating part: MOVE how are you * 2. responding part: MOVE i'm fine */ /*1. initiating options*/ //initiation 1: how are you Action initiation; Action response; //TODO determine if it should be a reciprocating question or not //if its parent is of type greeting_exchange then make moves. otherwise enqueue two more, one for each person to ask the other how they are if (parent is AdjacencyPairPrefab_greeting_questionExchange) { initiation = new Action(new Conversation.MovesQueueItem("senseGreetingQuestion", new object[2] { q, conversationalParamaters })); //hi response = new Action(new Conversation.MovesQueueItem("senseGreetingAnswer", new object[2] { q.cloneAndSwapSpeakers(), conversationalParamaters })); //hi } else //make one new pair for each person to ask the other how they are { initiation = new Action(new AdjacencyPairPrefab_greeting_questionExchange(this, conversationalParamaters, q)); response = new Action(new AdjacencyPairPrefab_greeting_questionExchange(this, conversationalParamaters, q.cloneAndSwapSpeakers())); } //now put all the actions in arrays Action[] respondingActionArray = { response }; Action[] initiatingActionArray = { initiation }; /* * END MAKING RESPONDING OPTIONS * * PUSH ALL TO BASE * */ //send these presets to the base base.init("greeting question", parent, conversationalParamaters, initiatingActionArray, respondingActionArray ); }
//process next MovesQueue item private void step() { if (adjacencyPairQueue.Count > 0) { AdjacencyPair p = adjacencyPairQueue.Dequeue(); p.enqueueRecursively(MovesQueue); } if (MovesQueue.Count > 0) { Type t = typeof(Conversation);//necessary for invoke for some reason MovesQueueItem p = MovesQueue.Dequeue(); //loop makes array of types from the paramaters //(necessary for the getmethod function in order to differentiate between overloaded methods) Type[] paramaterTypes = new Type[p.paramaters.Length]; for (int i = 0; i < p.paramaters.Length; i++) { //if an exception is ever thrown here it might be becuse the name or paramaters of a production rule was wrong paramaterTypes[i] = p.paramaters[i].GetType(); } //search for correct method MethodInfo methodInfo = t.GetMethod(p.methodToCall, paramaterTypes); /*INVOKE THE METHOD*/ try { /*The following if statement determines whether the method produces output or not * methods producing output need to enqueue string return values onto the output buffer * this is determined by the fact that only middlelayer functions take a PairParamaters as paramater */ //this if statement used to be a hack to determine if it was a terminal symbol (which had output) or a rule (which would just be processed) //if (paramaterTypes[0] == typeof(PairParamaters)) // methodInfo.Invoke(this/*utteranceGenerator*/, p.paramaters); //else outputQueue.Enqueue(new Turn(((PairParamaters)p.paramaters[0]).initiatingSpeaker, (string)methodInfo.Invoke(this /*utteranceGenerator*/, p.paramaters))); } catch (Exception e) { outputQueue.Enqueue(new Turn("Exception thrown in reflection invoke of " + p.methodToCall)); if (e.InnerException != null) { string err = e.InnerException.Message; //get the inner exception throw; //rethrow the exception } } } }
public AdjacencyPairPrefab_farewell(AdjacencyPair parent, ConversationalParamaters conversationalParamaters, PairParamaters q) { //init preset paramaters, then pass them up to the base class /*describe purpose of paramaters * if farewell mode simple * 1. initiating part: MOVE(bye) * 2. response: MOVE(bye) * * TODO other farewell modes. e.g. none. thanks. */ /*1. initiating options*/ //initiation 1: bye Action initiation; Action response; initiation = new Action(new Conversation.MovesQueueItem("senseFarewell", new object[2] { q, conversationalParamaters })); response = new Action(new Conversation.MovesQueueItem("senseFarewell", new object[2] { q.cloneAndSwapSpeakers(), conversationalParamaters })); //now put all the parts into arrays Action[] initiatingActionArray = { initiation }; Action[] respondingActionArray = { response }; /* * END MAKING OPTIONS * * PUSH ALL TO BASE * */ //send these presets to the base base.init("farewell", parent, conversationalParamaters, initiatingActionArray, respondingActionArray ); }