home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / freeWAIS-sf-1.1 / ir / stoplist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-06  |  8.7 KB  |  539 lines

  1. /* WIDE AREA INFORMATION SERVER SOFTWARE:
  2.    No guarantees or restrictions.  See the readme file for the full standard
  3.    disclaimer.
  4. */
  5.  
  6. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  7.  
  8.  
  9. /* this is a set of utilities for maintaining a stoplist
  10.  * kind of a kludge.
  11.  *
  12.  * -brewster
  13.  */
  14.  
  15. #ifndef lint
  16. static char *RCSid = "$Header: /usr/local/ls6/src+data/src/freeWAIS-sf/ir/RCS/stoplist.c,v 1.7 1994/09/07 13:29:22 pfeifer Exp $";
  17. #endif
  18.  
  19. /* Change log:
  20.  * $Log: stoplist.c,v $
  21.  * Revision 1.7  1994/09/07  13:29:22  pfeifer
  22.  * ctype is now included from cdialect.h after inclusion of string.h.
  23.  * Since ctype.h (the local version defines strcmp and friends, inclusion o
  24.  * of string.h after that caused probems
  25.  *
  26.  * Revision 1.6  1994/05/25  12:37:13  huynh1
  27.  * incompatible type by allocating.
  28.  * stop_from_file = (char**)malloc (nstops * sizeof (charptr));
  29.  *
  30.  * Revision 1.5  1994/05/21  14:39:14  pfeifer
  31.  * removed bad (void *) casts
  32.  *
  33.  * Revision 1.4  1994/04/26  16:27:02  huynh1
  34.  * function init_stop_list() and next_stop_word() changed.
  35.  * patchlevel 09
  36.  *
  37.  * Revision 1.3  1994/04/06  23:52:04  huynh1
  38.  * 08, autoconf, Uli
  39.  *
  40.  * Revision 1.2  1994/03/08  21:07:29  pfeifer
  41.  * Patchlevel 04
  42.  *
  43.  * Revision 1.1  1993/02/16  15:05:35  freewais
  44.  * Initial revision
  45.  *
  46.  * Revision 1.2  92/02/12  13:50:01  jonathan
  47.  * Added "$Log" so RCS will put the log message in the header
  48.  * 
  49.  * 
  50. */
  51.  
  52. #include "stoplist.h"
  53. #include "cdialect.h"
  54. /* #include <string.h> */
  55.  
  56. static char stoplist_filename[MAX_FILENAME_LEN];/* dgg */
  57. long    stoplist_pointer = 0;
  58. char   *stoplist[] = {
  59.     "a",
  60.     "about",
  61.     "above",
  62.     "according",
  63.     "across",
  64.     "actually",
  65.     "adj",
  66.     "after",
  67.     "afterwards",
  68.     "again",
  69.     "against",
  70.     "all",
  71.     "almost",
  72.     "alone",
  73.     "along",
  74.     "already",
  75.     "also",
  76.     "although",
  77.     "always",
  78.     "among",
  79.     "amongst",
  80.     "an",
  81.     "and",
  82.     "another",
  83.     "any",
  84.     "anyhow",
  85.     "anyone",
  86.     "anything",
  87.     "anywhere",
  88.     "are",
  89.     "aren't",
  90.     "around",
  91.     "as",
  92.     "at",
  93.     "b",
  94.     "be",
  95.     "became",
  96.     "because",
  97.     "become",
  98.     "becomes",
  99.     "becoming",
  100.     "been",
  101.     "before",
  102.     "beforehand",
  103.     "begin",
  104.     "beginning",
  105.     "behind",
  106.     "being",
  107.     "below",
  108.     "beside",
  109.     "besides",
  110.     "between",
  111.     "beyond",
  112.     "billion",
  113.     "both",
  114.     "but",
  115.     "by",
  116.     "c",
  117.     "can",
  118.     "can't",
  119.     "cannot",
  120.     "caption",
  121.     "co",
  122.     "co.",
  123.     "could",
  124.     "couldn't",
  125.     "d",
  126.     "did",
  127.     "didn't",
  128.     "do",
  129.     "does",
  130.     "doesn't",
  131.     "don't",
  132.     "down",
  133.     "during",
  134.     "e",
  135.     "each",
  136.     "eg",
  137.     "eight",
  138.     "eighty",
  139.     "either",
  140.     "else",
  141.     "elsewhere",
  142.     "end",
  143.     "ending",
  144.     "enough",
  145.     "etc",
  146.     "even",
  147.     "ever",
  148.     "every",
  149.     "everyone",
  150.     "everything",
  151.     "everywhere",
  152.     "except",
  153.     "f",
  154.     "few",
  155.     "fifty",
  156.     "first",
  157.     "five",
  158.     "for",
  159.     "former",
  160.     "formerly",
  161.     "forty",
  162.     "found", "",
  163.     "four",
  164.     "from",
  165.     "further",
  166.     "g",
  167.     "h",
  168.     "had",
  169.     "has",
  170.     "hasn't",
  171.     "have",
  172.     "haven't",
  173.     "he",
  174.     "he'd",
  175.     "he'll",
  176.     "he's",
  177.     "hence",
  178.     "her",
  179.     "here",
  180.     "here's",
  181.     "hereafter",
  182.     "hereby",
  183.     "herein",
  184.     "hereupon",
  185.     "hers",
  186.     "herself",
  187.     "him",
  188.     "himself",
  189.     "his",
  190.     "how",
  191.     "however",
  192.     "hundred",
  193.     "i",
  194.     "i'd",
  195.     "i'll",
  196.     "i'm",
  197.     "i've",
  198.     "ie",
  199.     "if",
  200.     "in",
  201.     "inc.",
  202.     "indeed",
  203.     "instead",
  204.     "into",
  205.     "is",
  206.     "isn't",
  207.     "it",
  208.     "it's",
  209.     "its",
  210.     "itself",
  211.     "j",
  212.     "k",
  213.     "l",
  214.     "last",
  215.     "later",
  216.     "latter",
  217.     "latterly",
  218.     "least",
  219.     "less",
  220.     "let",
  221.     "let's",
  222.     "like",
  223.     "likely",
  224.     "ltd",
  225.     "m",
  226.     "made",
  227.     "make",
  228.     "makes",
  229.     "many",
  230.     "maybe",
  231.     "me",
  232.     "meantime",
  233.     "meanwhile",
  234.     "might",
  235.     "million",
  236.     "miss",
  237.     "more",
  238.     "moreover",
  239.     "most",
  240.     "mostly",
  241.     "mr",
  242.     "mrs",
  243.     "much",
  244.     "must",
  245.     "my",
  246.     "myself",
  247.     "n",
  248.     "namely",
  249.     "neither",
  250.     "never",
  251.     "nevertheless",
  252.     "next",
  253.     "nine",
  254.     "ninety",
  255.     "no",
  256.     "nobody",
  257.     "none",
  258.     "nonetheless",
  259.     "noone",
  260.     "nor",
  261.     "not",
  262.     "nothing",
  263.     "now",
  264.     "nowhere",
  265.     "o",
  266.     "of",
  267.     "off",
  268.     "often",
  269.     "on",
  270.     "once",
  271.     "one",
  272.     "one's",
  273.     "only",
  274.     "onto",
  275.     "or",
  276.     "other",
  277.     "others",
  278.     "otherwise",
  279.     "our",
  280.     "ours",
  281.     "ourselves",
  282.     "out",
  283.     "over",
  284.     "overall",
  285.     "own",
  286.     "p",
  287.     "per",
  288.     "perhaps",
  289.     "q",
  290.     "r",
  291.     "rather",
  292.     "recent",
  293.     "recently",
  294.     "s",
  295.     "same",
  296.     "seem",
  297.     "seemed",
  298.     "seeming",
  299.     "seems",
  300.     "seven",
  301.     "seventy",
  302.     "several",
  303.     "she",
  304.     "she'd",
  305.     "she'll",
  306.     "she's",
  307.     "should",
  308.     "shouldn't",
  309.     "since",
  310.     "six",
  311.     "sixty",
  312.     "so",
  313.     "some",
  314.     "somehow",
  315.     "someone",
  316.     "something",
  317.     "sometime",
  318.     "sometimes",
  319.     "somewhere",
  320.     "still",
  321.     "stop",
  322.     "such",
  323.     "t",
  324.     "taking",
  325.     "ten",
  326.     "than",
  327.     "that",
  328.     "that'll",
  329.     "that's",
  330.     "that've",
  331.     "the",
  332.     "their",
  333.     "them",
  334.     "themselves",
  335.     "then",
  336.     "thence",
  337.     "there",
  338.     "there'd",
  339.     "there'll",
  340.     "there're",
  341.     "there's",
  342.     "there've",
  343.     "thereafter",
  344.     "thereby",
  345.     "therefore",
  346.     "therein",
  347.     "thereupon",
  348.     "these",
  349.     "they",
  350.     "they'd",
  351.     "they'll",
  352.     "they're",
  353.     "they've",
  354.     "thirty",
  355.     "this",
  356.     "those",
  357.     "though",
  358.     "thousand",
  359.     "three",
  360.     "through",
  361.     "throughout",
  362.     "thru",
  363.     "thus",
  364.     "to",
  365.     "together",
  366.     "too",
  367.     "toward",
  368.     "towards",
  369.     "trillion",
  370.     "twenty",
  371.     "two",
  372.     "u",
  373.     "under",
  374.     "unless",
  375.     "unlike",
  376.     "unlikely",
  377.     "until",
  378.     "up",
  379.     "upon",
  380.     "us",
  381.     "used",
  382.     "using",
  383.     "v",
  384.     "very",
  385.     "via",
  386.     "w",
  387.     "was",
  388.     "wasn't",
  389.     "we",
  390.     "we'd",
  391.     "we'll",
  392.     "we're",
  393.     "we've",
  394.     "well",
  395.     "were",
  396.     "weren't",
  397.     "what",
  398.     "what'll",
  399.     "what's",
  400.     "what've",
  401.     "whatever",
  402.     "when",
  403.     "whence",
  404.     "whenever",
  405.     "where",
  406.     "where's",
  407.     "whereafter",
  408.     "whereas",
  409.     "whereby",
  410.     "wherein",
  411.     "whereupon",
  412.     "wherever",
  413.     "whether",
  414.     "which",
  415.     "while",
  416.     "whither",
  417.     "who",
  418.     "who'd",
  419.     "who'll",
  420.     "who's",
  421.     "whoever",
  422.     "whole",
  423.     "whom",
  424.     "whomever",
  425.     "whose",
  426.     "why",
  427.     "will",
  428.     "with",
  429.     "within",
  430.     "without",
  431.     "won't",
  432.     "would",
  433.     "wouldn't",
  434.     "x",
  435.     "y",
  436.     "yes",
  437.     "yet",
  438.     "you",
  439.     "you'd",
  440.     "you'll",
  441.     "you're",
  442.     "you've",
  443.     "your",
  444.     "yours",
  445.     "yourself",
  446.     "yourselves",
  447.     "z", NULL
  448. };
  449.  
  450. long    nstops = 0;
  451. long nstops_pointer = 0;
  452. char  **stop_from_file = NULL;    /* dgg */
  453. char  **stop_ptr;        /* dgg */
  454. typedef char    (*charptr);
  455.  
  456. void stop_list_file (filename)
  457. char   *filename;
  458. {
  459.     strcpy (stoplist_filename, filename);
  460. }
  461.  
  462. void init_stop_list () {
  463. /*
  464. #ifdef BIO
  465. */
  466.   if (nstops > 0 && stop_from_file != NULL) {/* dgg */
  467.     int i;
  468.     for (i = 0; i < nstops; i++)
  469.       free (stop_from_file[i]);
  470.     free (stop_from_file);
  471.     nstops = 0;
  472.   }
  473.   /* printf("init_stop_list: stoplist file is '%s'\n", stoplist_filename); */
  474.   if (stoplist_filename[0] != '\0') {
  475.     char    word[256];
  476.     FILE * fp;
  477.     fp = fopen (stoplist_filename, "r");
  478.     if(fp == NULL) {
  479.       panic("stoplist '%s' missing!", stoplist_filename);
  480.     }
  481.     nstops = 1;
  482.     stop_from_file = (char**)malloc (nstops * sizeof (charptr));
  483.     while (fgets (word, 255, fp)) {
  484.       char   *cp = strstr (word, "\n");
  485.       if (cp != NULL)
  486.     *cp = '\0';
  487.       stop_from_file[nstops - 1] = (char*)malloc(strlen (word) + 1);
  488.       strcpy (stop_from_file[nstops - 1], word);
  489.       /* printf("init_stop_list: word %d is '%s'\n", nstops, stop_from_file[nstops-1]); */
  490.       nstops++;
  491.       stop_from_file = (char**)realloc(stop_from_file, nstops * sizeof (charptr));
  492.     }
  493.     fclose (fp);
  494.     stop_from_file[nstops - 1] = NULL;
  495.     /*stop_ptr = stop_from_file;*/
  496.     /* printf("init_stop_list: read %d stop words from '%s'\n", nstops-1, stoplist_filename); */
  497.   }
  498. /*
  499.   else
  500. #endif
  501. */
  502.   stop_ptr = stoplist;
  503.   stoplist_pointer = 0;
  504.   nstops_pointer = 0;
  505. }
  506.  
  507.  
  508. char   *next_stop_word () {
  509.   /* AA 9/2/94 -- use either the built in stop words
  510.    * or the ones from external file, but not both */
  511.   if(stop_from_file != NULL) {
  512.     if(stop_from_file[nstops_pointer] == NULL)
  513.       return(NULL);
  514.     else
  515.       return(stop_from_file[nstops_pointer++]);
  516.   }
  517.   else {
  518.     if(stop_ptr[stoplist_pointer] == NULL)
  519.       return(NULL);
  520.     else
  521.       return(stop_ptr[stoplist_pointer++]);
  522.   }
  523.  
  524.   /* returns NULL if all out */
  525.   if(stop_ptr[stoplist_pointer] == NULL) {
  526.     if(stop_from_file != NULL) {
  527.       if(stop_from_file[nstops_pointer] == NULL)
  528.     return(NULL);
  529.       else
  530.     return(stop_from_file[nstops_pointer++]);
  531.     }
  532.     else return (NULL);
  533.   }
  534.   else
  535.     return (stop_ptr[stoplist_pointer++]);
  536. }
  537.  
  538.  
  539.