aboutsummaryrefslogtreecommitdiffstats
path: root/fsa/src/alltest/detector_test.cpp
blob: 87e9b5fb0f52ea7a03ec0a2f89f9f96184fe347e (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
 * @author  Peter Boros
 * @date    2004/08/20
 * @version $Id$
 * @file    vectorizertest.cpp
 * @brief   Test for the vectorizer class
 *
 */

#include <iostream>
#include <iomanip>

#include <vespa/fsa/fsa.h>
#include <vespa/fsa/detector.h>

using namespace fsa;

class MyHits : public Detector::Hits{
public:
  MyHits() {};
  ~MyHits() {};

  void add(const NGram &text,
           unsigned int from, int length,
           const FSA::State &) override
  {
    std::cout << "detected: [" << from << "," << from+length-1 << "], '"
              << text.join(" ",from,length) << "'\n";
  }
};

int main(int argc, char **argv)
{
  FSA dict(argc>=2? argv[1] : "__testfsa__.__fsa__");

  Detector d(dict);
  MyHits   h;

  std::string text;
  while(!std::cin.eof()){
    getline(std::cin,text);

    d.detect(text,h);
  }

  return 0;
}