• 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
resourceterm.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Nepomuk KDE project.
3  Copyright (C) 2009-2012 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 Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) version 3, or any
9  later version accepted by the membership of KDE e.V. (or its
10  successor approved by the membership of KDE e.V.), which shall
11  act as a proxy defined in Section 6 of version 3 of the license.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "resourceterm.h"
23 #include "resourceterm_p.h"
24 #include "querybuilderdata_p.h"
25 #include "andterm_p.h"
26 
27 #include <Soprano/Node>
28 
29 
30 bool Nepomuk2::Query::ResourceTermPrivate::equals( const TermPrivate* other ) const
31 {
32  if ( other->m_type == m_type ) {
33  const ResourceTermPrivate* rtp = static_cast<const ResourceTermPrivate*>( other );
34  return rtp->m_resource == m_resource;
35  }
36  else {
37  return false;
38  }
39 }
40 
41 
42 QString Nepomuk2::Query::ResourceTermPrivate::toSparqlGraphPattern( const QString& varName, const TermPrivate* parentTerm, const QString& additionalFilters, QueryBuilderData* qbd ) const
43 {
44  //
45  // A negation is expressed via a filter. Since filters can only work on a "real" graph pattern
46  // we need to make sure that such a pattern exists. This can be done by searching one in a
47  // surrounding AndTerm.
48  //
49  // Why is that enough?
50  // Nested AndTerms are flattened before the SPARQL query is constructed in Query. Thus, an AndTerm can
51  // only be embedded in an OrTerm or as a child term to either a ComparisonTerm or an OptionalTerm.
52  // In both cases we need a real pattern inside the AndTerm.
53  //
54  // We use a type pattern for performance reasons. Thus, we assume that each resource has a type. This
55  // is not perfect but much faster than using a wildcard for the property. And in the end all Nepomuk
56  // resources should have a properly defined type.
57  //
58  bool haveRealTerm = false;
59  if( parentTerm && parentTerm->m_type == Term::And ) {
60  haveRealTerm = static_cast<const AndTermPrivate*>(parentTerm)->hasRealPattern();
61  }
62 
63  QString term;
64  if( !haveRealTerm ) {
65  term += QString::fromLatin1("%1 a %2 . ")
66  .arg( varName, qbd->uniqueVarName() );
67  }
68 
69  term += QString::fromLatin1("FILTER(%1=%2) . ")
70  .arg( varName,
71  Soprano::Node::resourceToN3( m_resource.uri() ) );
72 
73  term += additionalFilters;
74 
75  return term;
76 }
77 
78 
79 Nepomuk2::Query::ResourceTerm::ResourceTerm( const ResourceTerm& term )
80  : Term( term )
81 {
82 }
83 
84 
85 Nepomuk2::Query::ResourceTerm::ResourceTerm( const Nepomuk2::Resource& resource )
86  : Term( new ResourceTermPrivate() )
87 {
88  setResource( resource );
89 }
90 
91 
92 Nepomuk2::Query::ResourceTerm::~ResourceTerm()
93 {
94 }
95 
96 
97 Nepomuk2::Query::ResourceTerm& Nepomuk2::Query::ResourceTerm::operator=( const ResourceTerm& term )
98 {
99  d_ptr = term.d_ptr;
100  return *this;
101 }
102 
103 
104 Nepomuk2::Resource Nepomuk2::Query::ResourceTerm::resource() const
105 {
106  N_D_CONST( ResourceTerm );
107  return d->m_resource;
108 }
109 
110 
111 void Nepomuk2::Query::ResourceTerm::setResource( const Nepomuk2::Resource& resource )
112 {
113  N_D( ResourceTerm );
114  d->m_resource = resource;
115 }
resourceterm.h
Nepomuk2::Query::ResourceTerm::resource
Nepomuk2::Resource resource() const
The resource this term should match against.
Definition: resourceterm.cpp:104
Nepomuk2::Query::Term
The base class for all term types.
Definition: term.h:64
Nepomuk2::Query::ResourceTerm::operator=
ResourceTerm & operator=(const ResourceTerm &term)
Assignment operator.
Definition: resourceterm.cpp:97
Nepomuk2::Query::ResourceTerm::~ResourceTerm
~ResourceTerm()
Desctructor.
Definition: resourceterm.cpp:92
Nepomuk2::Query::ResourceTerm::setResource
void setResource(const Nepomuk2::Resource &resource)
Set the resource this term should match against.
Definition: resourceterm.cpp:111
Nepomuk2::Resource
Resource is the central object type in Nepomuk.
Definition: resource.h:93
Nepomuk2::Query::ResourceTerm::ResourceTerm
ResourceTerm(const ResourceTerm &term)
Copy constructor.
Definition: resourceterm.cpp:79
Nepomuk2::Query::ResourceTerm
Matches exactly one resource.
Definition: resourceterm.h:52
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 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