File: int4docn.c

package info (click to toggle)
bow 19991122-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,544 kB
  • ctags: 2,987
  • sloc: ansic: 38,660; lisp: 1,072; makefile: 594; perl: 492; yacc: 149; sh: 91
file content (60 lines) | stat: -rw-r--r-- 1,558 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* A convient interface to int4str.c, specifically for document names. */

/* Copyright (C) 1997 Andrew McCallum

   Written by:  Andrew Kachites McCallum <mccallum@cs.cmu.edu>

   This file is part of the Bag-Of-Words Library, `libbow'.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License
   as published by the Free Software Foundation, version 2.
   
   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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA */

#include <bow/libbow.h>

static bow_int4str *doc_map = NULL;

const char *
bow_int2docname (int index)
{
  if (!doc_map)
    bow_error ("No documents yet added to the int-docname mapping.\n");
  return bow_int2str (doc_map, index);
}

int
bow_docname2int (const char *docname)
{
  if (!doc_map)
    doc_map = bow_int4str_new (0);
  return bow_str2int (doc_map, docname);
}

int
bow_num_docnames ()
{
  return doc_map->str_array_length;
}

void
bow_docnames_write (FILE *fp)
{
  bow_int4str_write (doc_map, fp);
}

void
bow_docnames_read_from_fp (FILE *fp)
{
  if (doc_map)
    bow_int4str_free (doc_map);
  doc_map = bow_int4str_new_from_fp (fp);
}