[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: Patch: thesaurus using wordnet
From: Daniel Naber <daniel.naber () t-online ! de>
Date: 2001-05-06 14:46:56
[Download RAW message or body]
Hi,
here's a very unfinished patch that adds a thesaurus to KWord. Several
things need to be decided before this can go in. Also I cannot do this all
alone, but I need quite some help. Anyway, I think it's such a nice
feature that people will surely support me :-)
You need Wordnet to use this:
http://www.cogsci.princeton.edu/~wn/ (it's ~13 MB big!)
Issues:
1. Wordnet 1.6 has a bug that makes it crash often. It is very easy to fix
(see their release notes), but it is in the release and a new release is
not in sight. Working around the bug is possible but not nice (involves
parsing text output).
2. AFAIK wordnet is not part of any Linux distibution. The license looks
very liberal too me (someone please check it), so this might change once
KWord can use it?
3. I don't know anything about configure, so the patch works on my system,
but probably not on other people's configurations.
4. Integration into KWord doesn't work, because I don't know such simple
things like "get the word the cursor is over" - well, I never worked with
KWord before...
5. Several fixme's in the code. Especially the current results are
incomplete because I didn't manage to iterate over a "char **" list
without crashes. I need help with this (i.e. a fix, I already tried
everything I can think of). Also the patch needs a cleanup.
6. Currently only English is supported and you cannot just "translate"
Wordnet. However, there are data files for other languages, but with other
licenses.
7. Maybe this should not be part of KWord but part of kdelibs, similar to
KSpell? It could even be used as a stand alone app.
Please post comments and improvements. I won't get much further without
help.
Regards
Daniel
--
Daniel Naber, Paul-Gerhardt-Str. 2, 33332 Guetersloh, Germany
Tel. 05241-59371, Mobil 0170-4819674
["wordnet.diff" (text/x-c)]
Index: kwview.h
===================================================================
RCS file: /home/kde/koffice/kword/kwview.h,v
retrieving revision 1.45
diff -u -r1.45 kwview.h
--- kwview.h 2001/05/03 19:44:03 1.45
+++ kwview.h 2001/05/06 14:12:25
@@ -176,6 +176,7 @@
void formatPage();
void formatFrameSet();
+ void extraWordInfo();
void extraSpelling();
void extraAutoFormat();
void extraStylist();
@@ -353,6 +354,7 @@
KAction *actionTableUngroup;
KAction *actionTableDelete;
+ KAction *actionExtraWordInfo;
KAction *actionExtraSpellCheck;
KAction *actionExtraCreateTemplate;
Index: kwview.cc
===================================================================
RCS file: /home/kde/koffice/kword/kwview.cc,v
retrieving revision 1.155
diff -u -r1.155 kwview.cc
--- kwview.cc 2001/05/04 11:42:02 1.155
+++ kwview.cc 2001/05/06 14:12:54
@@ -58,6 +58,7 @@
#include "kwcommand.h"
#include "fontdia.h"
#include "counter.h"
+#include "wordinfo.h"
#include <koMainWindow.h>
@@ -257,6 +258,9 @@
KStdAction::find( this, SLOT( editFind() ), actionCollection(), "edit_find" );
KStdAction::replace( this, SLOT( editReplace() ), actionCollection(), \
"edit_replace" );
actionEditSelectAll = KStdAction::selectAll( this, SLOT( editSelectAll() ), \
actionCollection(), "edit_selectall" ); + (void) new KAction( i18n( "Replace by \
related word..." ), 0, + this, SLOT( extraWordInfo() ),
+ actionCollection(), "extra_wordinfo" );
actionExtraSpellCheck = KStdAction::spelling( this, SLOT( extraSpelling() ), \
actionCollection(), "extra_spellcheck" );
@@ -1621,8 +1625,18 @@
}
/*===============================================================*/
+void KWView::extraWordInfo()
+{
+ QString term = "house"; // fixme! use the word under the cursor
+ KWWordInfo *wi = new KWWordInfo(0L, "wordinfo", term, i18n("Replace \
'%1'").arg(term)); + wi->show();
+}
+
+/*===============================================================*/
void KWView::extraSpelling()
{
+
+
if (kspell) return; // Already in progress
m_spellCurrFrameSetNum = -1;
kspell = new KSpell( this, i18n( "Spell Checking" ), this, SLOT( \
spellCheckerReady() ), doc->getKSpellConfig() );
Index: Makefile.am
===================================================================
RCS file: /home/kde/koffice/kword/Makefile.am,v
retrieving revision 1.123
diff -u -r1.123 Makefile.am
--- Makefile.am 2001/05/04 15:56:46 1.123
+++ Makefile.am 2001/05/06 14:13:51
@@ -1,7 +1,7 @@
KDE_CXXFLAGS = $(USE_RTTI)
INCLUDES = $(KOFFICE_INCLUDES) -I$(top_srcdir)/lib/kformula2 \
- -I$(top_srcdir)/qt3stuff $(all_includes)
+ -I$(top_srcdir)/qt3stuff $(all_includes) -I/usr/local/wordnet1.6/include
## The part
kde_module_LTLIBRARIES = libkwordpart.la
@@ -16,10 +16,11 @@
contents.cc counter.cc stylist.cc \
border.cc resizehandles.cc kwcommand.cc \
autoformat.cc autoformatdia.cc fontdia.cc \
- variable.cc variabledlgs.cc serialletter.cc
+ variable.cc variabledlgs.cc serialletter.cc \
+ wordinfo.cc
libkwordpart_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN)
-libkwordpart_la_LIBADD = ../lib/kofficeui/libkofficeui.la \
../lib/kformula2/libkformula2.la ../qt3stuff/libqt3stuff.la -lkspell \
+libkwordpart_la_LIBADD = ../lib/kofficeui/libkofficeui.la \
../lib/kformula2/libkformula2.la ../qt3stuff/libqt3stuff.la -lkspell -lwn \
libkwordpart_la_METASOURCES = AUTO
## The kdeinit loadable module
["wordinfo.h" (text/x-c)]
/* This file is part of the KDE project
Copyright (C) 2001 Daniel Naber <daniel.naber@t-online.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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 GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef kwordinfo_h
#define kwordinfo_h
#include <qlayout.h>
#include <kdialogbase.h>
#include <kcombobox.h>
#include <qlistbox.h>
#include "defs.h"
/******************************************************************/
/* Class: KWWordInfo */
/******************************************************************/
class KWWordInfo : public KDialogBase
{
Q_OBJECT
public:
KWWordInfo( QWidget *parent, const char *name, QString term, QString caption );
protected slots:
virtual void slotUser1Clicked();
virtual void slotUser2Clicked();
virtual void slotFindTerm(int index);
virtual void slotFindTerm(const QString &term);
protected:
QVBox *layout;
KHistoryCombo *edit;
QListBox *listbox;
};
#endif
["wordinfo.cc" (text/x-c)]
/* This file is part of the KDE project
Copyright (C) 2001 Daniel Naber <daniel.naber@t-online.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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 GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
TODO (2001-05-06, dnaber):
-wordnet license okay?
-fix all the "fixme"s, especially the iteration
-wordnet 1.6 known bug -> crash (e.g. with "table")
-configure check
-return value?
*/
#include "wordinfo.moc"
// fixme: remove useless includes
#include <qwidget.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qstring.h>
#include <qlistbox.h>
#include <qvbox.h>
#include <kapp.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <kdebug.h>
#include <kcombobox.h>
#include <stdlib.h>
// get access to the wordnet C API:
extern "C" {
#include <wn.h>
}
/******************************************************************/
/* Class: KWWordInfo */
/******************************************************************/
/*================================================================*/
KWWordInfo::KWWordInfo( QWidget* parent, const char* name, QString term, QString \
caption ) : KDialogBase( parent, name, false, caption, User1|User2|Cancel, User2, \
false, i18n("Replace"), i18n("Go"))
{
if( wninit() ) {
KMessageBox::error(0L, i18n("wninit() failed. Check if wordnet 1.6 is installed \
and if $WNHOME is set.")); return;
}
connect(this, SIGNAL(user1Clicked()), this, SLOT(slotUser1Clicked()));
connect(this, SIGNAL(user2Clicked()), this, SLOT(slotUser2Clicked()));
layout = makeVBoxMainWidget();
// fixme: selecting one item from the history should immediately go there
edit = new KHistoryCombo(layout);
KCompletion *comp = edit->completionObject();
connect(edit, SIGNAL(returnPressed(const QString&)), comp, SLOT(addItem(const \
QString&))); connect(edit, SIGNAL(returnPressed(const QString&)), this, \
SLOT(slotFindTerm(const QString&))); edit->insertItem(term, 0);
listbox = new QListBox(layout);
connect(listbox, SIGNAL(selected(int)), this, SLOT(slotFindTerm(int)));
slotFindTerm(term);
setInitialSize(QSize(300, 400));
}
/*================================================================*/
void KWWordInfo::slotFindTerm(int index)
{
QString term = listbox->text(index).stripWhiteSpace();
kdDebug() << "KWWordInfo::slotFindTerm(" << index << ") -- " << term << endl;
edit->insertItem(term, 0);
edit->setCurrentItem(0);
slotFindTerm(term);
}
/*================================================================*/
void KWWordInfo::slotFindTerm(const QString &term)
{
/*
From the wordnet doc (can be deleted once we get this right):
Since the Synset structure is used to represent the synsets for both
word senses and pointers, the ptrlist and nextss fields have different
meanings depending on whether the structure is a word sense or pointer.
This can make navigation through the lists returned by findtheinfo_ds()
confusing.
Navigation through the returned list involves the following:
Following the nextss chain from the synset returned moves through the
various senses of searchstr . NULL indicates that end of the chain of
senses.
Following the ptrlist chain from a Synset structure representing a sense
traces the hierarchy of the search results for that sense. Subsequent
links in the ptrlist chain indicate the next level (up or down, depending
on the search) in the hierarchy. NULL indicates the end of the chain of
search result synsets.
If a synset pointed to by ptrlist has a value in the nextss field, it
represents another pointer of the same type at that level in the
hierarchy. For example, some noun synsets have two hypernyms. Following
this nextss pointer, and then the ptrlist chain from the Synset structure
pointed to, traces another, parallel, hierarchy, until the end is
indicated by NULL on that ptrlist chain. So, a synset representing a
pointer (versus a sense of searchstr ) having a non-NULL value in nextss
has another chain of search results linked through the ptrlist chain of
the synset pointed to by nextss .
If searchstr contains more than one base form in WordNet (as in the noun
axes , which has base forms axe and axis ), synsets representing the
search results for each base form are linked through the nextform pointer
of the Synset structure. */
listbox->clear();
QString result = "";
int count = 1;
// fixme: show waiting mouse pointer
for (int pos = 1; pos <= NUMPARTS; pos++) {
SynsetPtr ptr = findtheinfo_ds(term.latin1(), pos, 2, ALLSENSES); // 2=synonyms
QString type;
switch(pos) {
case 1: type = i18n("noun"); break;
case 2: type = i18n("verb"); break;
case 3: type = i18n("adjective"); break;
case 4: type = i18n("adverb"); break;
default: type = i18n("unknown type"); break;
}
while( ptr ) {
char **erg = ptr->words;
// fixme: iterate over the results
listbox->insertItem(i18n("Meaning %1: %2 \
(%3)").arg(count).arg(QString(*erg)).arg(type));
SynsetPtr sub_res = ptr->ptrlist;
if( sub_res ) {
char **erg_res = sub_res->words;
// fixme: iterate over the results
// fixme: replace '_'
listbox->insertItem(" " + QString(*erg_res));
}
count++;
ptr = ptr->nextss;
}
}
// fixme: show "no matches" if nothing is found
}
/*================================================================*/
void KWWordInfo::slotUser1Clicked()
{
// "Replace"
kdDebug() << "KWWordInfo::user1Clicked" << endl;
KDialogBase::slotOk(); // fixme: how to return the selected item?
}
/*================================================================*/
void KWWordInfo::slotUser2Clicked()
{
// "Go"
kdDebug() << "KWWordInfo::user2Clicked" << endl;
if( listbox->currentItem() != -1 ) {
slotFindTerm(listbox->currentItem());
} else {
slotFindTerm(edit->currentText());
}
}
_______________________________________________
Koffice-devel mailing list
Koffice-devel@master.kde.org
http://master.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic