home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / freeWAIS-sf-1.1 / ir / irfiles.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-10  |  12.9 KB  |  445 lines

  1. /* WIDE AREA INFORMATION SERVER SOFTWARE:
  2.    No guarantees or restrictions.  See the readme file for the full standard
  3.    disclaimer.
  4.  
  5.    Brewster@think.com
  6.  *
  7.  * $Log: irfiles.h,v $
  8.  * Revision 1.11  1995/01/10  17:02:59  pfeifer
  9.  * Added filed_description
  10.  *
  11.  * Revision 1.10  1994/07/13  07:52:36  huynh1
  12.  * Uli
  13.  *
  14.  * Revision 1.9  1994/06/02  10:48:05  pfeifer
  15.  * DICTIONARY_TOTAL_SIZE_WORD now depends on #define ISO
  16.  *
  17.  * Revision 1.8  1994/05/31  15:40:19  pfeifer
  18.  * DICTIONARY_TOTAL_SIZE_WORD
  19.  *
  20.  * Revision 1.7  1994/05/20  12:57:29  pfeifer
  21.  * beta
  22.  *
  23.  * Revision 1.6  1994/04/05  14:40:10  huynh1
  24.  * stemming component added.
  25.  *
  26.  * Revision 1.5  1994/03/23  12:57:47  huynh1
  27.  * openDatabase modified.
  28.  * patchlevel 07.
  29.  *
  30.  * Revision 1.4  1994/03/10  17:34:37  huynh1
  31.  * Patchlevel 05
  32.  *
  33.  * Revision 1.3  1994/03/08  20:42:28  huynh1
  34.  * Patchlevel 04
  35.  *
  36.  * Revision 1.2  1994/02/14  10:31:12  huynh1
  37.  * new struct for field concept added.
  38.  *
  39.  * Revision 1.1  1993/02/16  15:05:35  freewais
  40.  * Initial revision
  41.  *
  42.  * Revision 1.19  92/04/16  20:04:44  morris
  43.  * small fix to dictionary_blockword_occurances, lenght read was
  44.  * NEXT_INDEX_BLOCK_SIZE, now its NUMBR_OF_OCCURANCES_SIZE.
  45.  * 
  46.  * Revision 1.18  92/03/19  09:34:08  morris
  47.  * fixed the dictionary header to accurately indicate the number of blocks
  48.  * 
  49.  * Revision 1.17  92/02/17  12:38:00  jonathan
  50.  * Added defines for catalog.
  51.  * 
  52.  */
  53.  
  54. /* include file for irfiles.c */
  55.  
  56. #ifndef IRFILES_H
  57. #define IRFILES_H
  58.  
  59. #include "cdialect.h"
  60. #include "cutil.h"
  61. #include "hash.h"
  62. #include "ustubs.h" /* for time_t */
  63. #include "synonym.h"
  64.  
  65. /* filename extensions for various components */
  66. #define dictionary_ext            ".dct"
  67. #define filename_table_ext        ".fn"
  68. #define headline_table_ext        ".hl"
  69. #define document_table_ext        ".doc"
  70. #define index_ext            ".inv"
  71. #define source_ext             ".src"
  72. #define catalog_ext             ".cat"
  73. #define synonym_ext            ".syn"
  74. #ifdef BIO
  75. #define delimiters_ext    ".dlm"        /* dgg */
  76. #endif
  77. #ifdef FIELDS /* tung, 12/93 */
  78. #define field_ext "_field_"
  79. #endif
  80. /* these dictionary definitions are used in irhash,irverify, and irfiles */
  81. #define DICTIONARY_HEADER_SIZE 4
  82. #define DICTIONARY_BLOCK_SIZE 1000L  /* in entries, not bytes */
  83. #define DICTIONARY_ENTRY_HASH_CODE_SIZE 2
  84. /* #define DICTIONARY_ENTRY_COUNT_SIZE 3  moved to inverted file */
  85. /* #define DICTIONARY_ENTRY_INDEX_BLOCK_SIZE 4 not used and too long a symbol*/
  86. /* #define DICTIONARY_ELEMENT_SIZE 6 was 9 */
  87. #define DICTIONARY_SIZE 524288L
  88.  
  89. /* the word that holds the total number of words in the whole dictionary */
  90. #ifdef ISO
  91. #define DICTIONARY_TOTAL_SIZE_WORD "\377\377\377"
  92. #else
  93. #define DICTIONARY_TOTAL_SIZE_WORD "{}" 
  94. #endif
  95. #define INDEX_HEADER_SIZE 4
  96. #ifdef BIO
  97.  
  98. /* !! Bug in W8B5 -- Increasing this INDEX_BLOCK_SIZE_SIZE above 2 now fails !! */
  99. /* it worked in W8B3 ... both 3 and 4 fail now */
  100. #define INDEX_BLOCK_SIZE_SIZE 2  /* was 2, genbank wants 3, dgg */
  101.  
  102. #else
  103. #define INDEX_BLOCK_SIZE_SIZE 2
  104. #endif
  105.  
  106. #define NEXT_INDEX_BLOCK_SIZE 4
  107. #define INDEX_BLOCK_FLAG_SIZE 1
  108.  
  109. /* dgg -- this is a bug 
  110. #define INDEX_BLOCK_HEADER_SIZE 7
  111. This == 7 only if the component SIZEs don't change
  112. */
  113. #define INDEX_BLOCK_HEADER_SIZE (INDEX_BLOCK_SIZE_SIZE+NEXT_INDEX_BLOCK_SIZE+INDEX_BLOCK_FLAG_SIZE)
  114.  
  115.  
  116. #define NUMBER_OF_OCCURANCES_SIZE 4
  117. #define INDEX_BLOCK_NOT_FULL_FLAG 101            /* 'e' */
  118. #define INDEX_BLOCK_FULL_FLAG 69                 /* 'E' */
  119. #define INDEX_BLOCK_DICTIONARY_FLAG 123          /* '{' */
  120.  
  121. #define DOCUMENT_ID_SIZE 4
  122. #define WORD_POSITION_SIZE 0
  123. #define CHARACTER_POSITION_SIZE 3
  124.  
  125. #ifdef NEW_WEIGHT /* tung, 5/94 */
  126. #define WEIGHT_SIZE 0
  127. #define NEW_WEIGHT_SIZE (sizeof(float))
  128. #define INDEX_ELEMENT_SIZE (DOCUMENT_ID_SIZE+CHARACTER_POSITION_SIZE+WEIGHT_SIZE+NEW_WEIGHT_SIZE)
  129. #else
  130. #define WEIGHT_SIZE 1
  131. #define INDEX_ELEMENT_SIZE 8
  132. #endif
  133.  
  134. #define WORD_ID_SIZE 4 /* for posting arrays */
  135.  
  136. #ifdef BOOLEANS            /* dgg */
  137. #define BOOLEAN_AND    "and"    /* may prefer "&", but need symbol fix */
  138. #define BOOLEAN_NOT "not"    /* may prefer "!", but need symbol fix */
  139. #define BOOLEAN_NOT_FLAG -91    /* stick in weight param as flag for search_word */
  140. #endif
  141.  
  142. #ifdef PARTIALWORD        /* dgg */
  143. #define PARTWORD_WILDCARD  '*'    
  144. #define PARTIAL_FLAG -9999
  145. #endif
  146.  
  147. #ifdef LITERAL            /* dgg */
  148. #define LITERAL_KEY1    '"'    
  149. #define LITERAL_KEY2    0x27    /* single quote ' dgg */
  150. #define LITERAL_FLAG    -92    /* stick in weight param as flag for search_word */
  151. #define MAX_PHRASE_LENGTH  200
  152. #endif
  153.  
  154. #ifdef SOUND
  155. #define SOUNDEX "soundex"
  156. #define PHONIX  "phonix"
  157. #endif
  158.  
  159. #ifdef FIELDS /* tung, 12/93 */
  160. typedef struct field_db {
  161.   char* field_name;
  162.   long field_id;
  163.   long total_word_count;
  164.   long number_of_words;
  165.   long number_of_words_in_hashtable;
  166.   long index_file_number;
  167.   boolean numeric;
  168.   boolean stemming;
  169. } field_db;
  170.  
  171. typedef struct ftable {
  172.   long begin_tag_pos;
  173.   long end_tag_pos;
  174.   long index_pos;
  175.   char** indextypes;
  176.   int* index_kind;
  177. } ftable;
  178.  
  179. typedef struct fields_struct {
  180.   long field_id;
  181.   char* field_name;
  182.   char* field_description;
  183.   boolean numeric;
  184.   boolean stemming;
  185.   int numeric_len;
  186.   long n_index_pos;
  187.   long number_of_Ftable;
  188.   ftable* Ftable;
  189. } fields_struct;
  190.  
  191. #define MAX_FIELD_LENGTH 220
  192. #define FIELD_FLAG -99
  193. #define NUMERIC_FLAG -999
  194. #define FIELD_EQUAL '='
  195. #define EQ '='
  196. #define GREATER '>'
  197. #define LESS '<'
  198. #define TEXT "TEXT"
  199. #define FREE_TEXT_FIELD "text"
  200. #define STEMMING_TAG 's'
  201. #endif
  202.  
  203. typedef struct database {
  204.     char*    database_file;
  205.     FILE*    dictionary_stream;
  206.     FILE*    filename_table_stream;
  207.     FILE*    headline_table_stream;
  208.     FILE*    document_table_stream;
  209.     FILE*    index_stream;
  210. #ifdef FIELDS /* tung, 12/93 */
  211.         FILE**   field_index_streams;
  212.         FILE**  field_dictionary_streams;
  213.         long number_of_fields;
  214.         long current_field_position;
  215.     long current_field_id;
  216.         field_db* fields;
  217.         fields_struct** index_fields;
  218. #endif
  219. #ifdef STEM_WORDS
  220.     boolean stemming;
  221. #endif
  222. #ifdef BIO
  223.     FILE*    delimiters_stream;
  224. #endif
  225.         long    doc_table_allocated_entries;
  226.     hashtable* the_word_memory_hashtable;
  227.     long     number_of_words_in_hashtable; /* for building.
  228.                          checked on every add_word.
  229.                          set at start of building,
  230.                          and on every flush.*/
  231.     long     flush_after_n_words; /* set at the start of building used
  232.                     to compare with 
  233.                     number_of_words_in_hashtable. */
  234.     long     number_of_words; /* for building.  number of different words.
  235.                     Set from the headers of .inv files
  236.                     as they are merged. 
  237.                     It is used to set the header when a .inv 
  238.                     file is first created (not by merging).
  239.                     */
  240.     long    index_file_number; /* for building. */
  241.     long    total_word_count; /* Total number of word occurances.
  242.                      set during indexing, saved in 
  243.                      dictionary under 'ALL' entry */
  244.     void*   ext_database;
  245.  t_Synonym* syn_Table;       /* synonym index lookup table */
  246.         int     syn_Table_Size;     /* number of entries in synonym table */
  247. } database;
  248.  
  249. typedef struct document_table_entry {
  250.     long    filename_id;
  251.     long    headline_id;
  252.     long    source_id;    /* for signature system */
  253.     long    start_character;
  254.     long    end_character;
  255.     long     document_length; /* in characters */
  256.     long    number_of_lines; /* in lines */
  257.     time_t  date;            /* 0 if unknown */
  258. } document_table_entry;
  259.  
  260. #ifdef __cplusplus
  261. /* declare these as C style functions */
  262. extern "C"
  263.     {
  264. #endif /* def __cplusplus */
  265.  
  266. #ifdef FIELDS /* tung, 3/94 */
  267. database* openDatabase _AP((char* name, boolean initialize, boolean for_search, boolean type_field));
  268. #else
  269. database* openDatabase _AP((char* name, boolean initialize, boolean for_search));
  270. #endif
  271. void        closeDatabase _AP((database* the_db));
  272. void        disposeDatabase _AP((database* the_db));
  273.  
  274. void initialize_index_files _AP((database* db));
  275.  
  276. char *read_filename_table_entry _AP((long position, 
  277.                   char* filename,
  278.                   char* type, 
  279.                   time_t* file_write_date,
  280.                   database* db));
  281.  
  282. long write_filename_table_entry _AP((char* filename, char *type, database* db));
  283. boolean filename_in_database _AP((char *filename, char *type,
  284.                   time_t *write_file_date, database *db));
  285. boolean filename_in_filename_file _AP ((char *filename, char*type,
  286.                   time_t *file_write_date, 
  287.                   char* filename_file));
  288. char *read_headline_table_entry _AP((long position,database* db));
  289. long write_headline_table_entry _AP((char* headline, database* db));
  290.  
  291. #ifdef BIO
  292. char *read_delimiters _AP((database* db));
  293. long write_delimiters _AP((char* delimiters, database* db));
  294. #endif
  295.  
  296. boolean read_document_table_entry 
  297.   _AP((document_table_entry* doc_entry,long number,database* db));
  298.  
  299. long write_document_table_entry
  300.   _AP((document_table_entry* doc_table_entry, database* db));
  301.  
  302. boolean writeUserValToDocIDTable _AP((unsigned long userVal,long doc,
  303.                       database* db));
  304.  
  305.  
  306. long next_document_id _AP((database* db));
  307.  
  308.  
  309. void close_dictionary_file _AP((database *db));
  310.  
  311. long add_word_to_dictionary
  312.   _AP((char *word, long index_file_block_number, long number_of_occurances,
  313.        database* db));
  314.  
  315. #ifdef FIELDS /* tung, 12/93 */
  316. long field_add_word_to_dictionary
  317.   _AP((char *word, long index_file_block_number, long number_of_occurances,
  318.        long field_id, database* db));
  319. #endif
  320.  
  321. #ifdef PARTIALWORD
  322. long look_up_partialword_in_dictionary _AP((
  323. #ifdef FIELDS /* tung, 1/94 */
  324.                                             char* field_name, 
  325. #endif
  326.                                             char *word, long *word_id, database* db));
  327. #endif
  328.  
  329. #ifdef FIELDS /* tung, 12/93 */
  330. long field_look_up_word_in_dictionary _AP((char* field_name, char *word, long *word_id, database* db));
  331. #endif
  332.  
  333. long look_up_word_in_dictionary _AP((char *word, long *word_id, database* db));
  334.  
  335. long init_dict_file_for_writing _AP((database *db));
  336.  
  337. #ifdef FIELDS /* tung, 12/93 */
  338. long field_init_dict_file_for_writing _AP((long field_id, database *db));
  339. #endif
  340.  
  341. void init_dict_file_detailed _AP((FILE* dictionary_stream,
  342.                   long number_of_blocks));
  343.  
  344. #ifdef FIELDS /* tung, 12/93 */
  345. void field_init_dict_file_detailed _AP((FILE* dictionary_stream,
  346.                                         long number_of_blocks));
  347. #endif
  348. void record_num_blocks_in_dict _AP((FILE* dictionary_stream,
  349.                     long number_of_words));
  350.  
  351. long finished_add_word_to_dictionary _AP((database *db));
  352.  
  353. #ifdef FIELDS /* tung, 12/93 */
  354. long field_finished_add_word_to_dictionary _AP((long field_id, database *db));
  355. #endif
  356.  
  357. boolean register_src_structure _AP((char *filename));
  358. #ifdef FIELDS /* tung, 3/94 */
  359. boolean write_src_structure _AP((char *filename, 
  360.                  char *database_name, 
  361.                  char *typename,
  362.                  char **filenames, 
  363.                  long number_of_filename,
  364.                  boolean export_database,
  365.                  long tcp_port,
  366.                                  database* db));
  367. #else
  368. boolean write_src_structure _AP((char *filename, 
  369.                  char *database_name, 
  370.                  char *typename,
  371.                  char **filenames, 
  372.                  long number_of_filename,
  373.                  boolean export_database,
  374.                  long tcp_port));
  375. #endif
  376. boolean build_catalog _AP((database* db));
  377.  
  378. long allocate_index_block _AP((long how_large, FILE* stream));
  379.  
  380. unsigned char *read_dictionary_block _AP((unsigned char* block,
  381.                       long position,long length,
  382.                       FILE* stream));
  383.                                       
  384. void print_dictionary _AP((database* db));
  385.  
  386. #define DICTIONARY_ENTRY_SIZE 29 /* sum of MAX_WORD_LENGTH, 1 ('\0'), 
  387.                     NEXT_INDEX_BLOCK_SIZE and
  388.                     NUMBER_OF_OCCURANCES_SIZE */
  389.  
  390.  
  391. #ifdef DICT_FUNC
  392.  
  393. char *dictionary_block_word _AP((long i,unsigned char* block));
  394. long dictionary_block_position _AP((long i,unsigned char* block));
  395. long dictionary_block_word_occurances _AP((long i,unsigned char* block));
  396.  
  397. #else /* macros */
  398.  
  399. #define dictionary_block_word(i,block) \
  400.   ((char *)((block) + ((i) * DICTIONARY_ENTRY_SIZE)))
  401.  
  402. #define dictionary_block_position(i,block) \
  403.   read_bytes_from_memory(NEXT_INDEX_BLOCK_SIZE, \
  404.              (block) + ((i) * DICTIONARY_ENTRY_SIZE) + \
  405.               MAX_WORD_LENGTH + 1)
  406.  
  407. #define dictionary_block_word_occurances(i,block) \
  408.   read_bytes_from_memory(NUMBER_OF_OCCURANCES_SIZE, \
  409.                          (block) + ((i) * DICTIONARY_ENTRY_SIZE) + \
  410.                          MAX_WORD_LENGTH + 1 + NEXT_INDEX_BLOCK_SIZE)
  411. #endif
  412.  
  413. void print_dictionary_block _AP((unsigned char* block,long size));
  414.  
  415. /* database functions */
  416. char* dictionary_filename _AP((char* destination, database* db));
  417. #ifdef FIELDS /* tung, 12/93 */
  418. char* field_dictionary_filename 
  419.   _AP((char* destination, char* field_name, database* db));
  420. #endif
  421. char* filename_table_filename _AP((char* destination, database* db));
  422. char* headline_table_filename _AP((char* destination, database* db));
  423. char* document_table_filename _AP((char* destination, database* db));
  424. char* index_filename _AP((char* destination, database* db));
  425. char* index_filename_with_version _AP((long version, char* destination, 
  426.                                        database* db));
  427. #ifdef FIELDS /* tung, 12/93 */
  428. char* field_index_filename  _AP((char* destination,
  429.                                  char* field_name, database* db));
  430. char* field_index_filename_with_version _AP((long version, char* destination, 
  431.                                              long field_id, database* db));
  432. #endif
  433.  
  434. char* source_filename _AP((char* destination, database* db));
  435.  
  436. #ifdef BIO
  437. char* delimiters_filename _AP((char* destination, database* db));
  438. #endif
  439.  
  440. #ifdef __cplusplus
  441.     }
  442. #endif /* def __cplusplus */
  443.  
  444. #endif /* IRFILES_H */
  445.