• 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
standardqueries.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Nepomuk KDE project.
3  Copyright (C) 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 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 "standardqueries.h"
23 #include "filequery.h"
24 #include "comparisonterm.h"
25 #include "literalterm.h"
26 #include "andterm.h"
27 #include "orterm.h"
28 #include "negationterm.h"
29 
30 #include "nie.h"
31 #include "nfo.h"
32 #include "nie.h"
33 #include "nuao.h"
34 
35 #include <Soprano/Vocabulary/NAO>
36 
37 #include <QtCore/QDate>
38 
39 
40 Nepomuk2::Query::Query Nepomuk2::Query::standardQuery( StandardQuery query, const Term& /*subterm*/ )
41 {
42  switch( query ) {
43  case LastModifiedFilesQuery: {
44  ComparisonTerm lastModifiedTerm( Nepomuk2::Vocabulary::NIE::lastModified(), Term() );
45  lastModifiedTerm.setSortWeight( 1, Qt::DescendingOrder );
46  FileQuery lastModifiedQuery( lastModifiedTerm );
47  return lastModifiedQuery;
48  }
49 
50  case MostImportantResourcesQuery: {
51  ComparisonTerm fancyTerm( Soprano::Vocabulary::NAO::score(), Term() );
52  fancyTerm.setSortWeight( 1, Qt::DescendingOrder );
53  Query fancyQuery( fancyTerm );
54  return fancyQuery;
55  }
56 
57  case NeverOpenedFilesQuery: {
58  // there are two ways a usage count of 0 can be expressed:
59  // 1. property with value 0
60  // 2. no property at all
61  OrTerm usageCntTerm(
62  ComparisonTerm(
63  Nepomuk2::Vocabulary::NUAO::usageCount(),
64  LiteralTerm( 0 ),
65  ComparisonTerm::Equal ),
66  NegationTerm::negateTerm(
67  ComparisonTerm(
68  Nepomuk2::Vocabulary::NUAO::usageCount(),
69  Term() ) ) );
70 
71  // Before we had the data management service there was no usage count
72  // tracking. Thus, in order not to return all files we should filter
73  // out all files that were created before we started tracking usage.
74  // However, by default we only show the top 10 results. Thus, in the
75  // worst case this query will return the same as lastModifiedFilesQuery().
76  ComparisonTerm modDateTerm(
77  Nepomuk2::Vocabulary::NIE::lastModified(),
78  Term() );
79  modDateTerm.setSortWeight( 1, Qt::DescendingOrder );
80 
81  FileQuery query( usageCntTerm && modDateTerm );
82  return query;
83  }
84 
85  case ResourcesForActivityQuery: {
86  // FIXME
87  // get all resources that have some prop defined in a graph which was created in the requested activity?
88  // select distinct ?r where { graph ?g { ?r ?p ?o . } . ?g <activity> <A> . }
89  // it would be something like: MetaDataTerm( <activity>, <A> )
90  }
91  }
92 
93  return Query();
94 }
95 
96 
97 Nepomuk2::Query::Query Nepomuk2::Query::dateRangeQuery( const QDate& start, const QDate& end, DateRangeFlags dateFlags )
98 {
99  // create our range
100  const LiteralTerm dateFrom( QDateTime( start, QTime( 0,0,0 ) ) );
101  const LiteralTerm dateTo( QDateTime( end, QTime( 23, 59, 59, 999 ) ) );
102 
103  Query query;
104 
105  if( dateFlags & ModificationDate ) {
106  // include files modified in our date range
107  ComparisonTerm lastModifiedStart = Nepomuk2::Vocabulary::NIE::lastModified() > dateFrom;
108  ComparisonTerm lastModifiedEnd = Nepomuk2::Vocabulary::NIE::lastModified() < dateTo;
109  if( start.isValid() && end.isValid() )
110  query = ( lastModifiedStart && lastModifiedEnd );
111  else if( start.isValid() )
112  query = lastModifiedStart;
113  else if( end.isValid() )
114  query = lastModifiedEnd;
115  }
116 
117  if( dateFlags & ContentDate ) {
118  // include files created (as in photos taken) in our data range
119  ComparisonTerm contentCreatedStart = Nepomuk2::Vocabulary::NIE::contentCreated() > dateFrom;
120  ComparisonTerm contentCreatedEnd = Nepomuk2::Vocabulary::NIE::contentCreated() < dateTo;
121  if( start.isValid() && end.isValid() )
122  query = query || ( contentCreatedStart && contentCreatedEnd );
123  else if( start.isValid() )
124  query = query || contentCreatedStart;
125  else if( end.isValid() )
126  query = query || contentCreatedEnd;
127  }
128 
129  if( dateFlags & UsageDate ) {
130  // include files opened (and optionally modified) in our date range
131  // TODO: also take the end of the event into account
132  ComparisonTerm accessEventStart = Nepomuk2::Vocabulary::NUAO::start() > dateFrom;
133  ComparisonTerm accessEventEnd = Nepomuk2::Vocabulary::NUAO::start() < dateTo;
134  ComparisonTerm accessEventCondition( Nepomuk2::Vocabulary::NUAO::involves(), Term() );
135  if( start.isValid() && end.isValid() )
136  accessEventCondition.setSubTerm( accessEventStart && accessEventEnd );
137  else if( start.isValid() )
138  accessEventCondition.setSubTerm( accessEventStart );
139  else if( end.isValid() )
140  accessEventCondition.setSubTerm( accessEventEnd );
141  if( accessEventCondition.subTerm().isValid() )
142  query = query || accessEventCondition.inverted();
143  }
144 
145  return query;
146 }
andterm.h
Nepomuk2::Query::Term
The base class for all term types.
Definition: term.h:64
Nepomuk2::Query::SimpleTerm::setSubTerm
void setSubTerm(const Term &term)
Set the sub term to match against.
Definition: simpleterm.cpp:59
Nepomuk2::Query::ContentDate
Query for the content creation date (nie:contentCreated)
Definition: standardqueries.h:85
Nepomuk2::Query::ComparisonTerm::inverted
ComparisonTerm inverted() const
Create an inverted copy of this ComparisonTerm.
Definition: comparisonterm.cpp:552
Nepomuk2::Query::StandardQuery
StandardQuery
A set of predefined queries that can be created via standardQuery().
Definition: standardqueries.h:39
Nepomuk2::Query::ComparisonTerm::setSortWeight
void setSortWeight(int weight, Qt::SortOrder sortOrder=Qt::AscendingOrder)
Set the sort weight of this property.
Definition: comparisonterm.cpp:516
Nepomuk2::Query::ModificationDate
Query for the modification date (nie:lastModified)
Definition: standardqueries.h:80
Nepomuk2::Query::SimpleTerm::subTerm
Term subTerm() const
The sub term to match against.
Definition: simpleterm.cpp:52
negationterm.h
Nepomuk2::Query::UsageDate
Query for usage events referring to the resource.
Definition: standardqueries.h:90
standardqueries.h
Nepomuk2::Query::FileQuery
A Nepomuk desktop query specialized for file searches.
Definition: filequery.h:44
Nepomuk2::Query::ComparisonTerm
A term matching the value of a property.
Definition: comparisonterm.h:70
Nepomuk2::Query::Query
A Nepomuk desktop query.
Definition: query.h:76
Nepomuk2::Query::OrTerm
Match resource that match at least one of the sub terms.
Definition: orterm.h:43
Nepomuk2::Query::standardQuery
Query standardQuery(StandardQuery query, const Term &subterm=Term())
Create a standard query as defined by query.
Definition: standardqueries.cpp:40
Nepomuk2::Query::NeverOpenedFilesQuery
Creates a query that returns all files with a usage count of 0 sorted by descending modification date...
Definition: standardqueries.h:61
comparisonterm.h
literalterm.h
Nepomuk2::Query::ResourcesForActivityQuery
Get the resources related to a specific activity.
Definition: standardqueries.h:67
Nepomuk2::Query::dateRangeQuery
Query dateRangeQuery(const QDate &start, const QDate &end, DateRangeFlags dateFlags=AllDates)
Create a query that returns resources/files that have been modified/accessed in the range from start ...
Definition: standardqueries.cpp:97
Nepomuk2::Query::MostImportantResourcesQuery
Creates a query that returns all resources sorted by descending score (as calculated by the DataMaint...
Definition: standardqueries.h:55
orterm.h
start
void start()
Definition: ontologydownloadjob.cpp:13
Nepomuk2::Query::Term::isValid
bool isValid() const
Definition: term.cpp:78
Nepomuk2::Query::LastModifiedFilesQuery
Creates a query that returns all files sorted by descending modification date.
Definition: standardqueries.h:46
filequery.h
Nepomuk2::Query::LiteralTerm
Match literal properties via full text.
Definition: literalterm.h:86
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