~ubuntu-branches/ubuntu/gutsy/soprano/gutsy

« back to all changes in this revision

Viewing changes to soprano/inference/inferenceruleset.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-12 14:43:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071012144348-yajzi51v4k23ahxf
Tags: 1.95.0~beta2-1ubuntu1
* Sync with Debian
* Add versioned build-dep on raptor

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of Soprano Project.
 
3
 *
 
4
 * Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 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
 * Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Library General Public License
 
17
 * along with this library; see the file COPYING.LIB.  If not, write to
 
18
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 * Boston, MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include "inferenceruleset.h"
 
25
#include "inferencerule.h"
 
26
#include "inferenceruleparser.h"
 
27
 
 
28
#include <QtCore/QHash>
 
29
#include <QtCore/QList>
 
30
 
 
31
 
 
32
class Soprano::Inference::RuleSet::Private : public QSharedData
 
33
{
 
34
public:
 
35
    QHash<QString, Rule> ruleMap;
 
36
    mutable QList<Rule> rules;
 
37
};
 
38
 
 
39
 
 
40
Soprano::Inference::RuleSet::RuleSet()
 
41
    : d( new Private() )
 
42
{
 
43
}
 
44
 
 
45
 
 
46
Soprano::Inference::RuleSet::RuleSet( const RuleSet& other )
 
47
{
 
48
    d = other.d;
 
49
}
 
50
 
 
51
Soprano::Inference::RuleSet::~RuleSet()
 
52
{
 
53
}
 
54
 
 
55
 
 
56
Soprano::Inference::RuleSet& Soprano::Inference::RuleSet::operator=( const RuleSet& other )
 
57
{
 
58
    d = other.d;
 
59
    return *this;
 
60
}
 
61
 
 
62
 
 
63
void Soprano::Inference::RuleSet::insert( const QString& name, const Rule& rule )
 
64
{
 
65
    d->ruleMap[name] = rule;
 
66
    d->rules.clear();
 
67
}
 
68
 
 
69
 
 
70
int Soprano::Inference::RuleSet::count() const
 
71
{
 
72
    return d->ruleMap.count();
 
73
}
 
74
 
 
75
 
 
76
Soprano::Inference::Rule Soprano::Inference::RuleSet::at( int index ) const
 
77
{
 
78
    if ( d->rules.isEmpty() ) {
 
79
        d->rules = d->ruleMap.values();
 
80
    }
 
81
    return d->rules.at( index );
 
82
}
 
83
 
 
84
 
 
85
Soprano::Inference::Rule Soprano::Inference::RuleSet::operator[]( int index ) const
 
86
{
 
87
    return at( index );
 
88
}
 
89
 
 
90
 
 
91
Soprano::Inference::Rule Soprano::Inference::RuleSet::rule( const QString& name ) const
 
92
{
 
93
    return d->ruleMap[name];
 
94
}
 
95
 
 
96
 
 
97
Soprano::Inference::Rule Soprano::Inference::RuleSet::operator[]( const QString& name ) const
 
98
{
 
99
    return rule( name );
 
100
}
 
101
 
 
102
 
 
103
QList<Soprano::Inference::Rule> Soprano::Inference::RuleSet::allRules() const
 
104
{
 
105
    if ( d->rules.isEmpty() ) {
 
106
        d->rules = d->ruleMap.values();
 
107
    }
 
108
    return d->rules;
 
109
}
 
110
 
 
111
 
 
112
void Soprano::Inference::RuleSet::clear()
 
113
{
 
114
    d->ruleMap.clear();
 
115
    d->rules.clear();
 
116
}
 
117
 
 
118
 
 
119
QStringList Soprano::Inference::RuleSet::ruleNames() const
 
120
{
 
121
    return d->ruleMap.keys();
 
122
}
 
123
 
 
124
 
 
125
Soprano::Inference::RuleSet Soprano::Inference::RuleSet::standardRuleSet( StandardRuleSet set )
 
126
{
 
127
    QString path( SOPRANO_PREFIX );
 
128
    path += "/share/soprano/rules/";
 
129
 
 
130
    switch( set ) {
 
131
    case RDFS:
 
132
        path += "rdfs.rules";
 
133
        break;
 
134
    case NRL:
 
135
        path += "nrl.rules";
 
136
        break;
 
137
    }
 
138
 
 
139
    RuleParser parser;
 
140
    parser.parseFile( path );
 
141
    return parser.rules();
 
142
}