• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • libnepomukcore
  • query
result.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Nepomuk KDE project.
3  Copyright (C) 2008-2010 Sebastian Trueg <trueg@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License version 2 as published by the Free Software Foundation.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19 
20 #include "result.h"
21 #include "variant.h"
22 
23 #include <QtCore/QSharedData>
24 
25 #include "resource.h"
26 #include "property.h"
27 
28 #include <Soprano/Node> // for qHash( QUrl() )
29 #include <Soprano/BindingSet>
30 
31 
32 class Nepomuk2::Query::Result::Private : public QSharedData
33 {
34 public:
35  Resource resource;
36  double score;
37  QHash<Types::Property, Soprano::Node> requestProperties;
38  Soprano::BindingSet additionalBindings;
39  QString excerpt;
40 };
41 
42 
43 Nepomuk2::Query::Result::Result()
44  : d( new Private() )
45 {
46 }
47 
48 
49 Nepomuk2::Query::Result::Result( const Resource& res, double score )
50  : d( new Private() )
51 {
52  d->resource = res;
53  d->score = score;
54 }
55 
56 
57 Nepomuk2::Query::Result::Result( const Result& other )
58 {
59  d = other.d;
60 }
61 
62 
63 Nepomuk2::Query::Result::~Result()
64 {
65 }
66 
67 
68 Nepomuk2::Query::Result& Nepomuk2::Query::Result::operator=( const Result& other )
69 {
70  d = other.d;
71  return *this;
72 }
73 
74 
75 double Nepomuk2::Query::Result::score() const
76 {
77  return d->score;
78 }
79 
80 
81 Nepomuk2::Resource Nepomuk2::Query::Result::resource() const
82 {
83  return d->resource;
84 }
85 
86 
87 void Nepomuk2::Query::Result::setScore( double score )
88 {
89  d->score = score;
90 }
91 
92 
93 void Nepomuk2::Query::Result::addRequestProperty( const Nepomuk2::Types::Property& property, const Soprano::Node& value )
94 {
95  d->requestProperties[property] = value;
96 }
97 
98 
99 Soprano::Node Nepomuk2::Query::Result::operator[]( const Nepomuk2::Types::Property& property ) const
100 {
101  return requestProperty( property );
102 }
103 
104 
105 Soprano::Node Nepomuk2::Query::Result::requestProperty( const Nepomuk2::Types::Property& property ) const
106 {
107  QHash<Nepomuk2::Types::Property, Soprano::Node>::const_iterator it = d->requestProperties.find( property );
108  if ( it != d->requestProperties.end() ) {
109  return *it;
110  }
111  else {
112  return Soprano::Node();
113  }
114 }
115 
116 
117 QHash<Nepomuk2::Types::Property, Soprano::Node> Nepomuk2::Query::Result::requestProperties() const
118 {
119  return d->requestProperties;
120 }
121 
122 
123 void Nepomuk2::Query::Result::setAdditionalBindings( const Soprano::BindingSet& bindings )
124 {
125  d->additionalBindings = bindings;
126 }
127 
128 
129 Soprano::BindingSet Nepomuk2::Query::Result::additionalBindings() const
130 {
131  return d->additionalBindings;
132 }
133 
134 
135 Nepomuk2::Variant Nepomuk2::Query::Result::additionalBinding( const QString& name ) const
136 {
137  return Variant::fromNode( d->additionalBindings.value(name) );
138 }
139 
140 
141 void Nepomuk2::Query::Result::setExcerpt( const QString& text )
142 {
143  d->excerpt = text;
144 }
145 
146 
147 QString Nepomuk2::Query::Result::excerpt() const
148 {
149  return d->excerpt;
150 }
151 
152 
153 bool Nepomuk2::Query::Result::operator==( const Result& other ) const
154 {
155  if ( d->resource != other.d->resource ||
156  d->score != other.d->score ) {
157  return false;
158  }
159  for ( QHash<Types::Property, Soprano::Node>::const_iterator it = d->requestProperties.constBegin();
160  it != d->requestProperties.constEnd(); ++it ) {
161  QHash<Types::Property, Soprano::Node>::const_iterator it2 = other.d->requestProperties.constFind( it.key() );
162  if ( it2 == other.d->requestProperties.constEnd() ||
163  it2.value() != it.value() ) {
164  return false;
165  }
166  }
167  for ( QHash<Types::Property, Soprano::Node>::const_iterator it = other.d->requestProperties.constBegin();
168  it != other.d->requestProperties.constEnd(); ++it ) {
169  QHash<Types::Property, Soprano::Node>::const_iterator it2 = d->requestProperties.constFind( it.key() );
170  if ( it2 == d->requestProperties.constEnd() ||
171  it2.value() != it.value() ) {
172  return false;
173  }
174  }
175  return d->additionalBindings == other.d->additionalBindings;
176 }
Nepomuk2::Query::Result::operator==
bool operator==(const Result &) const
Comparison operator.
Definition: result.cpp:153
Nepomuk2::Query::Result::requestProperties
QHash< Types::Property, Soprano::Node > requestProperties() const
Retrieve the values of the request properties.
Definition: result.cpp:117
QHash
Nepomuk2::Query::Result::additionalBinding
Variant additionalBinding(const QString &name) const
Retrieve an additional binding as returned by the query.
Definition: result.cpp:135
result.h
Nepomuk2::Variant
The Nepomuk Variant extends over QVariant by introducing direct support for Resource embedding...
Definition: variant.h:65
variant.h
Nepomuk2::Variant::fromNode
static Variant fromNode(const Soprano::Node &node)
Create a Variant object from a Soprano::Node.
Definition: variant.cpp:1364
Nepomuk2::Query::Result::operator[]
Soprano::Node operator[](const Types::Property &property) const
Retrieve value of request property property.
Definition: result.cpp:99
resource.h
Nepomuk2::Types::Property
A property is a resource of type rdf:Property which relates a domain with a range.
Definition: libnepomukcore/types/property.h:52
Nepomuk2::Query::Result::addRequestProperty
void addRequestProperty(const Types::Property &property, const Soprano::Node &value)
Add the value of a request property.
Definition: result.cpp:93
Nepomuk2::Query::Result::setExcerpt
void setExcerpt(const QString &text)
Set the excerpt from the query.
Definition: result.cpp:141
Nepomuk2::Query::Result
A single search result.
Definition: result.h:57
Nepomuk2::Query::Result::additionalBindings
Soprano::BindingSet additionalBindings() const
Retrieve the set of additional bindings as set via setAdditionalBindings().
Definition: result.cpp:129
Nepomuk2::Query::Result::Result
Result()
Create an empty result.
Definition: result.cpp:43
Nepomuk2::Query::Result::setAdditionalBindings
void setAdditionalBindings(const Soprano::BindingSet &bindings)
Set the additional bindings a query returned besides the result itself and the request properties...
Definition: result.cpp:123
Nepomuk2::Query::Result::excerpt
QString excerpt() const
An excerpt of the matched text with highlighted search words in case the query contained a full text ...
Definition: result.cpp:147
Nepomuk2::Query::Result::setScore
void setScore(double score)
Set the score of the result.
Definition: result.cpp:87
Nepomuk2::Resource
Resource is the central object type in Nepomuk.
Definition: resource.h:93
Nepomuk2::Query::Result::resource
Resource resource() const
The result resource.
Definition: result.cpp:81
Nepomuk2::Query::Result::score
double score() const
The score of the result.
Definition: result.cpp:75
Nepomuk2::Query::Result::operator=
Result & operator=(const Result &)
Assignment operator.
Definition: result.cpp:68
Nepomuk2::Query::Result::~Result
~Result()
Destructor.
Definition: result.cpp:63
Nepomuk2::Query::Result::requestProperty
Soprano::Node requestProperty(const Types::Property &property) const
Retrieve value of request property property.
Definition: result.cpp:105
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:09 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal