[191] | 1 | /**********************************************************************
|
---|
| 2 | ** Copyright (C) 2000-2007 Trolltech ASA. All rights reserved.
|
---|
| 3 | **
|
---|
| 4 | ** This file is part of the Qt Assistant.
|
---|
| 5 | **
|
---|
| 6 | ** This file may be distributed and/or modified under the terms of the
|
---|
| 7 | ** GNU General Public License version 2 as published by the Free Software
|
---|
| 8 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 9 | ** packaging of this file.
|
---|
| 10 | **
|
---|
| 11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
| 12 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
| 13 | ** Agreement provided with the Software.
|
---|
| 14 | **
|
---|
| 15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
| 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 17 | **
|
---|
| 18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
| 19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
| 20 | ** information about Qt Commercial License Agreements.
|
---|
| 21 | **
|
---|
| 22 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
| 23 | ** not clear to you.
|
---|
| 24 | **
|
---|
| 25 | **********************************************************************/
|
---|
| 26 |
|
---|
| 27 | #ifndef INDEX_H
|
---|
| 28 | #define INDEX_H
|
---|
| 29 |
|
---|
| 30 | #include <qstringlist.h>
|
---|
| 31 | #include <qdict.h>
|
---|
| 32 | #include <qdatastream.h>
|
---|
| 33 | #include <qobject.h>
|
---|
| 34 |
|
---|
| 35 | struct Document {
|
---|
| 36 | Document( int d, int f ) : docNumber( d ), frequency( f ) {}
|
---|
| 37 | Document() : docNumber( -1 ), frequency( 0 ) {}
|
---|
| 38 | bool operator==( const Document &doc ) const {
|
---|
| 39 | return docNumber == doc.docNumber;
|
---|
| 40 | }
|
---|
| 41 | bool operator<( const Document &doc ) const {
|
---|
| 42 | return frequency > doc.frequency;
|
---|
| 43 | }
|
---|
| 44 | bool operator<=( const Document &doc ) const {
|
---|
| 45 | return frequency >= doc.frequency;
|
---|
| 46 | }
|
---|
| 47 | bool operator>( const Document &doc ) const {
|
---|
| 48 | return frequency < doc.frequency;
|
---|
| 49 | }
|
---|
| 50 | Q_INT16 docNumber;
|
---|
| 51 | Q_INT16 frequency;
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 | QDataStream &operator>>( QDataStream &s, Document &l );
|
---|
| 55 | QDataStream &operator<<( QDataStream &s, const Document &l );
|
---|
| 56 |
|
---|
| 57 | class Index : public QObject
|
---|
| 58 | {
|
---|
| 59 | Q_OBJECT
|
---|
| 60 | public:
|
---|
| 61 | struct Entry {
|
---|
| 62 | Entry( int d ) { documents.append( Document( d, 1 ) ); }
|
---|
| 63 | Entry( QValueList<Document> l ) : documents( l ) {}
|
---|
| 64 | QValueList<Document> documents;
|
---|
| 65 | };
|
---|
| 66 | struct PosEntry {
|
---|
| 67 | PosEntry( int p ) { positions.append( p ); }
|
---|
| 68 | QValueList<uint> positions;
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 | Index( const QString &dp, const QString &hp );
|
---|
| 72 | Index( const QStringList &dl, const QString &hp );
|
---|
| 73 | void writeDict();
|
---|
| 74 | void readDict();
|
---|
| 75 | int makeIndex();
|
---|
| 76 | QStringList query( const QStringList&, const QStringList&, const QStringList& );
|
---|
| 77 | QString getDocumentTitle( const QString& );
|
---|
| 78 | void setDictionaryFile( const QString& );
|
---|
| 79 | void setDocListFile( const QString& );
|
---|
| 80 | void setDocList( const QStringList & );
|
---|
| 81 |
|
---|
| 82 | signals:
|
---|
| 83 | void indexingProgress( int );
|
---|
| 84 |
|
---|
| 85 | private slots:
|
---|
| 86 | void setLastWinClosed();
|
---|
| 87 |
|
---|
| 88 | private:
|
---|
| 89 | void setupDocumentList();
|
---|
| 90 | void parseDocument( const QString&, int );
|
---|
| 91 | void insertInDict( const QString&, int );
|
---|
| 92 | void writeDocumentList();
|
---|
| 93 | void readDocumentList();
|
---|
| 94 | QStringList getWildcardTerms( const QString& );
|
---|
| 95 | QStringList split( const QString& );
|
---|
| 96 | QValueList<Document> setupDummyTerm( const QStringList& );
|
---|
| 97 | bool searchForPattern( const QStringList&, const QStringList&, const QString& );
|
---|
| 98 | void buildMiniDict( const QString& );
|
---|
| 99 | QStringList docList;
|
---|
| 100 | QDict<Entry> dict;
|
---|
| 101 | QDict<PosEntry> miniDict;
|
---|
| 102 | uint wordNum;
|
---|
| 103 | QString docPath;
|
---|
| 104 | QString dictFile, docListFile;
|
---|
| 105 | bool alreadyHaveDocList;
|
---|
| 106 | bool lastWindowClosed;
|
---|
| 107 | };
|
---|
| 108 |
|
---|
| 109 | struct Term {
|
---|
| 110 | Term( const QString &t, int f, QValueList<Document> l )
|
---|
| 111 | : term( t ), frequency( f ), documents( l ) {}
|
---|
| 112 | QString term;
|
---|
| 113 | int frequency;
|
---|
| 114 | QValueList<Document>documents;
|
---|
| 115 | };
|
---|
| 116 |
|
---|
| 117 | class TermList : public QPtrList<Term>
|
---|
| 118 | {
|
---|
| 119 | public:
|
---|
| 120 | TermList() : QPtrList<Term>() {}
|
---|
| 121 | int compareItems( QPtrCollection::Item i1, QPtrCollection::Item i2 );
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 | #endif
|
---|