From 7a18cc8b56e3b8393909397f008fd70a8d094dd6 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Tue, 10 Feb 2015 14:51:01 -0800 Subject: [PATCH 01/10] Sketch out a class instead of using static methods --- src/spellchecker.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/spellchecker.h b/src/spellchecker.h index 8d9a7ec..faf8ac6 100644 --- a/src/spellchecker.h +++ b/src/spellchecker.h @@ -6,14 +6,16 @@ namespace spellchecker { -// Initializes everything. -void Init(const std::string& dirname); +class SpellcheckerImplementation { +public: + virtual void SetDictionaryDirectory(const std::string& path) = 0; -// Returns true if the word is misspelled. -bool IsMisspelled(const std::string& word); + // Returns an array containing possible corrections for the word. + virtual std::vector GetCorrectionsForMisspelling(const std::string& word) = 0; -// Returns an array containing possible corrections for the word. -std::vector GetCorrectionsForMisspelling(const std::string& word); + // Returns true if the word is misspelled. + virtual bool IsMisspelled(const std::string& word) = 0; +}; } // namespace spellchecker From a6536ac11431e39a506e4790d6e1865f156c1b25 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Tue, 10 Feb 2015 14:51:26 -0800 Subject: [PATCH 02/10] Adapt our existing code to the new class --- src/spellchecker_hunspell.cc | 8 ++++---- src/spellchecker_hunspell.h | 17 +++++++++++++++++ src/spellchecker_mac.h | 17 +++++++++++++++++ src/spellchecker_mac.mm | 8 ++++---- 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 src/spellchecker_hunspell.h create mode 100644 src/spellchecker_mac.h diff --git a/src/spellchecker_hunspell.cc b/src/spellchecker_hunspell.cc index a6b4cdb..4995263 100644 --- a/src/spellchecker_hunspell.cc +++ b/src/spellchecker_hunspell.cc @@ -1,4 +1,4 @@ -#include "spellchecker.h" +#include "spellchecker_hunspell.h" #include "../vendor/hunspell/src/hunspell/hunspell.hxx" @@ -10,7 +10,7 @@ Hunspell* g_hunspell = NULL; } // namespace -void Init(const std::string& dirname) { +void HunspellSpellchecker::SetDictionaryDirectory(const std::string& dirname) { if (g_hunspell != NULL) return; @@ -19,11 +19,11 @@ void Init(const std::string& dirname) { g_hunspell = new Hunspell(affixpath.c_str(), dpath.c_str()); } -bool IsMisspelled(const std::string& word) { +bool HunspellSpellchecker::IsMisspelled(const std::string& word) { return g_hunspell->spell(word.c_str()) == 0; } -std::vector GetCorrectionsForMisspelling(const std::string& word) { +std::vector HunspellSpellchecker::GetCorrectionsForMisspelling(const std::string& word) { std::vector corrections; char** slist; int size = g_hunspell->suggest(&slist, word.c_str()); diff --git a/src/spellchecker_hunspell.h b/src/spellchecker_hunspell.h new file mode 100644 index 0000000..3a08617 --- /dev/null +++ b/src/spellchecker_hunspell.h @@ -0,0 +1,17 @@ +#ifndef SRC_SPELLCHECKER_HUNSPELL_H_ +#define SRC_SPELLCHECKER_HUNSPELL_H_ + +#include "spellchecker.h" + +namespace spellchecker { + +class HunspellSpellchecker : public SpellcheckerImplementation { +public: + void SetDictionaryDirectory(const std::string& path); + std::vector GetCorrectionsForMisspelling(const std::string& word); + bool IsMisspelled(const std::string& word); +}; + +} // namespace spellchecker + +#endif // SRC_SPELLCHECKER_MAC_H_ diff --git a/src/spellchecker_mac.h b/src/spellchecker_mac.h new file mode 100644 index 0000000..f804dbe --- /dev/null +++ b/src/spellchecker_mac.h @@ -0,0 +1,17 @@ +#ifndef SRC_SPELLCHECKER_MAC_H_ +#define SRC_SPELLCHECKER_MAC_H_ + +#include "spellchecker.h" + +namespace spellchecker { + +class MacSpellchecker : public SpellcheckerImplementation { +public: + void SetDictionaryDirectory(const std::string& path); + std::vector GetCorrectionsForMisspelling(const std::string& word); + bool IsMisspelled(const std::string& word); +}; + +} // namespace spellchecker + +#endif // SRC_SPELLCHECKER_MAC_H_ diff --git a/src/spellchecker_mac.mm b/src/spellchecker_mac.mm index 73f4057..7f13b3c 100644 --- a/src/spellchecker_mac.mm +++ b/src/spellchecker_mac.mm @@ -1,14 +1,14 @@ -#include "spellchecker.h" +#include "spellchecker_mac.h" #import #import namespace spellchecker { -void Init(const std::string& dirname) { +void MacSpellchecker::SetDictionaryDirectory(const std::string& path) { } -bool IsMisspelled(const std::string& word) { +bool MacSpellchecker::IsMisspelled(const std::string& word) { bool result; @autoreleasepool { @@ -23,7 +23,7 @@ bool IsMisspelled(const std::string& word) { return result; } -std::vector GetCorrectionsForMisspelling(const std::string& word) { +std::vector MacSpellchecker::GetCorrectionsForMisspelling(const std::string& word) { std::vector corrections; @autoreleasepool { From f5ab5a42f91fb0832e035e76c843213066511dbe Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Tue, 10 Feb 2015 17:38:17 -0800 Subject: [PATCH 03/10] Create a Node class that wraps Hunspell for the moment --- lib/spellchecker.js | 3 +- src/main.cc | 112 +++++++++++++++++++++++++++++++------------- 2 files changed, 82 insertions(+), 33 deletions(-) diff --git a/lib/spellchecker.js b/lib/spellchecker.js index 4646864..adf65bd 100644 --- a/lib/spellchecker.js +++ b/lib/spellchecker.js @@ -3,5 +3,6 @@ bindings.init(__dirname); module.exports = { isMisspelled: bindings.isMisspelled, - getCorrectionsForMisspelling: bindings.getCorrectionsForMisspelling + getCorrectionsForMisspelling: bindings.getCorrectionsForMisspelling, + TestClass: bindings.TestClass }; diff --git a/src/main.cc b/src/main.cc index 42c751f..fe85d68 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,49 +1,97 @@ +#include "nan.h" #include "spellchecker.h" +#include "spellchecker_hunspell.h" -#include "nan.h" +using node::ObjectWrap; +using namespace spellchecker; using namespace v8; namespace { -NAN_METHOD(PlatformInit) { - NanScope(); - spellchecker::Init(*String::Utf8Value(args[0])); - NanReturnUndefined(); -} +class Spellchecker : public ObjectWrap { + SpellcheckerImplementation* impl; -NAN_METHOD(IsMisspelled) { - NanScope(); - if (args.Length() < 1) - return NanThrowError("Bad argument"); + static NAN_METHOD(New) { + NanScope(); + Spellchecker* that = new Spellchecker(); + that->Wrap(args.This()); - std::string word = *String::Utf8Value(args[0]); - NanReturnValue(NanNew(spellchecker::IsMisspelled(word))); -} + NanReturnValue(args.This()); + } -NAN_METHOD(GetCorrectionsForMisspelling) { - NanScope(); - if (args.Length() < 1) - return NanThrowError("Bad argument"); + static NAN_METHOD(SetDictionaryDirectory) { + NanScope(); - std::string word = *String::Utf8Value(args[0]); - std::vector corrections = - spellchecker::GetCorrectionsForMisspelling(word); + if (args.Length() < 1) { + return NanThrowError("Bad argument"); + } - Local result = NanNew(corrections.size()); - for (size_t i = 0; i < corrections.size(); ++i) { - const std::string& word = corrections[i]; - result->Set(i, NanNew(word.data(), word.size())); + Spellchecker* that = ObjectWrap::Unwrap(args.Holder()); + std::string directory = *String::Utf8Value(args[0]); + that->impl->SetDictionaryDirectory(directory); + NanReturnUndefined(); } - NanReturnValue(result); -} + static NAN_METHOD(IsMisspelled) { + NanScope(); + if (args.Length() < 1) { + return NanThrowError("Bad argument"); + } + + Spellchecker* that = ObjectWrap::Unwrap(args.Holder()); + std::string word = *String::Utf8Value(args[0]); + + NanReturnValue(NanNew(that->impl->IsMisspelled(word))); + } + + static NAN_METHOD(GetCorrectionsForMisspelling) { + NanScope(); + if (args.Length() < 1) { + return NanThrowError("Bad argument"); + } + + Spellchecker* that = ObjectWrap::Unwrap(args.Holder()); + + std::string word = *String::Utf8Value(args[0]); + std::vector corrections = + that->impl->GetCorrectionsForMisspelling(word); + + Local result = NanNew(corrections.size()); + for (size_t i = 0; i < corrections.size(); ++i) { + const std::string& word = corrections[i]; + result->Set(i, NanNew(word.data(), word.size())); + } + + NanReturnValue(result); + } + + Spellchecker() { + // TODO: Set impl + impl = new HunspellSpellchecker(); + } + + // actual destructor + virtual ~Spellchecker() { + delete impl; + } + + public: + static void Init(Handle exports) { + Local tpl = NanNew(Spellchecker::New); + + tpl->SetClassName(NanSymbol("Spellchecker")); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + + NODE_SET_METHOD(tpl->InstanceTemplate(), "setDictionaryDirectory", Spellchecker::SetDictionaryDirectory); + NODE_SET_METHOD(tpl->InstanceTemplate(), "getCorrectionsForMisspelling", Spellchecker::GetCorrectionsForMisspelling); + NODE_SET_METHOD(tpl->InstanceTemplate(), "isMisspelled", Spellchecker::IsMisspelled); + + exports->Set(NanNew("Spellchecker"), tpl->GetFunction()); + } +}; -void Init(Handle exports) { - NODE_SET_METHOD(exports, "init", PlatformInit); - NODE_SET_METHOD(exports, "isMisspelled", IsMisspelled); - NODE_SET_METHOD(exports, - "getCorrectionsForMisspelling", - GetCorrectionsForMisspelling); +void Init(Handle exports, Handle module) { + Spellchecker::Init(exports); } } // namespace From 08f5e141c45472df8a90cb3cb191c4f8ecc72821 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Tue, 10 Feb 2015 17:46:06 -0800 Subject: [PATCH 04/10] Redo the SetDictionary API to take language and dict directory --- src/main.cc | 14 ++++++++++---- src/spellchecker.h | 2 +- src/spellchecker_hunspell.cc | 2 +- src/spellchecker_hunspell.h | 2 +- src/spellchecker_mac.h | 2 +- src/spellchecker_mac.mm | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main.cc b/src/main.cc index fe85d68..404d9f8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -19,7 +19,7 @@ class Spellchecker : public ObjectWrap { NanReturnValue(args.This()); } - static NAN_METHOD(SetDictionaryDirectory) { + static NAN_METHOD(SetDictionary) { NanScope(); if (args.Length() < 1) { @@ -27,8 +27,14 @@ class Spellchecker : public ObjectWrap { } Spellchecker* that = ObjectWrap::Unwrap(args.Holder()); - std::string directory = *String::Utf8Value(args[0]); - that->impl->SetDictionaryDirectory(directory); + + std::string language = *String::Utf8Value(args[0]); + std::string directory = ""; + if (args.Length() > 1) { + directory = *String::Utf8Value(args[1]); + } + + that->impl->SetDictionary(language, directory); NanReturnUndefined(); } @@ -82,7 +88,7 @@ class Spellchecker : public ObjectWrap { tpl->SetClassName(NanSymbol("Spellchecker")); tpl->InstanceTemplate()->SetInternalFieldCount(1); - NODE_SET_METHOD(tpl->InstanceTemplate(), "setDictionaryDirectory", Spellchecker::SetDictionaryDirectory); + NODE_SET_METHOD(tpl->InstanceTemplate(), "setDictionary", Spellchecker::SetDictionary); NODE_SET_METHOD(tpl->InstanceTemplate(), "getCorrectionsForMisspelling", Spellchecker::GetCorrectionsForMisspelling); NODE_SET_METHOD(tpl->InstanceTemplate(), "isMisspelled", Spellchecker::IsMisspelled); diff --git a/src/spellchecker.h b/src/spellchecker.h index faf8ac6..79dba23 100644 --- a/src/spellchecker.h +++ b/src/spellchecker.h @@ -8,7 +8,7 @@ namespace spellchecker { class SpellcheckerImplementation { public: - virtual void SetDictionaryDirectory(const std::string& path) = 0; + virtual void SetDictionary(const std::string& language, const std::string& path) = 0; // Returns an array containing possible corrections for the word. virtual std::vector GetCorrectionsForMisspelling(const std::string& word) = 0; diff --git a/src/spellchecker_hunspell.cc b/src/spellchecker_hunspell.cc index 4995263..beba635 100644 --- a/src/spellchecker_hunspell.cc +++ b/src/spellchecker_hunspell.cc @@ -10,7 +10,7 @@ Hunspell* g_hunspell = NULL; } // namespace -void HunspellSpellchecker::SetDictionaryDirectory(const std::string& dirname) { +void HunspellSpellchecker::SetDictionary(const std::string& language, const std::string& dirname) { if (g_hunspell != NULL) return; diff --git a/src/spellchecker_hunspell.h b/src/spellchecker_hunspell.h index 3a08617..95faab7 100644 --- a/src/spellchecker_hunspell.h +++ b/src/spellchecker_hunspell.h @@ -7,7 +7,7 @@ namespace spellchecker { class HunspellSpellchecker : public SpellcheckerImplementation { public: - void SetDictionaryDirectory(const std::string& path); + void SetDictionary(const std::string& language, const std::string& path); std::vector GetCorrectionsForMisspelling(const std::string& word); bool IsMisspelled(const std::string& word); }; diff --git a/src/spellchecker_mac.h b/src/spellchecker_mac.h index f804dbe..ad92082 100644 --- a/src/spellchecker_mac.h +++ b/src/spellchecker_mac.h @@ -7,7 +7,7 @@ namespace spellchecker { class MacSpellchecker : public SpellcheckerImplementation { public: - void SetDictionaryDirectory(const std::string& path); + void SetDictionary(const std::string& language, const std::string& path); std::vector GetCorrectionsForMisspelling(const std::string& word); bool IsMisspelled(const std::string& word); }; diff --git a/src/spellchecker_mac.mm b/src/spellchecker_mac.mm index 7f13b3c..9b35ac7 100644 --- a/src/spellchecker_mac.mm +++ b/src/spellchecker_mac.mm @@ -5,7 +5,7 @@ namespace spellchecker { -void MacSpellchecker::SetDictionaryDirectory(const std::string& path) { +void MacSpellchecker::SetDictionary(const std::string& language, const std::string& path) { } bool MacSpellchecker::IsMisspelled(const std::string& word) { From 100c3a45b664bfc90ec8c664759241be0d9b664f Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Tue, 10 Feb 2015 17:47:22 -0800 Subject: [PATCH 05/10] Virtual destructor --- src/spellchecker.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/spellchecker.h b/src/spellchecker.h index 79dba23..b1a7c5d 100644 --- a/src/spellchecker.h +++ b/src/spellchecker.h @@ -15,6 +15,8 @@ class SpellcheckerImplementation { // Returns true if the word is misspelled. virtual bool IsMisspelled(const std::string& word) = 0; + + virtual ~SpellcheckerImplementation(); }; } // namespace spellchecker From e6562d99edcb80efd9b2e7fbe86f0d1b9177d503 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Tue, 10 Feb 2015 17:52:32 -0800 Subject: [PATCH 06/10] Hunspell is now language-aware --- src/spellchecker.h | 2 +- src/spellchecker_hunspell.cc | 34 ++++++++++++++++++++-------------- src/spellchecker_hunspell.h | 8 ++++++++ 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/spellchecker.h b/src/spellchecker.h index b1a7c5d..af6f329 100644 --- a/src/spellchecker.h +++ b/src/spellchecker.h @@ -16,7 +16,7 @@ class SpellcheckerImplementation { // Returns true if the word is misspelled. virtual bool IsMisspelled(const std::string& word) = 0; - virtual ~SpellcheckerImplementation(); + virtual ~SpellcheckerImplementation() {} }; } // namespace spellchecker diff --git a/src/spellchecker_hunspell.cc b/src/spellchecker_hunspell.cc index beba635..e55a939 100644 --- a/src/spellchecker_hunspell.cc +++ b/src/spellchecker_hunspell.cc @@ -1,38 +1,44 @@ -#include "spellchecker_hunspell.h" - #include "../vendor/hunspell/src/hunspell/hunspell.hxx" +#include "spellchecker_hunspell.h" + namespace spellchecker { -namespace { +HunspellSpellchecker::HunspellSpellchecker() { + this->hunspell = NULL; +} -Hunspell* g_hunspell = NULL; +HunspellSpellchecker::~HunspellSpellchecker() { + if (!this->hunspell) return; -} // namespace + delete this->hunspell; +} void HunspellSpellchecker::SetDictionary(const std::string& language, const std::string& dirname) { - if (g_hunspell != NULL) - return; + if (hunspell != NULL) { + delete this->hunspell; + } - std::string affixpath = dirname + "/../vendor/hunspell_dictionaries/en_US.aff"; - std::string dpath = dirname + "/../vendor/hunspell_dictionaries/en_US.dic"; - g_hunspell = new Hunspell(affixpath.c_str(), dpath.c_str()); + std::string affixpath = dirname + "/" + language + ".aff"; + std::string dpath = dirname + "/" + language + ".dic"; + this->hunspell = new Hunspell(affixpath.c_str(), dpath.c_str()); } bool HunspellSpellchecker::IsMisspelled(const std::string& word) { - return g_hunspell->spell(word.c_str()) == 0; + return this->hunspell->spell(word.c_str()) == 0; } std::vector HunspellSpellchecker::GetCorrectionsForMisspelling(const std::string& word) { std::vector corrections; char** slist; - int size = g_hunspell->suggest(&slist, word.c_str()); + int size = hunspell->suggest(&slist, word.c_str()); corrections.reserve(size); - for (int i = 0; i < size; ++i) + for (int i = 0; i < size; ++i) { corrections.push_back(slist[i]); + } - g_hunspell->free_list(&slist, size); + this->hunspell->free_list(&slist, size); return corrections; } diff --git a/src/spellchecker_hunspell.h b/src/spellchecker_hunspell.h index 95faab7..7a9a515 100644 --- a/src/spellchecker_hunspell.h +++ b/src/spellchecker_hunspell.h @@ -3,13 +3,21 @@ #include "spellchecker.h" +class Hunspell; + namespace spellchecker { class HunspellSpellchecker : public SpellcheckerImplementation { public: + HunspellSpellchecker(); + ~HunspellSpellchecker(); + void SetDictionary(const std::string& language, const std::string& path); std::vector GetCorrectionsForMisspelling(const std::string& word); bool IsMisspelled(const std::string& word); + +private: + Hunspell* hunspell; }; } // namespace spellchecker From a0e18598b50e8b5ac1ff145213515197bb1e4cbc Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Tue, 10 Feb 2015 18:10:50 -0800 Subject: [PATCH 07/10] Modify spellchecker.js to shim to the new class --- lib/spellchecker.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/spellchecker.js b/lib/spellchecker.js index adf65bd..c080bfa 100644 --- a/lib/spellchecker.js +++ b/lib/spellchecker.js @@ -1,8 +1,30 @@ +var path = require('path'); var bindings = require('../build/Release/spellchecker.node'); -bindings.init(__dirname); + +Spellchecker = bindings.Spellchecker; + +var defaultSpellcheck = null; +var ensureDefaultSpellCheck = function() { + if (defaultSpellcheck) return; + + defaultSpellcheck = new Spellchecker(); + defaultSpellcheck.setDictionary('en_US', path.join(__dirname, '..', 'vendor', 'hunspell_dictionaries')); +}; + +var isMisspelled = function(word) { + ensureDefaultSpellCheck(); + + return defaultSpellcheck.isMisspelled(word); +}; + +var getCorrectionsForMisspelling = function(word) { + ensureDefaultSpellCheck(); + + return defaultSpellcheck.getCorrectionsForMisspelling(word); +}; module.exports = { - isMisspelled: bindings.isMisspelled, - getCorrectionsForMisspelling: bindings.getCorrectionsForMisspelling, - TestClass: bindings.TestClass + isMisspelled: isMisspelled, + getCorrectionsForMisspelling: getCorrectionsForMisspelling, + Spellchecker: Spellchecker }; From b67675c53ecf839a64a1083fe93f1676e8552701 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 11 Feb 2015 13:09:43 -0800 Subject: [PATCH 08/10] Create a class that is defined per-platform to create the spellchecker --- binding.gyp | 10 ++++++++++ src/main.cc | 4 +--- src/spellchecker.h | 5 +++++ src/spellchecker_linux.cc | 10 ++++++++++ src/spellchecker_mac.mm | 4 ++++ src/spellchecker_win.cc | 10 ++++++++++ 6 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/spellchecker_linux.cc create mode 100644 src/spellchecker_win.cc diff --git a/binding.gyp b/binding.gyp index fea190a..a25b57d 100644 --- a/binding.gyp +++ b/binding.gyp @@ -34,6 +34,16 @@ 'src/spellchecker_hunspell.cc', ], }], + ['OS=="win"', { + 'sources': [ + 'src/spellchecker_win.cc' + ], + }], + ['OS=="linux"', { + 'sources': [ + 'src/spellchecker_linux.cc' + ], + }], ['OS=="mac" and spellchecker_use_hunspell=="false"', { 'sources': [ 'src/spellchecker_mac.mm', diff --git a/src/main.cc b/src/main.cc index 404d9f8..b886403 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,5 @@ #include "nan.h" #include "spellchecker.h" -#include "spellchecker_hunspell.h" using node::ObjectWrap; using namespace spellchecker; @@ -72,8 +71,7 @@ class Spellchecker : public ObjectWrap { } Spellchecker() { - // TODO: Set impl - impl = new HunspellSpellchecker(); + impl = SpellcheckerFactory::CreateSpellchecker(); } // actual destructor diff --git a/src/spellchecker.h b/src/spellchecker.h index af6f329..e8a48ee 100644 --- a/src/spellchecker.h +++ b/src/spellchecker.h @@ -19,6 +19,11 @@ class SpellcheckerImplementation { virtual ~SpellcheckerImplementation() {} }; +class SpellcheckerFactory { +public: + static SpellcheckerImplementation* CreateSpellchecker(); +}; + } // namespace spellchecker #endif // SRC_SPELLCHECKER_H_ diff --git a/src/spellchecker_linux.cc b/src/spellchecker_linux.cc new file mode 100644 index 0000000..e5ab00b --- /dev/null +++ b/src/spellchecker_linux.cc @@ -0,0 +1,10 @@ +#include "spellchecker.h" +#include "spellchecker_hunspell.h" + +namespace spellchecker { + +SpellcheckerImplementation* SpellcheckerFactory::CreateSpellchecker() { + return new HunspellSpellchecker(); +} + +} // namespace spellchecker diff --git a/src/spellchecker_mac.mm b/src/spellchecker_mac.mm index 9b35ac7..1d53fe3 100644 --- a/src/spellchecker_mac.mm +++ b/src/spellchecker_mac.mm @@ -47,4 +47,8 @@ return corrections; } +SpellcheckerImplementation* SpellcheckerFactory::CreateSpellchecker() { + return new MacSpellchecker(); +} + } // namespace spellchecker diff --git a/src/spellchecker_win.cc b/src/spellchecker_win.cc new file mode 100644 index 0000000..e5ab00b --- /dev/null +++ b/src/spellchecker_win.cc @@ -0,0 +1,10 @@ +#include "spellchecker.h" +#include "spellchecker_hunspell.h" + +namespace spellchecker { + +SpellcheckerImplementation* SpellcheckerFactory::CreateSpellchecker() { + return new HunspellSpellchecker(); +} + +} // namespace spellchecker From 0903123c837092c87f1cdf265562969279f16c25 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 11 Feb 2015 13:29:52 -0800 Subject: [PATCH 09/10] Ensure arguments get marshaled correctly --- lib/spellchecker.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/spellchecker.js b/lib/spellchecker.js index c080bfa..2584274 100644 --- a/lib/spellchecker.js +++ b/lib/spellchecker.js @@ -11,16 +11,16 @@ var ensureDefaultSpellCheck = function() { defaultSpellcheck.setDictionary('en_US', path.join(__dirname, '..', 'vendor', 'hunspell_dictionaries')); }; -var isMisspelled = function(word) { +var isMisspelled = function() { ensureDefaultSpellCheck(); - return defaultSpellcheck.isMisspelled(word); + return defaultSpellcheck.isMisspelled.apply(defaultSpellcheck, arguments); }; -var getCorrectionsForMisspelling = function(word) { +var getCorrectionsForMisspelling = function() { ensureDefaultSpellCheck(); - return defaultSpellcheck.getCorrectionsForMisspelling(word); + return defaultSpellcheck.getCorrectionsForMisspelling.apply(defaultSpellcheck, arguments); }; module.exports = { From 08f733fc208d9aafd02d5f55466ca7fd86321863 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 11 Feb 2015 13:38:03 -0800 Subject: [PATCH 10/10] Current dir is default dict directory --- src/main.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cc b/src/main.cc index b886403..6a9f59a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -28,7 +28,7 @@ class Spellchecker : public ObjectWrap { Spellchecker* that = ObjectWrap::Unwrap(args.Holder()); std::string language = *String::Utf8Value(args[0]); - std::string directory = ""; + std::string directory = "."; if (args.Length() > 1) { directory = *String::Utf8Value(args[1]); }