/*
 * GFAgent.java
 * Copyright (C) 2004-2005, Bjorn Bringert (bringert@cs.chalmers.se)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package se.chalmers.cs.gf.oaa;

import se.gu.ling.trindikit.oaa.common.*;

import se.chalmers.cs.gf.translate.*;

import java.io.IOException;

/*

BUGS: 

- get no results if we return something that does not unify with the solvable
- get no results if we return a function with no children


*/

/**
 *  The GF OAA agent.
 */
public class GFAgent extends OAAAgent {
    
        /** The name of this agent. */
        static final String name = "GFAgent";

        /** The only state of this agent. */
        static final int RUNNING = 0; 

        public GFAgent(Translators translators) {
                super(RUNNING,1);

                addSolver(RUNNING, new Parse(translators));
                addSolver(RUNNING, new Linearize(translators));
                addSolver(RUNNING, new Translate(translators));
                addSolver(RUNNING, new TranslateWithRanges(translators));
                addSolver(RUNNING, new ListGrammars(translators));
                addSolver(RUNNING, new ListLanguages(translators));
                addSolver(RUNNING, new LoadGrammar(translators));
        }
    
        public static void main(String[] args) throws IOException {
                Translators ts = new Translators();
                int i = 0;
                while (i < args.length) {
                        if (args[i].endsWith(".properties")) {
                                System.err.println("Loading grammar from " + args[i]);
                                ts.addTranslator(TranslatorFactory.createTranslator(args[i]));
                        } else {
                                break;
                        }
                        i++;
                }

                GFAgent agent = new GFAgent(ts);

                String[] oaaArgs = new String[args.length - i];
                System.arraycopy(args, i, oaaArgs, 0, args.length - i);
                
                if (!agent.register(name,oaaArgs)) {
                        System.err.println(name + ": register() failed");
                }
        }

}