From 5ef3952a7657a35c5731a99814b5198827438054 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 30 Apr 2010 15:51:38 +0000 Subject: [PATCH] Added beginnings of spell checking support --- applications/present3D/CMakeLists.txt | 2 + applications/present3D/SpellChecker.cpp | 91 +++++++++++++++++++++++++ applications/present3D/SpellChecker.h | 39 +++++++++++ applications/present3D/present3D.cpp | 11 ++- 4 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 applications/present3D/SpellChecker.cpp create mode 100644 applications/present3D/SpellChecker.h diff --git a/applications/present3D/CMakeLists.txt b/applications/present3D/CMakeLists.txt index c68b78d93..09da1b1d8 100644 --- a/applications/present3D/CMakeLists.txt +++ b/applications/present3D/CMakeLists.txt @@ -5,6 +5,7 @@ SET(TARGET_SRC present3D.cpp ReadShowFile.cpp ShowEventHandler.cpp + SpellChecker.cpp ) SET(TARGET_H @@ -13,6 +14,7 @@ SET(TARGET_H PointsEventHandler.h ReadShowFile.h ShowEventHandler.h + SpellChecker.h ) IF (SDL_FOUND) diff --git a/applications/present3D/SpellChecker.cpp b/applications/present3D/SpellChecker.cpp new file mode 100644 index 000000000..97694af8a --- /dev/null +++ b/applications/present3D/SpellChecker.cpp @@ -0,0 +1,91 @@ +/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield + * + * This software is open source and may be redistributed and/or modified under + * the terms of the GNU General Public License (GPL) version 2.0. + * The full license is in LICENSE.txt file included with this distribution,. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * include LICENSE.txt for more details. +*/ + +#include +#include + +#include + +#include "SpellChecker.h" + +using namespace p3d; + +SpellChecker::SpellChecker() +{ +} + +void SpellChecker::checkP3dXml(const std::string& filename) const +{ + std::string foundFileName = osgDB::findDataFile( filename ); + if (foundFileName.empty()) return; + + std::ifstream fin(foundFileName.c_str()); + + osgDB::XmlNode::Input input; + input.attach(fin); + input.readAllDataIntoBuffer(); + + osg::ref_ptr doc = new osgDB::XmlNode; + doc->read(input); + + if (!doc) return; + + checkXml(doc.get()); +} + +void SpellChecker::checkXml(osgDB::XmlNode* node) const +{ + if (node->name=="page") checkWords(node->contents); + else if (node->name=="paragraph") checkWords(node->contents); + else if (node->name=="bullet") checkWords(node->contents); + + for(osgDB::XmlNode::Children::iterator itr = node->children.begin(); + itr != node->children.end(); + ++itr) + { + checkXml(itr->get()); + } +} + +void SpellChecker::checkWords(const std::string& words) const +{ + OSG_NOTICE<<"--"< + +namespace p3d +{ + +class SpellChecker +{ + public: + + SpellChecker(); + + void checkP3dXml(const std::string& filename) const; + void checkXml(osgDB::XmlNode* xmlNode) const; + void checkWords(const std::string& words) const; + + bool isCorrect(const std::string& word) const; + + typedef std::list WordList; + WordList suggest(const std::string& word) const; +}; + +} + +#endif diff --git a/applications/present3D/present3D.cpp b/applications/present3D/present3D.cpp index 29ccbca4b..fa051d439 100644 --- a/applications/present3D/present3D.cpp +++ b/applications/present3D/present3D.cpp @@ -44,7 +44,7 @@ #include "PointsEventHandler.h" #include "Cluster.h" #include "ExportHTML.h" - +#include "SpellChecker.h" #include #include @@ -428,6 +428,15 @@ int main( int argc, char **argv ) while (arguments.read("--clear-color",clearColor[0],clearColor[1],clearColor[2],clearColor[3])) {} + std::string filename; + if (arguments.read("--spell-check",filename)) + { + p3d::SpellChecker spellChecker; + spellChecker.checkP3dXml(filename); + return 1; + } + + // construct the viewer. osgViewer::Viewer viewer(arguments);