Child: [8b2b00] (diff)

Download this file

stoplist.cpp    105 lines (84 with data), 2.0 kB

  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
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
#ifndef lint
static char rcsid[] = "@(#$Id: stoplist.cpp,v 1.1 2007-06-02 08:30:42 dockes Exp $ (C) 2007 J.F.Dockes";
#endif
#ifndef TEST_STOPLIST
#include "debuglog.h"
#include "readfile.h"
#include "unacpp.h"
#include "stoplist.h"
#ifndef NO_NAMESPACES
namespace Rcl
{
#endif
bool StopList::setFile(const string &filename)
{
m_hasStops = false;
m_stops.clear();
string stoptext, reason;
if (!file_to_string(filename, stoptext, &reason)) {
LOGDEB(("StopList::StopList: file_to_string(%s) failed: %s\n",
filename.c_str(), reason.c_str()));
return false;
}
TextSplit ts(this, TextSplit::TXTS_ONLYSPANS);
ts.text_to_words(stoptext);
return true;
}
bool StopList::takeword(const string& term, int, int, int)
{
string dterm;
unacmaybefold(term, dterm, "UTF-8", true);
LOGDEB2(("StopList::takeword: inserting [%s]\n", dterm.c_str()));
m_hasStops = true;
m_stops.insert(dterm);
return true;
}
bool StopList::isStop(const string &term) const
{
return m_hasStops ? m_stops.find(term) != m_stops.end() : false;
}
#ifndef NO_NAMESPACES
}
#endif
#else // TEST_STOPLIST
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <string>
#include <iostream>
#include "stoplist.h"
using namespace std;
using namespace Rcl;
static char *thisprog;
static char usage [] =
"trstoplist stopstermsfile\n\n"
;
static void
Usage(void)
{
fprintf(stderr, "%s: usage:\n%s", thisprog, usage);
exit(1);
}
const string tstwords[] = {
"the", "is", "xweird"
};
const int tstsz = sizeof(tstwords) / sizeof(string);
int main(int argc, char **argv)
{
int count = 10;
thisprog = argv[0];
argc--; argv++;
if (argc != 1)
Usage();
string filename = argv[0]; argc--;
StopList sl(filename);
for (int i = 0; i < tstsz; i++) {
const string &tst = tstwords[i];
cout << "[" << tst << "] " <<
(sl.isStop(tst) ? "in stop list" : "not in stop list") << endl;
}
exit(0);
}
#endif // TEST_STOPLIST