/* This is -*- C -*- */
/* vim: set sw=2: */
/* $Id$ */

/*
 * markov.h
 *
 * Copyright (C) 2003 The Free Software Foundation, Inc.
 *
 */

/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 * 
 * This program 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA.
 */

#ifndef __MARKOV_H__
#define __MARKOV_H__

#include <glib.h>
#include <Python.h>
#include "rhyme.h"
#include "token.h"
#include "text.h"

typedef struct _Markov Markov;
struct _Markov {
  GSList *texts;

  GHashTable *all_hash;
  GPtrArray  *all;

  GHashTable *next;
  GHashTable *prev;

  gboolean sorted;
};

typedef struct _MarkovFilter MarkovFilter;
struct _MarkovFilter {
  Token   *next_is;
  Token   *prev_is;
  gboolean left_rooted;

  gboolean no_start;
  gboolean no_stop;

  int      min_syllables;
  int      max_syllables;

  RhymeType rhyme_type_exists;

  Token    *rhymes_with;
  RhymeType minimum_rhyme_type;

  gboolean (*filter_fn) (Token *token, gpointer user_data);
  gpointer   user_data;
};

#define MARKOV_FILTER_INIT { NULL, NULL, TRUE, FALSE, FALSE, 0, 0, RHYME_NONE, NULL, RHYME_TRUE, NULL, NULL }

Markov *markov_new       (void);
void    markov_add_pair  (Markov *markov, Token *t1, Token *t2);
void    markov_add_text  (Markov *markov, Text *txt);

void    markov_choose_many (Markov *markov,
			    MarkovFilter *filter,
			    int N,
			    TokenFn iter, gpointer user_data,
			    int *basic_choices,
			    int *filtered_choices);

Token *markov_choose (Markov *markov,
		      MarkovFilter *filter,
		      gboolean count_choices_only,
		      int *unfiltered_choices,
		      int *filtered_choices);

Token  *markov_choose_next (Markov *markov, Token *t,
			    MarkovFilter *filter,
			    int *unfiltered_choices,
			    int *filtered_choices);

Token  *markov_choose_prev (Markov *markov, Token *t,
			    MarkovFilter *filter,
			    int *unfiltered_choices,
			    int *filtered_choices);

PyObject *markov_to_py   (Markov *markov);
Markov   *markov_from_py (PyObject *py_markov);

void markov_filter_from_py_dict (MarkovFilter *filter,
				 PyObject *py_dict);
void markov_filter_py_dict_cleanup (MarkovFilter *filter);

/* Python Extensions */

PyObject *py_markov_new (PyObject *self, PyObject *args);



#endif /* __MARKOV_H__ */

