changeset 1:60954ea75cce

Add main.c++
author Jordi Gutiérrez Hermoso <jordigh@gmail.com>
date Mon, 27 Dec 2010 12:53:47 -0600
parents 57fc6080db4d
children 0748d902784c
files main.c++
diffstat 1 files changed, 40 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/main.c++
@@ -0,0 +1,40 @@
+#include "levenshtein.c++"
+
+#include <fstream>
+#include <sstream>
+#include <algorithm>
+
+void string_to_upper(std::string& str) 
+{
+  std::transform( str.begin(), str.end(), str.begin(),  &toupper);
+}
+
+int main()
+{
+  using namespace std;
+  ifstream ifs("twl06.txt");
+  string word;
+  vector<string> wl;
+  while(ifs >> word)
+  {
+    wl.push_back(word);
+  }
+
+  string phrase = "tihs sententcnes iss nout varrry goud";
+  stringstream ss; ss << phrase;
+  size_t total_distance = 0;
+
+  while( ss >> word)
+  {
+    string_to_upper(word);
+    size_t m = 50;
+    for(size_t i = 0; i < wl.size(); i++)
+    {
+      m = min(levenshtein(wl[i],word,m), m);
+      if(m == 0)
+        break;
+    }
+    total_distance += m;
+  }
+  cout << total_distance << endl;
+}