/* Jaivox version 0.5 August 2013 Copyright 2010-2013 by Bits and Pixels, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import java.util.Properties; import java.util.Vector; import com.jaivox.interpreter.Command; import com.jaivox.interpreter.HistNode; /** * roadCommand is a user-defined function handler. The jaivox.interpreter * package contains a default Command class, this can be replaced by a * class similar to the one here. */ public class roadCommand extends Command { cmdProc proc; String base = "./"; String spec = "road_es.spec"; String quest = "road.quest"; String datafile = "road.txt"; String answer = "answer_es.txt"; /** * Create a roadCommand class, specifying properties used for naswering questions * as well as the cmdProc class which makes answers. */ public roadCommand () { Properties pp = new Properties (); pp.setProperty ("base_dir", base); pp.setProperty ("specs_file", spec); pp.setProperty ("data_file", datafile); pp.setProperty ("questions_file", quest); pp.setProperty ("answer_file", answer); proc = new cmdProc (this, pp); } /** * Overrides Command.handle. This is generated by the Jvgen generator from * user-defined functions in the grammar. * @param f * @param question * @param spec * @param instate * @param history * @return */ public String [] handle (String f, String question, String spec, String instate, Vector <HistNode> history) { if (f.equals ("ask")) return ask (question, spec, instate, history); else if (f.equals ("find")) return find (question, spec, instate, history); else return null; } /** * This function, without the connection to cmdProc, is created by Jvgen. * This function is expected to provide a true or false answer. * @param question * @param spec * @param instate * @param history * @return */ String [] ask (String question, String spec, String instate, Vector <HistNode> history) { // String result = "implement ask command!"; String [] result = proc.makeAnswer (question, history); return result; } /** * This function is also generated by the generator, tools.Jvgen. This one * finds specific answers, while ask returns true or false. * @param question * @param spec * @param instate * @param history * @return */ String [] find (String question, String spec, String instate, Vector <HistNode> history) { // String result = "implement find command!"; String [] result = proc.makeAnswer (question, history); return result; } }