• 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
  • services
  • fileindexer
  • indexer
extractorplugin.cpp
Go to the documentation of this file.
1 /*
2  <one line to give the library's name and an idea of what it does.>
3  Copyright (C) 2012 Vishesh Handa <me@vhanda.in>
4  Copyright (C) 2012 Jörg Ehrichs <joerg.ehrichs@gmx.de>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 
22 #include "extractorplugin.h"
23 #include "nco.h"
24 
25 #include <KDebug>
26 
27 using namespace Nepomuk2::Vocabulary;
28 
29 namespace Nepomuk2 {
30 
31 ExtractorPlugin::ExtractorPlugin(QObject* parent): QObject(parent)
32 {
33 }
34 
35 ExtractorPlugin::~ExtractorPlugin()
36 {
37 }
38 
39 ExtractorPlugin::ExtractingCritera ExtractorPlugin::criteria()
40 {
41  return BasicMimeType;
42 }
43 
44 QStringList ExtractorPlugin::mimetypes()
45 {
46  return QStringList();
47 }
48 
49 bool ExtractorPlugin::shouldExtract(const QUrl& url, const QString& type)
50 {
51  Q_UNUSED( url );
52  return mimetypes().contains( type );
53 }
54 
55 //
56 // Helper functions
57 //
58 
59 QDateTime ExtractorPlugin::dateTimeFromString(const QString& dateString)
60 {
61  QDateTime dateTime;
62 
63  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("yyyy-MM-dd")); dateTime.setTimeSpec(Qt::UTC); }
64  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("dd-MM-yyyy")); dateTime.setTimeSpec(Qt::UTC); }
65  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("yyyy-MM")); dateTime.setTimeSpec(Qt::UTC); }
66  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("MM-yyyy")); dateTime.setTimeSpec(Qt::UTC); }
67  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("yyyy.MM.dd")); dateTime.setTimeSpec(Qt::UTC); }
68  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("dd.MM.yyyy")); dateTime.setTimeSpec(Qt::UTC); }
69  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("dd MMMM yyyy")); dateTime.setTimeSpec(Qt::UTC); }
70  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("MM.yyyy")); dateTime.setTimeSpec(Qt::UTC); }
71  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("yyyy.MM")); dateTime.setTimeSpec(Qt::UTC); }
72  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("yyyy")); dateTime.setTimeSpec(Qt::UTC); }
73  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("yy")); dateTime.setTimeSpec(Qt::UTC); }
74  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, Qt::ISODate); }
75  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("dddd d MMM yyyy h':'mm':'ss AP"));dateTime.setTimeSpec(Qt::LocalTime);}
76  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, QLatin1String("yyyy:MM:dd hh:mm:ss"));dateTime.setTimeSpec(Qt::LocalTime);}
77  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, Qt::SystemLocaleDate); dateTime.setTimeSpec(Qt::UTC);}
78  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, Qt::SystemLocaleShortDate); dateTime.setTimeSpec(Qt::UTC);}
79  if(!dateTime.isValid()) { dateTime = QDateTime::fromString(dateString, Qt::SystemLocaleLongDate); dateTime.setTimeSpec(Qt::UTC);}
80  if(!dateTime.isValid()) {
81  kWarning() << "Could not determine correct datetime format from:" << dateString;
82  return QDateTime();
83  }
84 
85  return dateTime;
86 }
87 
88 QList<SimpleResource> ExtractorPlugin::contactsFromString(const QString& string)
89 {
90  QString cleanedString = string;
91  cleanedString = cleanedString.remove( '{' );
92  cleanedString = cleanedString.remove( '}' );
93 
94  QStringList contactStrings = string.split(',', QString::SkipEmptyParts);
95  if( contactStrings.size() == 1 )
96  contactStrings = string.split(';', QString::SkipEmptyParts);
97 
98  if( contactStrings.size() == 1 )
99  contactStrings = string.split(" ft ", QString::SkipEmptyParts);
100 
101  if( contactStrings.size() == 1 )
102  contactStrings = string.split(" feat. ", QString::SkipEmptyParts);
103 
104  if( contactStrings.size() == 1 )
105  contactStrings = string.split(" feat ", QString::SkipEmptyParts);
106 
107  QList<SimpleResource> resList;
108  foreach(const QString& contactName, contactStrings) {
109  SimpleResource res;
110  res.addType( NCO::Contact() );
111  res.addProperty( NCO::fullname(), contactName.trimmed() );
112 
113  resList << res;
114  }
115 
116  return resList;
117 }
118 
119 // This number has been experimentally chosen. Virtuoso cannot handle more than this
120 // The max query size actually seems to be 2500243, but we're leaving space for the other parts
121 // of the query
122 int ExtractorPlugin::s_plainTextSize = 2490999;
123 
124 int ExtractorPlugin::maxPlainTextSize()
125 {
126  return s_plainTextSize;
127 }
128 
129 void ExtractorPlugin::resetMaxPlainTextSize()
130 {
131  s_plainTextSize = 2490999;
132 }
133 
134 void ExtractorPlugin::setMaxPlainTextSize(int size)
135 {
136  s_plainTextSize = size;
137 }
138 
139 
140 }
Nepomuk2::ExtractorPlugin::contactsFromString
static QList< SimpleResource > contactsFromString(const QString &string)
Creates a list of nco:Contacts from a list of strings which are separated by a number of different se...
Definition: extractorplugin.cpp:88
Nepomuk2::SimpleResource
Represents a snapshot of one Nepomuk resource.
Definition: simpleresource.h:46
QObject
Nepomuk2::SimpleResource::addProperty
void addProperty(const QUrl &property, const QVariant &value)
Add a property.
Definition: simpleresource.cpp:206
Nepomuk2::ExtractorPlugin::ExtractorPlugin
ExtractorPlugin(QObject *parent)
Definition: extractorplugin.cpp:31
Nepomuk2::ExtractorPlugin::criteria
virtual ExtractingCritera criteria()
Returns the critera that is being used for determining if this plugin can index the files provided to...
Definition: extractorplugin.cpp:39
Nepomuk2::ExtractorPlugin::BasicMimeType
This is a simple plugin that just has a list of mimetypes that it supports.
Definition: extractorplugin.h:76
Nepomuk2::ExtractorPlugin::maxPlainTextSize
static int maxPlainTextSize()
Virtuoso does not support streaming operators, and does not accept queries above a certain size...
Definition: extractorplugin.cpp:124
Nepomuk2::ExtractorPlugin::shouldExtract
virtual bool shouldExtract(const QUrl &url, const QString &mimeType)
By default this returns true if mimetype is in the list of mimetypes provided by the plugin...
Definition: extractorplugin.cpp:49
Nepomuk2::ExtractorPlugin::setMaxPlainTextSize
static void setMaxPlainTextSize(int size)
Definition: extractorplugin.cpp:134
Nepomuk2::ExtractorPlugin::dateTimeFromString
static QDateTime dateTimeFromString(const QString &dateString)
Tries to extract a valid date time from the string provided.
Definition: extractorplugin.cpp:59
Nepomuk2::SimpleResource::addType
void addType(const QUrl &type)
A convenience method which adds a property of type rdf:type.
Definition: simpleresource.cpp:257
Nepomuk2::ExtractorPlugin::mimetypes
virtual QStringList mimetypes()
Provide a list of mimetypes which are supported by this plugin.
Definition: extractorplugin.cpp:44
Nepomuk2::ExtractorPlugin::resetMaxPlainTextSize
static void resetMaxPlainTextSize()
Definition: extractorplugin.cpp:129
Nepomuk2::ExtractorPlugin::ExtractingCritera
ExtractingCritera
Each Plugin provides an extracting critera which determines when the plugin should be called...
Definition: extractorplugin.h:71
extractorplugin.h
Nepomuk2::ExtractorPlugin::~ExtractorPlugin
virtual ~ExtractorPlugin()
Definition: extractorplugin.cpp:35
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