/*
 * This file is part of the Poliqarp suite.
 * 
 * Copyright (C) 2009 by Instytut Podstaw Informatyki Polskiej
 * Akademii Nauk (IPI PAN; Institute of Computer Science, Polish
 * Academy of Sciences; cf. www.ipipan.waw.pl).  All rights reserved.
 * 
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation and appearing in the file gpl.txt included in the packaging
 * of this file.  (See http://www.gnu.org/licenses/translations.html for
 * unofficial translations.)
 * 
 * A commercial license is available from IPI PAN (contact
 * Michal.Ciesiolka@ipipan.waw.pl or ipi@ipipan.waw.pl for more
 * information).  Licensees holding a valid commercial license from IPI
 * PAN may use this file in accordance with that license.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE.
 */

#ifndef BPNG_DOCUMENT_H
#define BPNG_DOCUMENT_H 1

#include <bp/ng/list.h>
#include <bp/ng/corpus.h>

/**
 * Data for parsing an XML document.
 */
struct document {
   char *dir_name; /**< directory in which the document resides */
   const char *morph_name; /**< name of the morphosyntax XML file */
   const char *header_name; /**< name of the header XML file */
   void *xml_header; /**< parsed header XML file */
   const struct list *meta_keys; /**< metadata keys */
};

/**
 * Initialize the document structure.
 */
void document_create(struct document *, const char *dir_name,
   const char *morph_name, const char *header_name);

/**
 * Allocate memory for a document structure. Then, initialize it.
 */
struct document *document_alloc(const char *dir_name, 
   const char *morph_name, const char *header_name);

/**
 * Destroy the document structure.
 */
void document_destroy(struct document *);

/**
 * Destroy the document structure and free the allocated memory.
 */
void document_free(void *);

/**
 * Parse the document header.
 *
 * @return 0 in case of success, -1 in case of error
 */
int document_parse_header(struct document *, const struct list *meta_keys);

/**
 * Free memory allocated for parsed document header.
 */
void document_free_header(struct document *);


/**
 * Collect metadata from the parsed XML headers, for inclusion in the given
 * corpus. */
void document_collect_metadata(struct document *document,
   struct corpus_document *corpus_document, const char *id);

/**
 * Parse the document morphosyntax data, for inclusion in the given corpus.
 *
 * @return 0 in case of success, -1 in case of error
 */
int document_parse_morph(struct document *, struct corpus *);

#endif
