• 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
  • storage
virtuosoinferencemodel.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Nepomuk KDE project.
3  Copyright (C) 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 "virtuosoinferencemodel.h"
23 
24 #include <Soprano/QueryResultIterator>
25 #include <Soprano/Node>
26 #include <Soprano/Vocabulary/NRL>
27 #include <Soprano/Vocabulary/NAO>
28 #include <Soprano/Vocabulary/XMLSchema>
29 #include <Soprano/Vocabulary/RDFS>
30 
31 #include <KDebug>
32 
33 using namespace Soprano::Vocabulary;
34 
35 namespace {
36  const char* s_nepomukInferenceRuleSetName = "nepomukinference";
37  const char* s_nepomukOntologyGroup = "nepomuk-ontology-group";
38 }
39 
40 
41 Nepomuk2::VirtuosoInferenceModel::VirtuosoInferenceModel(Model *model)
42  : Soprano::FilterModel(model),
43  m_haveInferenceRule(false)
44 {
45 }
46 
47 Nepomuk2::VirtuosoInferenceModel::~VirtuosoInferenceModel()
48 {
49 }
50 
51 Soprano::QueryResultIterator Nepomuk2::VirtuosoInferenceModel::executeQuery(const QString &query, Soprano::Query::QueryLanguage language, const QString &userQueryLanguage) const
52 {
53  if(language == Soprano::Query::QueryLanguageSparqlNoInference) {
54  return FilterModel::executeQuery(query, Soprano::Query::QueryLanguageSparql);
55  }
56  else if(language == Soprano::Query::QueryLanguageSparql && m_haveInferenceRule) {
57  return FilterModel::executeQuery(QString::fromLatin1("DEFINE input:inference <%1> ")
58  .arg(QLatin1String(s_nepomukInferenceRuleSetName)) + query, language);
59  }
60  else {
61  return FilterModel::executeQuery(query, language, userQueryLanguage);
62  }
63 }
64 
65 void Nepomuk2::VirtuosoInferenceModel::updateOntologyGraphs(bool forced)
66 {
67  // Create the Nepomuk Ontology group
68  QString ontGroupQuery = QString::fromLatin1("DB.DBA.RDF_GRAPH_GROUP_CREATE( '%1', 1, '',"
69  "'Contains the graphs all of all the ontologies' )")
70  .arg( QLatin1String(s_nepomukOntologyGroup) );
71  executeQuery( ontGroupQuery, Soprano::Query::QueryLanguageUser, QLatin1String("sql"));
72 
73  int ontologyCount= 0;
74 
75  // update the ontology graph group only if something changed (forced) or if it is empty
76  if(forced || ontologyCount <= 0) {
77  kDebug() << "Need to update ontology graph group";
78  // fetch all ontology graphs and add them to the graph group
79 
80  QString query = QString::fromLatin1("select distinct ?r where { ?r a ?t . "
81  "FILTER(?t in (%1, %2)) . }")
82  .arg(Soprano::Node::resourceToN3(NRL::Ontology()),
83  Soprano::Node::resourceToN3(NRL::KnowledgeBase()));
84 
85  QList<QUrl> ontologies;
86  Soprano::QueryResultIterator it = executeQuery( query , Soprano::Query::QueryLanguageSparql);
87  while(it.next()) {
88  ++ontologyCount;
89  executeQuery(QString::fromLatin1("rdfs_rule_set('%1','%2')")
90  .arg(QLatin1String(s_nepomukInferenceRuleSetName))
91  .arg(it[0].uri().toString()),
92  Soprano::Query::QueryLanguageUser,
93  QLatin1String("sql"));
94 
95  /*
96  QString ontGroupQuery = QString::fromLatin1("DB.DBA.RDF_GRAPH_GROUP_INS('%1', '%2')")
97  .arg( QLatin1String(s_nepomukOntologyGroup),
98  it[0].uri().toString() );
99  executeQuery( ontGroupQuery, Soprano::Query::QueryLanguageUser, QLatin1String("sql"));
100  ontologies << it[0].uri();
101  */
102  }
103 
104  // Fetch all the graph metadata graphs
105  /*
106  foreach(const QUrl& graphUri, ontologies) {
107  QString graphMetaQUery = QString::fromLatin1("select distinct ?r where { ?r %1 %2 . }")
108  .arg( Soprano::Node::resourceToN3(NRL::coreGraphMetadataFor()),
109  Soprano::Node::resourceToN3(graphUri) );
110  it = executeQuery( graphMetaQUery, Soprano::Query::QueryLanguageSparql );
111  if(it.next()) {
112  QString ontGroupQuery = QString::fromLatin1("DB.DBA.RDF_GRAPH_GROUP_INS('%1', '%2')")
113  .arg( QLatin1String(s_nepomukOntologyGroup),
114  it[0].uri().toString() );
115  executeQuery( ontGroupQuery, Soprano::Query::QueryLanguageUser, QLatin1String("sql"));
116  }
117  }
118 
119  // Insert virtuoso's default graph
120  QString ontGroupQuery = QString::fromLatin1("DB.DBA.RDF_GRAPH_GROUP_INS('%1', '%2')")
121  .arg( QLatin1String(s_nepomukOntologyGroup),
122  QLatin1String("http://www.openlinksw.com/schemas/virtrdf#") );
123  executeQuery( ontGroupQuery, Soprano::Query::QueryLanguageUser, QLatin1String("sql"));
124  */
125  }
126 
127  m_haveInferenceRule = (ontologyCount > 0);
128 }
129 
130 #include "virtuosoinferencemodel.moc"
Nepomuk2::VirtuosoInferenceModel::updateOntologyGraphs
void updateOntologyGraphs(bool forced)
Needs to be called if any ontology changes or a new ontology is imported.
Definition: virtuosoinferencemodel.cpp:65
Nepomuk2::VirtuosoInferenceModel::VirtuosoInferenceModel
VirtuosoInferenceModel(Soprano::Model *model)
Definition: virtuosoinferencemodel.cpp:41
Nepomuk2::VirtuosoInferenceModel::executeQuery
Soprano::QueryResultIterator executeQuery(const QString &query, Soprano::Query::QueryLanguage language, const QString &userQueryLanguage=QString()) const
Reimplemented to add Virtuoso SPARQL extensions for inference to each query and suppeor for Soprano::...
Definition: virtuosoinferencemodel.cpp:51
virtuosoinferencemodel.h
Nepomuk2::VirtuosoInferenceModel::~VirtuosoInferenceModel
~VirtuosoInferenceModel()
Definition: virtuosoinferencemodel.cpp:47
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