pbek / QOwnNotes

QOwnNotes is a plain-text file notepad and todo-list manager with Markdown support and Nextcloud / ownCloud integration.
https://www.qownnotes.org/
GNU General Public License v2.0
4.61k stars 409 forks source link

Spell Checking? #125

Closed praxiq closed 4 years ago

praxiq commented 8 years ago

This would be really useful. Perhaps with qtspell?

pbek commented 8 years ago

Thank you for your suggestion. I already have spell checking on my todo list. So far I had hunspell on the radar, I will take a look at qtspell as well, thanks for link! The challenge is to make it work on all platforms...

eemantsal commented 8 years ago

Hi, pbek.

Excuse my ignorance, but couldn't you app just use the system's spell checker? AFAIK most apps don't use their own spelling corrector, right? Even Dolphin corrects your spelling when introducing folder and file names, but it doesn't implement a special backend, just calls the desktop to do the checks, no? I ask this because I'm a bit tired of all those hunspell, aspell, ispell, LanguageTool, whatever. Why not simply respect what the user's desktop is using instead confusing us? Besides, this way, if I introduce a new word in, say, Kmail, I'd have it available for QOwnNotes and any other app that uses KDE's spell corrector; having several checkers doesn't imply a different dictionary for each?

pbek commented 8 years ago

Dolphin and KMail are KDE apps, QOwnNotes is a Qt app and can't build upon the KDE libraries for spell checking in text edit boxes... But there are solutions for Qt, they are just not easy peasy to integrate, keeping compatibility with all OSes...

sandsmark commented 8 years ago

As the maintainer of Sonnet I can highly recommend it. :-)

It only depends on qtbase, and supports multiple spell checking backends (e. g. a native one on OS X, not yet one for Windows, unfortunately) and automatic language detection.

The API should be pretty straightforward: http://api.kde.org/frameworks-api/frameworks5-apidocs/sonnet/html/index.html

pbek commented 8 years ago

Thank you very much, @sandsmark for letting me know! Without having it tested yet... it's looking great! What's the minimum Qt requirement? Higher than Qt 5.3? What would it take to get Windows support (wouldn't it be great to have KDE apps on Windows? 😄 ) like https://github.com/manisandro/qtspell?

It also supports automated language detection, based on a combination of different algorithms.

Does it by any chances also support detection and checking for different languages in the same text edit?

sandsmark commented 8 years ago

What's the minimum Qt requirement? Higher than Qt 5.3?

Seems like minimum required version now is set at 5.4, but I think it should work with 5.3 just by changing the minimum version here: https://github.com/KDE/sonnet/blob/master/CMakeLists.txt#L18

The increase to requiring 5.4 seems to be just a "global" change for all Frameworks.

What would it take to get Windows support (wouldn't it be great to have KDE apps on Windows? :smile: ) like https://github.com/manisandro/qtspell?

It already supports Windows, but then it requires you to use a third party library like for example Aspell or Hunspell (which is used by LibreOffice, OpenOffice.org, Mozilla Firefox 3 & Thunderbird, Google Chrome, Mac OS X, InDesign, Opera). Nick Shaforostoff has already done some nice work to improve the functionality on Windows, however, so it should be pretty nice to use: https://github.com/KDE/sonnet/commit/4a61bc24836aeff42bc53284d890bd41b1700376

What I meant was that I want to eventually support using the "native" spell checking facilities on Windows without having to rely on an extra library, like we do for OS X: https://github.com/KDE/sonnet/commit/97a172f3312b59215764542f4d373ee538b4071b

Does it by any chances also support detection and checking for different languages in the same text edit?

Yes, it supports using several languages in the same text edit, it only assumes one language per sentence in the text. If you disable the automatic language detection however, there's only one language per text edit (it doesn't support changing the language manually for individual parts of text).

sandsmark commented 8 years ago

Btw, the .pro files (https://github.com/KDE/sonnet/blob/master/src/core/sonnet-core.pro, https://github.com/KDE/sonnet/blob/master/src/plugins/hunspell/hunspell.pro and https://github.com/KDE/sonnet/blob/master/src/ui/sonnet-ui.pro) don't have a minimum Qt version set, so it is probably easier to use qmake for building with 5.3.

pbek commented 8 years ago

Thank you for your explanations! I only kept the minimum requirement of Qt 5.3 for Debian 8. How are you guys handling that? I would love to drop it too to maybe some day be able to integrate QtWebEngine for the preview. The QTextEdit has too many rendering bugs... But QtWebEngine needs QML, Quick, OpenGL and at least Qt 5.4. That's a bit of a bummer... (and has still no printing support)

sandsmark commented 8 years ago

The explanation of the Qt version requirements are described here: https://community.kde.org/Frameworks/Policies#Frameworks_Qt_requirements

But I just test compiled Sonnet with qmake on debian stable, and it builds fine (just missed enabling c++11 support for sonnet-core, which I just committed a fix for: https://github.com/KDE/sonnet/commit/9671ba9ea8e9b3fb320e49003636a326ec064541).

pbek commented 8 years ago

For instance, once Qt 5.6 was released, the minimum required Qt version changed from Qt 5.3 to Qt 5.4, i.e. the three supported Qt versions became 5.4, 5.5 and 5.6

And the rest of KDE... how is Debian 8 handled there?

sandsmark commented 8 years ago

I don't know, tbh.

pbek commented 8 years ago

Thank you anyway, I will evaluate Sonnet in the future, it sounds very promising for QOwnNotes!

pbek commented 8 years ago

@sandsmark, do you know of a KDE and a Qt (non-KDE) app that is using Sonnet with automatic language detection, so I can see it in action (and in source code)?

sandsmark commented 8 years ago

Quassel is the first thing that comes to mind: https://github.com/quassel/quassel/commit/8cece06596c290d69c1f32b7221c796437f5fabb

sandsmark commented 8 years ago

Kate (the editor) also uses it.

pbek commented 8 years ago

thank you, also any non-KDE apps?

pbek commented 8 years ago

And does Sonnet require KDE, @sandsmark? I see some KDE references in the CMakeLists.txt file.. Do you have any idea to also make it work on qmake?

sandsmark commented 8 years ago

No KDE dependencies (Quassel is a "pure" Qt application, with optional KDE integration), and you can use qmake as well if you don't want to use cmake. See https://github.com/KDE/sonnet/blob/master/src/plugins/hunspell/hunspell.pro https://github.com/KDE/sonnet/blob/master/src/core/sonnet-core.pro and https://github.com/KDE/sonnet/blob/master/src/ui/sonnet-ui.pro

pbek commented 8 years ago

Nice, I need both cmake and qmake, because I use CLion (cmake) and Qt Creator (qmake) ;) The build systems are using qmake as well.

sandsmark commented 8 years ago

When you install it it installs .pri files as well, if you want to use it like a normal Qt library (put «QT += SonnetCore SonnetUi» in your own .pro file).

Otherwise you can just use the .pro files I linked above to link it in statically.

pbek commented 8 years ago

Thank you for your hint, I will try that out.

pbek commented 8 years ago

@sandsmark, http://api.kde.org/frameworks-api/frameworks5-apidocs/sonnet/html/index.html currently returns a 404 error message

sandsmark commented 8 years ago

Sorry, someone is apparently doing some restructuring: http://api.kde.org/frameworks-api/frameworks5-apidocs/frameworks/sonnet/html/index.html

pbek commented 8 years ago

Ah, thank you. 3 times api and 3 times framework, someone made sure those keywords are covered! :)

pbek commented 8 years ago

@sandsmark I would so love to integrate Sonnet into QOwnNotes, but I don't even get Sonnet to build on my Ubuntu (Neon) development machine...

Is there a way to create a amalgamation build of Sonnet, so I only end up with a large c++ and header file to include?

Like we have for botan: https://botan.randombit.net/manual/building.html#the-amalgamation-build https://github.com/pbek/QOwnNotes/tree/develop/src/libraries/botan

That would help me tremendously... And I guess I would need the same for Aspell or Hunspell, to make it run on Linux and Windows, don't I?

sandsmark commented 8 years ago

What error do you get when trying to build?

As for amalgation, I've never tried it for anything, but I guess it should be possible, by just catting together files.

pbek commented 8 years ago

So far I managed to build the Sonnet core and ui with your .pro files.

My intention is to place Sonnet in the library folder:

and then to get Sonnet into the project files:

I need to be able to build QOwnNotes under Linux with cmake and on Linux / OS X / Windows with qmake.

So I included this in QOwnNotes.pro:

SOURCES += libraries/sonnet/src/core/loader.cpp \
           libraries/sonnet/src/core/client.cpp \
           libraries/sonnet/src/core/spellerplugin.cpp \
           libraries/sonnet/src/core/speller.cpp \
           libraries/sonnet/src/core/settings.cpp \
           libraries/sonnet/src/core/backgroundchecker.cpp \
           libraries/sonnet/src/core/guesslanguage.cpp \
           libraries/sonnet/src/core/textbreaks.cpp \
           libraries/sonnet/src/core/tokenizer.cpp \
           libraries/sonnet/src/core/languagefilter.cpp \
           libraries/sonnet/src/ui/highlighter.cpp

HEADERS += libraries/sonnet/src/core/client_p.h \
           libraries/sonnet/src/core/loader_p.h \
           libraries/sonnet/src/ui/highlighter.h

unix:system("touch sonnetcore_export.h")
win32:system("type nul > sonnetcore_export.h")

I get this error message when I compile:

In file included from ../src/libraries/sonnet/src/core/loader.cpp:21:0:
../src/libraries/sonnet/src/core/loader_p.h:43:32: error: expected initializer before ':' token
 class SONNETCORE_EXPORT Loader : public QObject
                                ^
../src/libraries/sonnet/src/core/loader_p.h:45:20: error: expected '}' before end of line
../src/libraries/sonnet/src/core/loader_p.h:45:20: error: expected declaration before end of line
Makefile:1670: recipe for target 'loader.o' failed
pbek commented 8 years ago

I found out that I missed the DEFINES:

DEFINES += SONNETUI_EXPORT=""
DEFINES += SONNETCORE_EXPORT=""
DEFINES += INSTALLATION_PLUGIN_PATH=""
DEFINES += SONNET_STATIC

But now I have a naming clash with src/libraries/sonnet/src/ui/highlighter.cpp and src/libraries/qmarkdowntextedit/highlighter.cpp.

If I comment it out I get:

loader.o: In function `Sonnet::Loader::loadPlugin(QString const&)':
/home/omega/Code/_internal/QOwnNotes/build-QOwnNotes-Desktop-Debug/../src/libraries/sonnet/src/core/loader.cpp:305: undefined reference to `HunspellClient::HunspellClient(QObject*)'
Makefile:461: recipe for target 'QOwnNotes' failed
backgroundchecker.o: In function `BackgroundCheckerPrivate::checkNext()':
/home/omega/Code/_internal/QOwnNotes/build-QOwnNotes-Desktop-Debug/../src/libraries/sonnet/src/core/backgroundchecker.cpp:50: undefined reference to `BackgroundCheckerPrivate::misspelling(QString const&, int)'
/home/omega/Code/_internal/QOwnNotes/build-QOwnNotes-Desktop-Debug/../src/libraries/sonnet/src/core/backgroundchecker.cpp:70: undefined reference to `BackgroundCheckerPrivate::done()'
backgroundchecker.o: In function `Sonnet::BackgroundChecker::BackgroundChecker(QObject*)':
/home/omega/Code/_internal/QOwnNotes/build-QOwnNotes-Desktop-Debug/../src/libraries/sonnet/src/core/backgroundchecker.cpp:75: undefined reference to `vtable for Sonnet::BackgroundChecker'
backgroundchecker.o: In function `Sonnet::BackgroundChecker::BackgroundChecker(Sonnet::Speller const&, QObject*)':
/home/omega/Code/_internal/QOwnNotes/build-QOwnNotes-Desktop-Debug/../src/libraries/sonnet/src/core/backgroundchecker.cpp:85: undefined reference to `vtable for Sonnet::BackgroundChecker'
/home/omega/Code/_internal/QOwnNotes/build-QOwnNotes-Desktop-Debug/../src/libraries/sonnet/src/core/backgroundchecker.cpp:89: undefined reference to `Sonnet::BackgroundChecker::misspelling(QString const&, int)'
/home/omega/Code/_internal/QOwnNotes/build-QOwnNotes-Desktop-Debug/../src/libraries/sonnet/src/core/backgroundchecker.cpp:89: undefined reference to `BackgroundCheckerPrivate::misspelling(QString const&, int)'
/home/omega/Code/_internal/QOwnNotes/build-QOwnNotes-Desktop-Debug/../src/libraries/sonnet/src/core/backgroundchecker.cpp:91: undefined reference to `BackgroundCheckerPrivate::done()'
backgroundchecker.o: In function `Sonnet::BackgroundChecker::~BackgroundChecker()':
/home/omega/Code/_internal/QOwnNotes/build-QOwnNotes-Desktop-Debug/../src/libraries/sonnet/src/core/backgroundchecker.cpp:94: undefined reference to `vtable for Sonnet::BackgroundChecker'
backgroundchecker.o: In function `Sonnet::BackgroundChecker::slotEngineDone()':
/home/omega/Code/_internal/QOwnNotes/build-QOwnNotes-Desktop-Debug/../src/libraries/sonnet/src/core/backgroundchecker.cpp:171: undefined reference to `Sonnet::BackgroundChecker::done()'
backgroundchecker.o: In function `BackgroundCheckerPrivate::BackgroundCheckerPrivate()':
/home/omega/Code/_internal/QOwnNotes/build-QOwnNotes-Desktop-Debug/../src/libraries/sonnet/src/core/backgroundchecker_p.h:36: undefined reference to `vtable for BackgroundCheckerPrivate'
backgroundchecker.o: In function `QMetaObject::Connection QObject::connect<void (BackgroundCheckerPrivate::*)(QString const&, int), void (Sonnet::BackgroundChecker::*)(QString const&, int)>(QtPrivate::FunctionPointer<void (BackgroundCheckerPrivate::*)(QString const&, int)>::Object const*, void (BackgroundCheckerPrivate::*)(QString const&, int), QtPrivate::FunctionPointer<void (Sonnet::BackgroundChecker::*)(QString const&, int)>::Object const*, void (Sonnet::BackgroundChecker::*)(QString const&, int), Qt::ConnectionType)':
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:239: undefined reference to `BackgroundCheckerPrivate::staticMetaObject'
backgroundchecker.o: In function `QMetaObject::Connection QObject::connect<void (BackgroundCheckerPrivate::*)(), void (Sonnet::BackgroundChecker::*)()>(QtPrivate::FunctionPointer<void (BackgroundCheckerPrivate::*)()>::Object const*, void (BackgroundCheckerPrivate::*)(), QtPrivate::FunctionPointer<void (Sonnet::BackgroundChecker::*)()>::Object const*, void (Sonnet::BackgroundChecker::*)(), Qt::ConnectionType)':
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:239: undefined reference to `BackgroundCheckerPrivate::staticMetaObject'

@sandsmark, do you have any suggestions?

sandsmark commented 8 years ago

Sorry for not coming back to you earlier, but why is it a problem that files in different folders have the same name?

Do you have this code in a branch I can try?

pbek commented 8 years ago

Thank you for helping, I will see that I can get a branch together.

pbek commented 8 years ago

@sandsmark, I renamed my highlighter files and created a branch for you to test. Sonnet is included as git submodule.

https://github.com/pbek/QOwnNotes/tree/feature/sonnet

Don't forget to do a git submodule update --init. These instructions should still work (beside the branch): http://www.qownnotes.org/installation#building

Thanks a lot for your help!

pbek commented 8 years ago

@sandsmark, did you already have time for taking a look at the branch?

Maboroshy commented 8 years ago

I'm also interested in this feature. If you would make a build instruction for dummies or an Arch pkg I could test it too. I'm not into building yet.

vcg3rd commented 7 years ago

I too want to see spell check; however, until then it seems like a work-around would be to open in external editor (in my case Xed), spell check and save. However, when I do that the changes don't show in QOwnNotes even if I go to another note and come back. I suspect it will work if I close QON and reopen, but that is not a good solution. Something like detecting changes (the way Xed, Sublime, etc) do and asking to reload, or Ctrl-x Ctrl-v in Emacs maybe

pbek commented 7 years ago

QOwnNotes detects external file changes if your system permits it (has enough open file handlers left) and you didn't run that off in the settings. You can press Ctrl + Shift + R to manually reload the note folder.

QuAzI commented 7 years ago

Maybe Hunspell is more easy way to use spellcheck with Qt application?

pbek commented 7 years ago

Why do you think so, @QuAzI?

QuAzI commented 7 years ago

I use it in one simple project and it was very simple as I remember. Please check https://wiki.qt.io/Spell-Checking-with-Hunspell One trouble: to search good *.dic files for different languages.

pbek commented 7 years ago

Thank you, I already had this link on my list. On Linux Sonnet uses hunspell as backend (as far as I remember), but on macOS and Windows it uses the native spell checkers, which is great. It needs to work with both qmake and cmake and work on all platforms...

borghal commented 6 years ago

Please add spell checking, it's a major showstopper for me.

pbek commented 6 years ago

I'd love too, but so far I had no success integrating a solution that works on all platforms.

borghal commented 6 years ago

Thank you for the effort!

maras commented 6 years ago

First of all, I want to thank you for this wonderful program. I searched program for easy creating and organising my notes like nvALT that could work on Linux and Windows. There was some candidates, but they had some serious drawbacks. QOwnNotes have all the strong points of other similar software and have minor drawbacks. Apart one serious defect - spellchecker. Spellcheck is the most needed feature in QOwnNotes for me and, I think, for those of us who use it as a part of text creation workflow (in my case - creation of humanities texts in Zettelkasten method). It is needed more than any other planned feature. I haven't knowledge in programming, but I know some qt programs, that is working in all major OS and have spellcheck, like TexWorks https://github.com/TeXworks/texworks or TexStudio https://www.texstudio.org/ Maybe they can inspire how to add spellcheck to this wonderful program?

pbek commented 6 years ago

Thank you for your kind words. The current problem is to get the library work on all platforms with all build systems on qmake and cmake, which didn't work out so far...

BlackCanopus commented 6 years ago

I wanted to suggest SpellChecking too, but since it's already on your ToDo list, I'll just have to say I really really liked your note editor and I hope it grows. It's incredible.

pbek commented 6 years ago

Thank you for your kind words. My magic wand that developers usually use to conjure new features out of thin air is currently broken. 😿

ghost commented 6 years ago

spell checking seems easy to me : have a list of words (dictionary) compare text with list entries - mark when there is no match (add grammar) suggest the closest similar string to items in list

I am quite resistent to writing errorfree scripts but may be I can learn that some day . . .

ghost commented 6 years ago

How long can it take to learn the tools to create it?

pbek commented 6 years ago

Spell checking isn't that easy any more... There are different libraries on different platforms that are hard to integrate. And the language should also be detected automatically...

ghost commented 6 years ago

Would there be need for an own language detector?