• 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
  • types
ontology.cpp
Go to the documentation of this file.
1 /* This file is part of the Nepomuk-KDE libraries
2  Copyright (c) 2007 Sebastian Trueg <trueg@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
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 "ontology.h"
21 #include "ontology_p.h"
22 #include "class.h"
23 #include "property.h"
24 #include "entitymanager.h"
25 #include "resourcemanager.h"
26 
27 #include <Soprano/QueryResultIterator>
28 #include <Soprano/Model>
29 #include <Soprano/Vocabulary/NAO>
30 #include <Soprano/Vocabulary/RDFS>
31 #include <Soprano/Vocabulary/RDF>
32 #include <Soprano/Vocabulary/XMLSchema>
33 
34 #undef D
35 #define D static_cast<Nepomuk2::Types::OntologyPrivate*>( d.data() )
36 
37 Nepomuk2::Types::OntologyPrivate::OntologyPrivate( const QUrl& uri )
38  : EntityPrivate( uri ),
39  entitiesAvailable( uri.isValid() ? -1 : 0 )
40 {
41 }
42 
43 
44 void Nepomuk2::Types::OntologyPrivate::initEntities()
45 {
46  if ( entitiesAvailable < 0 ) {
47  entitiesAvailable = loadEntities() ? 1 : 0;
48  }
49 }
50 
51 
52 bool Nepomuk2::Types::OntologyPrivate::loadEntities()
53 {
54  // load classes
55  // We use a FILTER(STR(?ns)...) to support both Soprano 2.3 (with plain literals) and earlier (with only typed ones)
56  Soprano::QueryResultIterator it
57  = ResourceManager::instance()->mainModel()->executeQuery( QString("select ?c where { "
58  "graph ?g { ?c a <%1> . } . "
59  "?g <%2> ?ns . "
60  "FILTER(STR(?ns) = \"%3\") . }" )
61  .arg( Soprano::Vocabulary::RDFS::Class().toString() )
62  .arg( Soprano::Vocabulary::NAO::hasDefaultNamespace().toString() )
63  .arg( QString::fromAscii( uri.toEncoded() ) ),
64  Soprano::Query::QueryLanguageSparql );
65  while ( it.next() ) {
66  classes.append( Class( it.binding( "c" ).uri() ) );
67  }
68 
69 
70  // load properties
71  it = ResourceManager::instance()->mainModel()->executeQuery( QString("select ?p where { "
72  "graph ?g { ?p a <%1> . } . "
73  "?g <%2> ?ns . "
74  "FILTER(STR(?ns) = \"%3\") . }" )
75  .arg( Soprano::Vocabulary::RDF::Property().toString() )
76  .arg( Soprano::Vocabulary::NAO::hasDefaultNamespace().toString() )
77  .arg( QString::fromAscii( uri.toEncoded() ) ),
78  Soprano::Query::QueryLanguageSparql );
79  while ( it.next() ) {
80  properties.append( Property( it.binding( "p" ).uri() ) );
81  }
82 
83  return !it.lastError();
84 }
85 
86 
87 bool Nepomuk2::Types::OntologyPrivate::addProperty( const QUrl&, const Soprano::Node& )
88 {
89  return false;
90 }
91 
92 
93 bool Nepomuk2::Types::OntologyPrivate::addAncestorProperty( const QUrl&, const QUrl& )
94 {
95  return false;
96 }
97 
98 
99 void Nepomuk2::Types::OntologyPrivate::reset( bool recursive )
100 {
101  QMutexLocker lock( &mutex );
102 
103  if ( entitiesAvailable != -1 ) {
104  if ( recursive ) {
105  foreach( Class c, classes ) {
106  c.reset( true );
107  }
108  foreach( Property p, properties ) {
109  p.reset( true );
110  }
111  }
112  classes.clear();
113  properties.clear();
114 
115  entitiesAvailable = -1;
116  }
117 
118  EntityPrivate::reset( recursive );
119 }
120 
121 
122 
123 Nepomuk2::Types::Ontology::Ontology()
124 {
125  d = new OntologyPrivate();
126 }
127 
128 
129 Nepomuk2::Types::Ontology::Ontology( const QUrl& uri )
130 {
131  d = EntityManager::self()->getOntology( uri );
132 }
133 
134 
135 Nepomuk2::Types::Ontology::Ontology( const Ontology& other )
136  : Entity( other )
137 {
138 }
139 
140 
141 Nepomuk2::Types::Ontology::~Ontology()
142 {
143 }
144 
145 
146 Nepomuk2::Types::Ontology& Nepomuk2::Types::Ontology::operator=( const Ontology& other )
147 {
148  d = other.d;
149  return *this;
150 }
151 
152 
153 QList<Nepomuk2::Types::Class> Nepomuk2::Types::Ontology::allClasses()
154 {
155  D->initEntities();
156  return D->classes;
157 }
158 
159 
160 Nepomuk2::Types::Class Nepomuk2::Types::Ontology::findClassByName( const QString& name )
161 {
162  D->initEntities();
163  for ( QList<Class>::const_iterator it = D->classes.constBegin();
164  it != D->classes.constEnd(); ++it ) {
165  const Class& c = *it;
166  if ( c.name() == name ) {
167  return c;
168  }
169  }
170 
171  return Class();
172 }
173 
174 
175 Nepomuk2::Types::Class Nepomuk2::Types::Ontology::findClassByLabel( const QString& label, const QString& language )
176 {
177  D->initEntities();
178  for ( QList<Class>::iterator it = D->classes.begin();
179  it != D->classes.end(); ++it ) {
180  Class& c = *it;
181  if ( c.label( language ) == label ) {
182  return c;
183  }
184  }
185 
186  return Class();
187 }
188 
189 
190 QList<Nepomuk2::Types::Property> Nepomuk2::Types::Ontology::allProperties()
191 {
192  D->initEntities();
193  return D->properties;
194 }
195 
196 
197 Nepomuk2::Types::Property Nepomuk2::Types::Ontology::findPropertyByName( const QString& name )
198 {
199  D->initEntities();
200  for ( QList<Property>::const_iterator it = D->properties.constBegin();
201  it != D->properties.constEnd(); ++it ) {
202  const Property& p = *it;
203  if ( p.name() == name ) {
204  return p;
205  }
206  }
207 
208  return Property();
209 }
210 
211 
212 Nepomuk2::Types::Property Nepomuk2::Types::Ontology::findPropertyByLabel( const QString& label, const QString& language )
213 {
214  D->initEntities();
215  for ( QList<Property>::iterator it = D->properties.begin();
216  it != D->properties.end(); ++it ) {
217  Property& p = *it;
218  if ( p.label( language ) == label ) {
219  return p;
220  }
221  }
222 
223  return Property();
224 }
Nepomuk2::Types::Ontology::allClasses
QList< Class > allClasses()
All classes defined in this ontology, i.e.
Definition: ontology.cpp:153
class.h
ontology.h
Nepomuk2::Types::Ontology::allProperties
QList< Property > allProperties()
A list of all properties defined in this ontology.
Definition: ontology.cpp:190
Nepomuk2::addProperty
KJob * addProperty(const QList< QUrl > &resources, const QUrl &property, const QVariantList &values, const KComponentData &component=KGlobal::mainComponent())
Add one or more property values to one or more resources.
Definition: datamanagement.cpp:36
Nepomuk2::Types::Ontology::~Ontology
~Ontology()
Destructor.
Definition: ontology.cpp:141
Nepomuk2::Types::Ontology::findPropertyByName
Property findPropertyByName(const QString &name)
Search for a property in the ontology by its name.
Definition: ontology.cpp:197
Nepomuk2::Types::Ontology::findClassByName
Class findClassByName(const QString &name)
Search for a class in the ontology by its name.
Definition: ontology.cpp:160
Nepomuk2::Types::Entity
Abstract base class for Class and Property;.
Definition: entity.h:54
Nepomuk2::Types::Class
A Class is a resource of type rdf:Class.
Definition: class.h:49
Nepomuk2::Types::Ontology::findPropertyByLabel
Property findPropertyByLabel(const QString &label, const QString &language=QString())
Search for a property in the ontology by its label.
Definition: ontology.cpp:212
Nepomuk2::Types::Ontology::Ontology
Ontology()
Default constructor.
Definition: ontology.cpp:123
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
resourcemanager.h
Nepomuk2::Types::EntityManager::getOntology
QExplicitlySharedDataPointer< OntologyPrivate > getOntology(const QUrl &uri)
Definition: entitymanager.cpp:68
entitymanager.h
Nepomuk2::Types::Ontology::findClassByLabel
Class findClassByLabel(const QString &label, const QString &language=QString())
Search for a class in the ontology by its label.
Definition: ontology.cpp:175
Nepomuk2::Types::Entity::name
QString name() const
The name of the resource.
Definition: entity.cpp:181
Property
Represents the property of a resource.
Definition: rcgen/property.h:29
Nepomuk2::Types::Entity::label
QString label(const QString &language=KGlobal::locale() ->language())
Retrieve the label of the entity (rdfs:label)
Definition: entity.cpp:187
Nepomuk2::Types::Entity::d
QExplicitlySharedDataPointer< EntityPrivate > d
Definition: entity.h:250
property.h
Nepomuk2::Types::EntityManager::self
static EntityManager * self()
Definition: entitymanager.cpp:84
Nepomuk2::Types::Ontology
Represents one ontology.
Definition: ontology.h:45
D
#define D
Definition: ontology.cpp:35
Nepomuk2::Types::Ontology::operator=
Ontology & operator=(const Ontology &)
Definition: ontology.cpp:146
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