hdt 3.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/deps/hdt-it/.cproject +42 -0
  2. package/deps/hdt-it/.project +27 -0
  3. package/deps/hdt-it/Camera.cpp +249 -0
  4. package/deps/hdt-it/Camera.h +77 -0
  5. package/deps/hdt-it/Color.cpp +157 -0
  6. package/deps/hdt-it/Color.h +49 -0
  7. package/deps/hdt-it/Info.plist +58 -0
  8. package/deps/hdt-it/LICENSE +280 -0
  9. package/deps/hdt-it/README.md +73 -0
  10. package/deps/hdt-it/StopWatch.cpp +170 -0
  11. package/deps/hdt-it/StopWatch.hpp +61 -0
  12. package/deps/hdt-it/abouthdt.cpp +14 -0
  13. package/deps/hdt-it/abouthdt.hpp +22 -0
  14. package/deps/hdt-it/abouthdt.ui +173 -0
  15. package/deps/hdt-it/colors.hpp +29 -0
  16. package/deps/hdt-it/constants.h +39 -0
  17. package/deps/hdt-it/createdmg.sh +72 -0
  18. package/deps/hdt-it/dictionarysuggestions.cpp +186 -0
  19. package/deps/hdt-it/dictionarysuggestions.hpp +39 -0
  20. package/deps/hdt-it/doc/hdtit.png +0 -0
  21. package/deps/hdt-it/doc/manual.html +88 -0
  22. package/deps/hdt-it/doc/matrix.png +0 -0
  23. package/deps/hdt-it/editreset.png +0 -0
  24. package/deps/hdt-it/hdt-it.pro +135 -0
  25. package/deps/hdt-it/hdt-it_es.qm +0 -0
  26. package/deps/hdt-it/hdt-it_es.ts +906 -0
  27. package/deps/hdt-it/hdtcachedinfo.cpp +155 -0
  28. package/deps/hdt-it/hdtcachedinfo.hpp +38 -0
  29. package/deps/hdt-it/hdtcontroller.cpp +369 -0
  30. package/deps/hdt-it/hdtcontroller.hpp +103 -0
  31. package/deps/hdt-it/hdtico.icns +0 -0
  32. package/deps/hdt-it/hdtico.rc +1 -0
  33. package/deps/hdt-it/hdtit.cpp +400 -0
  34. package/deps/hdt-it/hdtit.hpp +78 -0
  35. package/deps/hdt-it/hdtit.ui +875 -0
  36. package/deps/hdt-it/hdtoperation.cpp +284 -0
  37. package/deps/hdt-it/hdtoperation.hpp +71 -0
  38. package/deps/hdt-it/hdtresources.qrc +7 -0
  39. package/deps/hdt-it/hdtspecform.cpp +180 -0
  40. package/deps/hdt-it/hdtspecform.hpp +38 -0
  41. package/deps/hdt-it/hdtspecform.ui +361 -0
  42. package/deps/hdt-it/hdtsummarygenerator.cpp +109 -0
  43. package/deps/hdt-it/hdtsummarygenerator.hpp +15 -0
  44. package/deps/hdt-it/hdtwinico.ico +0 -0
  45. package/deps/hdt-it/hdtwinico2.ico +0 -0
  46. package/deps/hdt-it/headermodel.cpp +174 -0
  47. package/deps/hdt-it/headermodel.hpp +38 -0
  48. package/deps/hdt-it/loading.gif +0 -0
  49. package/deps/hdt-it/logo-hdt.png +0 -0
  50. package/deps/hdt-it/logo-hdt2.png +0 -0
  51. package/deps/hdt-it/main.cpp +39 -0
  52. package/deps/hdt-it/matrixviewwidget.cpp +501 -0
  53. package/deps/hdt-it/matrixviewwidget.hpp +81 -0
  54. package/deps/hdt-it/myapplication.cpp +45 -0
  55. package/deps/hdt-it/myapplication.hpp +24 -0
  56. package/deps/hdt-it/predicatestatus.cpp +97 -0
  57. package/deps/hdt-it/predicatestatus.hpp +39 -0
  58. package/deps/hdt-it/qclearlineedit.cpp +48 -0
  59. package/deps/hdt-it/qclearlineedit.hpp +30 -0
  60. package/deps/hdt-it/regexmodel.cpp +132 -0
  61. package/deps/hdt-it/regexmodel.hpp +37 -0
  62. package/deps/hdt-it/resultcounter.cpp +47 -0
  63. package/deps/hdt-it/resultcounter.hpp +30 -0
  64. package/deps/hdt-it/searchresultsmodel.cpp +179 -0
  65. package/deps/hdt-it/searchresultsmodel.hpp +39 -0
  66. package/deps/hdt-it/sparqlform.cpp +27 -0
  67. package/deps/hdt-it/sparqlform.hpp +28 -0
  68. package/deps/hdt-it/sparqlform.ui +112 -0
  69. package/deps/hdt-it/sparqlmodel.cpp +155 -0
  70. package/deps/hdt-it/sparqlmodel.hpp +32 -0
  71. package/deps/hdt-it/stringutils.cpp +48 -0
  72. package/deps/hdt-it/stringutils.hpp +18 -0
  73. package/deps/hdt-it/triplecomponentmodel.cpp +146 -0
  74. package/deps/hdt-it/triplecomponentmodel.hpp +33 -0
  75. package/deps/libcds/Doxyfile +307 -0
  76. package/deps/libcds/tutorial/tutorial.pdf +0 -0
  77. package/deps/libhdt/.cproject +304 -0
  78. package/deps/libhdt/Doxyfile +1630 -0
  79. package/package.json +7 -1
  80. package/.eslintrc +0 -178
  81. package/.github/workflows/ci.yml +0 -73
  82. package/.gitmodules +0 -4
  83. package/.idea/codeStyles/Project.xml +0 -38
  84. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  85. package/.idea/hdt.iml +0 -12
  86. package/.idea/inspectionProfiles/Project_Default.xml +0 -7
  87. package/.idea/jsLinters/jshint.xml +0 -16
  88. package/.idea/modules.xml +0 -8
  89. package/.idea/vcs.xml +0 -7
  90. package/.jshintignore +0 -1
  91. package/.jshintrc +0 -10
  92. package/perf/run.js +0 -43
  93. package/replace-in-file.json +0 -5
@@ -0,0 +1,97 @@
1
+ #include "predicatestatus.hpp"
2
+
3
+ PredicateStatus::PredicateStatus(HDTController *manager) :
4
+ controller(manager), minPredicateCount(0), maxPredicateCount(0)
5
+ {
6
+ }
7
+
8
+ size_t PredicateStatus::getMinimumPredicateCount()
9
+ {
10
+ return minPredicateCount;
11
+ }
12
+
13
+ size_t PredicateStatus::getMaximumPredicateCount()
14
+ {
15
+ return maxPredicateCount;
16
+ }
17
+
18
+ bool PredicateStatus::isPredicateActive(size_t i)
19
+ {
20
+ return activePredicate[i];
21
+ }
22
+
23
+ void PredicateStatus::setPredicateActive(size_t i, bool b)
24
+ {
25
+ if(activePredicate[i]!=b) {
26
+ activePredicate[i] = b;
27
+ setMinimumPredicateCountInternal(0);
28
+ emit predicatesChanged(i,i);
29
+ }
30
+ }
31
+
32
+ void PredicateStatus::refreshAll()
33
+ {
34
+ activePredicate.clear();
35
+ if(controller->hasHDT()) {
36
+ activePredicate.resize(controller->getHDT()->getDictionary()->getNpredicates(), true);
37
+ this->maxPredicateCount = controller->getHDTCachedInfo()->getMaxPredicateCount();
38
+ setMinimumPredicateCountInternal(0);
39
+ }
40
+ }
41
+
42
+ void PredicateStatus::selectAllPredicates()
43
+ {
44
+ // cout << "selectAllPredicates" << endl;
45
+ for(size_t i=0;i<activePredicate.size();i++) {
46
+ activePredicate[i] = true;
47
+ }
48
+ emit predicatesChanged(0, activePredicate.size());
49
+ setMinimumPredicateCountInternal(0);
50
+ }
51
+
52
+ void PredicateStatus::selectNonePredicates()
53
+ {
54
+ // cout << "selectNonePredicates" << endl;
55
+ for(size_t i=0;i<activePredicate.size();i++) {
56
+ activePredicate[i] = false;
57
+ }
58
+ emit predicatesChanged(0, activePredicate.size());
59
+ setMinimumPredicateCountInternal(0);
60
+ }
61
+
62
+ void PredicateStatus::selectPredicate(size_t pred)
63
+ {
64
+ if(pred==0) {
65
+ selectAllPredicates();
66
+ return;
67
+ }
68
+
69
+ for(size_t i=0;i<activePredicate.size();i++) {
70
+ activePredicate[i] = i==(pred-1);
71
+ }
72
+ emit predicatesChanged(0, activePredicate.size());
73
+ setMinimumPredicateCountInternal(0);
74
+ emit predicateSelected(pred-1);
75
+ }
76
+
77
+ // Private, just updates the value.
78
+ void PredicateStatus::setMinimumPredicateCountInternal(int count)
79
+ {
80
+ if(count!=minPredicateCount) {
81
+ minPredicateCount = count;
82
+ emit minimumPredicateCountChanged(count);
83
+ }
84
+ }
85
+
86
+ // Public, update all activePredicate, values.
87
+ void PredicateStatus::setMinimumPredicateCount(int count)
88
+ {
89
+ if(count!=minPredicateCount) {
90
+ minPredicateCount = count;
91
+ for(size_t i=0;i<activePredicate.size();i++) {
92
+ activePredicate[i] = controller->getHDTCachedInfo()->getPredicateUsages(i)>=(size_t)count;
93
+ }
94
+ emit predicatesChanged(0, activePredicate.size());
95
+ emit minimumPredicateCountChanged(count);
96
+ }
97
+ }
@@ -0,0 +1,39 @@
1
+ #ifndef PREDICATESTATUS_HPP
2
+ #define PREDICATESTATUS_HPP
3
+
4
+ #include <QObject>
5
+ #include "hdtcontroller.hpp"
6
+
7
+ class PredicateStatus : public QObject
8
+ {
9
+ Q_OBJECT
10
+ private:
11
+ vector<bool> activePredicate;
12
+ size_t minPredicateCount;
13
+ size_t maxPredicateCount;
14
+ HDTController *controller;
15
+
16
+ void setMinimumPredicateCountInternal(int count);
17
+ public:
18
+ explicit PredicateStatus(HDTController *controller);
19
+
20
+ size_t getMinimumPredicateCount();
21
+ size_t getMaximumPredicateCount();
22
+
23
+ bool isPredicateActive(size_t i);
24
+ void setPredicateActive(size_t i, bool b);
25
+
26
+ signals:
27
+ void predicatesChanged(size_t min, size_t max);
28
+ void minimumPredicateCountChanged(size_t newval);
29
+ void predicateSelected(size_t npred);
30
+
31
+ public slots:
32
+ void refreshAll();
33
+ void selectPredicate(size_t pred);
34
+ void selectAllPredicates();
35
+ void selectNonePredicates();
36
+ void setMinimumPredicateCount(int count);
37
+ };
38
+
39
+ #endif // PREDICATESTATUS_HPP
@@ -0,0 +1,48 @@
1
+ #include "qclearlineedit.hpp"
2
+ #include <QToolButton>
3
+ #include <QStyle>
4
+
5
+ QClearLineEdit::QClearLineEdit(QWidget *parent)
6
+ : QLineEdit(parent)
7
+ {
8
+ clearButton = new QToolButton(this);
9
+ QPixmap pixmap(":/images/editreset.png");
10
+ clearButton->setIcon(QIcon(pixmap));
11
+ clearButton->setIconSize(pixmap.size());
12
+ clearButton->setCursor(Qt::ArrowCursor);
13
+ clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
14
+ clearButton->hide();
15
+ connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
16
+ connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
17
+ int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
18
+ setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(clearButton->sizeHint().width() + frameWidth + 1));
19
+ QSize msz = minimumSizeHint();
20
+ setMinimumSize(qMax(msz.width(), clearButton->sizeHint().height() + frameWidth * 2 + 2),
21
+ qMax(msz.height(), clearButton->sizeHint().height() + frameWidth * 2 + 2));
22
+
23
+ suggestions = new DictionarySuggestions(this);
24
+ }
25
+
26
+ QClearLineEdit::~QClearLineEdit()
27
+ {
28
+ delete suggestions;
29
+ delete clearButton;
30
+ }
31
+
32
+ void QClearLineEdit::resizeEvent(QResizeEvent *)
33
+ {
34
+ QSize sz = clearButton->sizeHint();
35
+ int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
36
+ clearButton->move(rect().right() - frameWidth - sz.width(),
37
+ (rect().bottom() + 1 - sz.height())/2);
38
+ }
39
+
40
+ void QClearLineEdit::updateCloseButton(const QString& text)
41
+ {
42
+ clearButton->setVisible(!text.isEmpty());
43
+ }
44
+
45
+ DictionarySuggestions * QClearLineEdit::getSuggestions()
46
+ {
47
+ return suggestions;
48
+ }
@@ -0,0 +1,30 @@
1
+ #ifndef QCLEARLINEEDIT_HPP
2
+ #define QCLEARLINEEDIT_HPP
3
+
4
+ #include <QLineEdit>
5
+
6
+ #include "dictionarysuggestions.hpp"
7
+
8
+ class QToolButton;
9
+
10
+ class QClearLineEdit: public QLineEdit
11
+ {
12
+ Q_OBJECT
13
+
14
+ public:
15
+ QClearLineEdit(QWidget *parent = 0);
16
+ ~QClearLineEdit();
17
+ DictionarySuggestions *getSuggestions();
18
+
19
+ protected:
20
+ void resizeEvent(QResizeEvent *);
21
+
22
+ private slots:
23
+ void updateCloseButton(const QString &text);
24
+
25
+ private:
26
+ QToolButton *clearButton;
27
+ DictionarySuggestions *suggestions;
28
+ };
29
+
30
+ #endif // QCLEARLINEEDIT_HPP
@@ -0,0 +1,132 @@
1
+ #include "stringutils.hpp"
2
+ #include "regexmodel.hpp"
3
+
4
+ #include <QFont>
5
+ #include <QMessageBox>
6
+
7
+ class QFont;
8
+
9
+ #include "../hdt-lib/src/dictionary/LiteralDictionary.hpp"
10
+
11
+ RegexModel::RegexModel(HDTController *manager) : hdtController(manager), numResults(0), results(NULL)
12
+ {
13
+ }
14
+
15
+ RegexModel::~RegexModel()
16
+ {
17
+ if(results!=NULL) {
18
+ free(results);
19
+ }
20
+ }
21
+
22
+ void RegexModel::setQuery(QString query)
23
+ {
24
+ if(hdtController->hasHDT()) {
25
+ hdt::LiteralDictionary *dict = dynamic_cast<hdt::LiteralDictionary *>(hdtController->getHDT()->getDictionary());
26
+ if(dict==NULL) {
27
+ QMessageBox::warning(NULL, tr("ERROR"), tr("This HDT does not support substring search"));
28
+ return;
29
+ }
30
+ if(query.length()==0) {
31
+ numResults = 0;
32
+ } else {
33
+ QByteArray arr = query.toUtf8();
34
+ numResults = dict->substringToId((uchar *)arr.data(), arr.size(), &results);
35
+ }
36
+ emit layoutChanged();
37
+ }
38
+ }
39
+
40
+ int RegexModel::rowCount(const QModelIndex &parent) const
41
+ {
42
+ return (int)numResults;
43
+ }
44
+
45
+ int RegexModel::columnCount(const QModelIndex &parent) const
46
+ {
47
+ return 2;
48
+ }
49
+
50
+ QVariant RegexModel::data(const QModelIndex &index, int role) const
51
+ {
52
+ if(results==NULL) {
53
+ return QVariant();
54
+ }
55
+
56
+ switch(role) {
57
+ case Qt::ToolTipRole:
58
+ case Qt::DisplayRole:
59
+ {
60
+ hdt::Dictionary *d = hdtController->getHDT()->getDictionary();
61
+
62
+ try {
63
+ switch(index.column()) {
64
+ case 0:
65
+ {
66
+ hdt::Triples *t = hdtController->getHDT()->getTriples();
67
+
68
+ hdt::TripleID tripleObject(0, 0, results[index.row()]);
69
+ hdt::IteratorTripleID *it = t->search(tripleObject);
70
+
71
+ int nResults = it->estimatedNumResults();
72
+ delete it;
73
+
74
+ return nResults;
75
+ }
76
+ case 1: {
77
+ return stringutils::toQString(d->idToString(results[index.row()], hdt::OBJECT).c_str());
78
+ }
79
+ }
80
+
81
+ } catch (char *e) {
82
+ cerr << "Error accesing dictionary: " << e << endl;
83
+ } catch (const char *e) {
84
+ cerr << "Error accesing dictionary: " << e << endl;
85
+ }
86
+ return QVariant();
87
+
88
+ break;
89
+ }
90
+ case Qt::FontRole:
91
+ {
92
+ static QFont font;
93
+ font.setPointSize(10);
94
+ return font;
95
+ }
96
+
97
+ }
98
+ return QVariant();
99
+ }
100
+
101
+ QVariant RegexModel::headerData(int section, Qt::Orientation orientation, int role) const
102
+ {
103
+ switch(role) {
104
+ case Qt::DisplayRole:
105
+ {
106
+ if(orientation == Qt::Horizontal) {
107
+ switch(section) {
108
+ case 0:
109
+ return tr("Triples ");
110
+ case 1:
111
+ return tr("Object Literal");
112
+ }
113
+ } else {
114
+ return QString::number(results[section]);
115
+ }
116
+ break;
117
+ }
118
+ }
119
+
120
+ return QVariant();
121
+ }
122
+
123
+ void RegexModel::updateDatasetChanged()
124
+ {
125
+ if(results==NULL) {
126
+ free(results);
127
+ }
128
+ numResults = 0;
129
+ results=NULL;
130
+
131
+ emit layoutChanged();
132
+ }
@@ -0,0 +1,37 @@
1
+ #ifndef REGEXMODEL_HPP
2
+ #define REGEXMODEL_HPP
3
+
4
+ #include <QAbstractTableModel>
5
+
6
+ #include "hdtcontroller.hpp"
7
+
8
+ class HDTController;
9
+
10
+ class RegexModel : public QAbstractTableModel
11
+ {
12
+ Q_OBJECT
13
+
14
+ private:
15
+ HDTController *hdtController;
16
+ uint32_t numResults;
17
+ uint32_t *results;
18
+
19
+ public:
20
+ explicit RegexModel(HDTController *manager);
21
+ ~RegexModel();
22
+
23
+ void setQuery(QString query);
24
+
25
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
26
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
27
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
28
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
29
+
30
+ void updateDatasetChanged();
31
+ signals:
32
+
33
+ public slots:
34
+
35
+ };
36
+
37
+ #endif // REGEXMODEL_HPP
@@ -0,0 +1,47 @@
1
+ #include "resultcounter.hpp"
2
+ #include <QtConcurrent/QtConcurrent>
3
+
4
+
5
+ ResultCounter::ResultCounter(QObject *parent, HDTController *controller) :
6
+ QObject(parent),
7
+ hdtController(controller),
8
+ iterator(NULL)
9
+ {
10
+ }
11
+
12
+ void ResultCounter::startCounting()
13
+ {
14
+ if(!hdtController->hasHDT()){
15
+ return;
16
+ }
17
+ iterator = hdtController->getHDT()->getTriples()->search(hdtController->getSearchPatternID());
18
+ shouldCancel = false;
19
+ QtConcurrent::run(this, &ResultCounter::run);
20
+ }
21
+
22
+ void ResultCounter::cancel()
23
+ {
24
+ shouldCancel = true;
25
+ }
26
+
27
+ void ResultCounter::run()
28
+ {
29
+ if(iterator==NULL) {
30
+ return;
31
+ }
32
+ StopWatch cl;
33
+ unsigned int numResults = 0;
34
+ while(!shouldCancel && iterator->hasNext()) {
35
+ iterator->next();
36
+ numResults++;
37
+
38
+ cl.stop();
39
+ if(cl.getReal()>10000) {
40
+ cl.reset();
41
+ emit numResultsChanged(numResults);
42
+ }
43
+ }
44
+ delete iterator;
45
+ iterator = NULL;
46
+ emit finished();
47
+ }
@@ -0,0 +1,30 @@
1
+ #ifndef RESULTCOUNTER_HPP
2
+ #define RESULTCOUNTER_HPP
3
+
4
+ #include <QObject>
5
+
6
+ #include <hdtcontroller.hpp>
7
+
8
+ class ResultCounter : public QObject
9
+ {
10
+ Q_OBJECT
11
+ private:
12
+ HDTController *hdtController;
13
+ hdt::IteratorTripleID *iterator;
14
+ bool shouldCancel;
15
+ public:
16
+ explicit ResultCounter(QObject *parent, HDTController *hdtController);
17
+
18
+ void run();
19
+ signals:
20
+ void numResultsChanged(int numResults);
21
+ void messageChanged(QString message);
22
+ void finished();
23
+ private slots:
24
+ void startCounting();
25
+ void cancel();
26
+ public slots:
27
+
28
+ };
29
+
30
+ #endif // RESULTCOUNTER_HPP
@@ -0,0 +1,179 @@
1
+ #include "stringutils.hpp"
2
+ #include "searchresultsmodel.hpp"
3
+ #include <QFont>
4
+
5
+ SearchResultsModel::SearchResultsModel(HDTController *view) : hdtController(view), triples(NULL)
6
+ {
7
+ this->updateResultListChanged();
8
+ }
9
+
10
+ SearchResultsModel::~SearchResultsModel()
11
+ {
12
+ if(triples!=NULL) {
13
+ delete triples;
14
+ triples = NULL;
15
+ }
16
+ }
17
+
18
+ int SearchResultsModel::rowCount(const QModelIndex &parent) const
19
+ {
20
+ // FIXME: QTableView crashes when returning more than 100 Million rows :(
21
+ return numResults > 100000000 ? 100000000 : numResults;
22
+ }
23
+
24
+ int SearchResultsModel::columnCount(const QModelIndex &parent) const
25
+ {
26
+ return 3;
27
+ }
28
+
29
+ QVariant SearchResultsModel::data(const QModelIndex &index, int role) const
30
+ {
31
+ if(triples == NULL) {
32
+ return QVariant();
33
+ }
34
+
35
+ switch(role) {
36
+ case Qt::ToolTipRole:
37
+ case Qt::DisplayRole:
38
+ {
39
+ // cerr << "SearchResultsModel.data " << index.row() << "," << index.column() << endl;
40
+ // Compiler complains that by calling findTriple we are modifying internal
41
+ // state, which is illegal due to this function being const. But we need to
42
+ // modify the currentIndex and currentTriple, so we can avoid it.
43
+ SearchResultsModel *noConstThis = const_cast<SearchResultsModel *>(this);
44
+ noConstThis->findTriple(index.row());
45
+
46
+ hdt::Dictionary *d = hdtController->getHDT()->getDictionary();
47
+
48
+ try {
49
+ switch(index.column()) {
50
+ case 0:
51
+ return stringutils::toQString(d->idToString(currentTriple->getSubject(), hdt::SUBJECT).c_str());
52
+ case 1:
53
+ return stringutils::toQString(d->idToString(currentTriple->getPredicate(), hdt::PREDICATE).c_str());
54
+ case 2:
55
+ return stringutils::toQString(d->idToString(currentTriple->getObject(), hdt::OBJECT).c_str());
56
+ }
57
+ } catch (char *e) {
58
+ cerr << "Error accesing dictionary: " << e << endl;
59
+ } catch (const char *e) {
60
+ cerr << "Error accesing dictionary: " << e << endl;
61
+ }
62
+ return QVariant();
63
+
64
+ break;
65
+ }
66
+ case Qt::FontRole:
67
+ {
68
+ static QFont font;
69
+ font.setPointSize(10);
70
+ return font;
71
+ }
72
+
73
+ }
74
+ return QVariant();
75
+ }
76
+
77
+
78
+ QVariant SearchResultsModel::headerData(int section, Qt::Orientation orientation, int role) const
79
+ {
80
+
81
+ switch(role) {
82
+ case Qt::DisplayRole:
83
+ {
84
+ if(orientation == Qt::Horizontal) {
85
+ switch(section) {
86
+ case 0:
87
+ return tr("Subject");
88
+ case 1:
89
+ return tr("Predicate");
90
+ case 2:
91
+ return tr("Object");
92
+ }
93
+ } else {
94
+ return QString::number(section+1);
95
+ }
96
+ break;
97
+ }
98
+ }
99
+
100
+ return QVariant();
101
+ }
102
+
103
+ void SearchResultsModel::updateResultListChanged() {
104
+ if(triples!=NULL) {
105
+ delete triples;
106
+ triples = NULL;
107
+ }
108
+
109
+ if(hdtController->hasHDT()) {
110
+ triples = hdtController->getHDT()->getTriples()->search(hdtController->getSearchPatternID());
111
+ if(triples->hasNext()) {
112
+ currentTriple = triples->next();
113
+ }
114
+ } else {
115
+ triples = NULL;
116
+ currentTriple = NULL;
117
+ numResults=0;
118
+ }
119
+ currentIndex = 0;
120
+ goingUp = true;
121
+ numResults = hdtController->getNumResults();
122
+
123
+ emit layoutChanged();
124
+ }
125
+
126
+ void SearchResultsModel::updateNumResultsChanged()
127
+ {
128
+ unsigned int old = numResults;
129
+ numResults = hdtController->getNumResults();
130
+
131
+ if(old!=numResults) {
132
+ #if 0
133
+ beginInsertRows(QModelIndex(), old+1, numResults);
134
+ endInsertRows();
135
+ //emit dataChanged(createIndex(old+1,0), createIndex(numResults,2));
136
+ #else
137
+ emit layoutChanged();
138
+ #endif
139
+ }
140
+ }
141
+
142
+
143
+ void SearchResultsModel::findTriple(unsigned int index)
144
+ {
145
+ if(triples == NULL) {
146
+ return;
147
+ }
148
+
149
+ if(triples->canGoTo() && abs((long int)currentIndex-(long int)index)>5) {
150
+ triples->goTo(index);
151
+ goingUp = true;
152
+ currentTriple = triples->next();
153
+ currentIndex = index;
154
+ //cerr << "Jump: " << currentIndex << " => " << *currentTriple << endl;
155
+ return;
156
+ }
157
+
158
+ while(currentIndex > index && triples->hasPrevious()) {
159
+ if(goingUp) {
160
+ // On direction changes, we need to move one extra position.
161
+ goingUp = false;
162
+ currentIndex++;
163
+ }
164
+ currentTriple = triples->previous();
165
+ currentIndex--;
166
+ }
167
+
168
+ while(currentIndex < index && triples->hasNext()) {
169
+ if(!goingUp){
170
+ // On direction changes, we need to move one extra position.
171
+ goingUp = true;
172
+ currentIndex--;
173
+ }
174
+ currentTriple = triples->next();
175
+ currentIndex++;
176
+ }
177
+
178
+ //cerr << "Access " << currentIndex << " => " << *currentTriple << endl;
179
+ }
@@ -0,0 +1,39 @@
1
+ #ifndef SEARCHRESULTSMODEL_HPP
2
+ #define SEARCHRESULTSMODEL_HPP
3
+
4
+ #include <QAbstractTableModel>
5
+
6
+ #include <SingleTriple.hpp>
7
+
8
+ #include "hdtcontroller.hpp"
9
+
10
+ class HDTController;
11
+
12
+ class SearchResultsModel : public QAbstractTableModel {
13
+ Q_OBJECT
14
+ private:
15
+ HDTController *hdtController;
16
+ hdt::IteratorTripleID *triples;
17
+ hdt::TripleID *currentTriple;
18
+ unsigned int currentIndex;
19
+ unsigned int numResults;
20
+ bool goingUp;
21
+
22
+ void findTriple(unsigned int index);
23
+
24
+ public:
25
+ SearchResultsModel(HDTController *view);
26
+ ~SearchResultsModel();
27
+
28
+ int rowCount(const QModelIndex &parent = QModelIndex()) const ;
29
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
30
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
31
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
32
+
33
+ void updateResultListChanged();
34
+ void updateNumResultsChanged();
35
+ signals:
36
+ };
37
+
38
+
39
+ #endif // SEARCHRESULTSMODEL_HPP
@@ -0,0 +1,27 @@
1
+ #include "sparqlform.hpp"
2
+ #include "ui_sparqlform.h"
3
+
4
+ #include "sparqlmodel.hpp"
5
+ #include "hdtit.hpp"
6
+
7
+ SparqlForm::SparqlForm(QWidget *parent) :
8
+ QMainWindow(parent),
9
+ ui(new Ui::SparqlForm)
10
+ {
11
+ ui->setupUi(this);
12
+
13
+ HDTit *hdtit = reinterpret_cast<HDTit *>(parent);
14
+ sparqlModel = new SparqlModel(hdtit->getManager());
15
+ ui->sparqlResultTable->setModel(sparqlModel);
16
+ }
17
+
18
+ SparqlForm::~SparqlForm()
19
+ {
20
+ delete ui;
21
+ }
22
+
23
+ void SparqlForm::on_pushButton_clicked()
24
+ {
25
+ sparqlModel->setQuery(ui->sparqlTextEdit->toPlainText());
26
+ ui->sparqlResultTable->scrollToTop();
27
+ }