/*
  $Id: example.cc 4056 2008-10-10 22:01:51Z abehm $

  Copyright (C) 2007 by The Regents of the University of California
	
  Redistribution of this file is permitted under
  the terms of the BSD license
    
  Date: 09/19/2007
  Author: Alexander Behm <abehm (at) ics.uci.edu>
*/

#include "wrappers.h"

StringContainerVector strContainer;
void initStringContainer();

// EXAMPLES
void wrapperSimpleExample();

int main() {
  
  initStringContainer();
  
  wrapperSimpleExample();
  
  return 0;
}

void initStringContainer() {
  vector<string> prefixes;
  prefixes.push_back("string");
  prefixes.push_back("example");  
  prefixes.push_back("test");
  prefixes.push_back("hello");
  prefixes.push_back("world");
  prefixes.push_back("foo");
  prefixes.push_back("bar");

  vector<string> suffixes;
  suffixes.push_back("1");
  suffixes.push_back("10");
  suffixes.push_back("100");
  suffixes.push_back("2");
  suffixes.push_back("20");
  suffixes.push_back("200");
  suffixes.push_back("3");
  suffixes.push_back("30");
  suffixes.push_back("300");

  cout << "---------------------------------------" << endl;
  cout << "STRING DICTIONARY:" << endl;
  for(unsigned j = 0; j < prefixes.size(); j++)
    for(unsigned i = 0; i < suffixes.size(); i++) {
      string ins = prefixes.at(j) + suffixes.at(i);
      strContainer.insertString(ins);
      cout << ins << endl;
    }
  cout << "---------------------------------------" << endl << endl;
}

// USAGE OF WRAPPERS FOR SIMPLE INDEXES
// List of Wrappers:
// WrapperSimpleEd - uses edit distance
// WrapperSimpleEdNorm - uses noralized edit distance
// WrapperSimpleJacc - uses jaccard similarity
// WrapperSimpleCos - uses cosine similarity
// WrapperSimpleDice - uses dice similarity
// see typedefs in wrappersimple.h
// ALSO POSSIBLE TO SPECIFY SIMMETRIC AS TEMPLATE PARAMETER: WrapperSimple<SimilarityMetric>
void wrapperSimpleExample() {
  cout << "----- EXAMPLE: WrapperSimpleEd -----" << endl;

  // create wrapper and build index
  // gramLength is 3 and use pre and postfixing of the string
  WrapperSimpleEd wrapper(&strContainer, 3, false);
  wrapper.buildIndex();

  // perform search
  float editDistance = 2.0f;
  string queryString = "xample";
  vector<unsigned> resultStringIDs;
  wrapper.search(queryString, editDistance, resultStringIDs);
  cout << "SIMILAR STRINGS: " << endl;
  for(unsigned i = 0; i < resultStringIDs.size(); i++) {
    string tmp;
    strContainer.retrieveString(tmp, resultStringIDs.at(i));
    cout << tmp << endl;
  }

  // save index
  wrapper.saveIndex("wrapperIndex.ix");

  // load index
  wrapper.loadIndex("wrapperIndex.ix");

  // perform search on loaded index
  resultStringIDs.clear();
  wrapper.search(queryString, editDistance, resultStringIDs);
  cout << "SIMILAR STRINGS: " << endl;
  for(unsigned i = 0; i < resultStringIDs.size(); i++) {
    string tmp;
    strContainer.retrieveString(tmp, resultStringIDs.at(i));
    cout << tmp << endl;
  }

  cout << "-----------------------------------------" << endl << endl;  
}
