• 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
  • tools
  • nepomukshow
uri.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  *
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) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  */
20 
21 #include "uri.h"
22 #include <KUrl>
23 
24 #include <Soprano/Node>
25 #include <Soprano/Model>
26 #include <Soprano/QueryResultIterator>
27 #include <Soprano/Vocabulary/NAO>
28 
29 #include "resourcemanager.h"
30 
31 using namespace Soprano::Vocabulary;
32 
33 namespace Nepomuk2 {
34 
35 QHash<QString, QString> s_prefixHash;
36 
37 QHash<QString, QString> createPrefixHash() {
38  QString query = QString::fromLatin1("select ?g ?abr where { ?r %1 ?g ; %2 ?abr . }")
39  .arg( Soprano::Node::resourceToN3( NAO::hasDefaultNamespace() ),
40  Soprano::Node::resourceToN3( NAO::hasDefaultNamespaceAbbreviation() ) );
41 
42  Soprano::Model* model = Nepomuk2::ResourceManager::instance()->mainModel();
43  Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
44 
45  QHash<QString, QString> hash;
46  while( it.next() ) {
47  hash.insert( it[0].toString(), it[1].toString() );
48  }
49 
50  return hash;
51 }
52 
53 Uri::Uri(const QUrl& uri)
54 {
55  // FIXME: Not particularly thread safe
56  if( s_prefixHash.isEmpty() )
57  s_prefixHash = createPrefixHash();
58 
59  init( uri );
60 }
61 
62 Uri::~Uri()
63 {
64 
65 }
66 
67 void Uri::init(const QUrl& uri)
68 {
69  m_uri = uri;
70  m_prefix.clear();
71  m_suffix.clear();
72  m_n3.clear();
73 
74  QString uriString = uri.toString();
75 
76  int index = uriString.indexOf('#');
77  if( index != -1 ) {
78  m_prefix = s_prefixHash.value( uriString.mid( 0, index+1 ) );
79  m_suffix = uriString.mid( index+1 );
80 
81  m_n3 = m_prefix + QLatin1Char(':') + m_suffix;
82  return;
83  }
84 
85  if( uriString.startsWith("http://purl.org/dc/") ) {
86  m_prefix = "purl";
87  m_suffix = KUrl(m_uri).fileName();
88 
89  m_n3 = m_prefix + QLatin1Char(':') + m_suffix;
90  return;
91  }
92 
93  m_n3 = Soprano::Node::resourceToN3( m_uri );
94 }
95 
96 QString Uri::prefix()
97 {
98  return m_prefix;
99 }
100 
101 QString Uri::suffix()
102 {
103  return m_suffix;
104 }
105 
106 QString Uri::toN3()
107 {
108  return m_n3;
109 }
110 
111 }
Nepomuk2::s_prefixHash
QHash< QString, QString > s_prefixHash
Definition: uri.cpp:35
uri.h
QHash
Nepomuk2::ResourceManager::instance
static ResourceManager * instance()
Definition: resourcemanager.cpp:270
resourcemanager.h
Nepomuk2::createPrefixHash
QHash< QString, QString > createPrefixHash()
Definition: uri.cpp:37
Nepomuk2::ResourceManager::mainModel
Soprano::Model * mainModel()
Retrieve the main data storage model.
Definition: resourcemanager.cpp:363
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