26 namespace Syndication {
29 long Model::ModelPrivate::idCounter = 0;
52 return *d == *(other.d);
59 if (d->properties.contains(uri))
61 prop = d->properties[uri];
65 prop = PropertyPtr(
new Property(uri) );
66 prop->setModel(*
this);
69 if (d->resources.contains(uri))
71 prop->setId(d->resources[uri]->id());
84 if (d->resources.contains(uri))
86 res = d->resources[uri];
90 res = ResourcePtr(
new Resource(uri) );
102 if (d->sequences.contains(uri))
104 seq = d->sequences[uri];
108 seq = SequencePtr(
new Sequence(uri) );
109 seq->setModel(*
this);
112 if (d->resources.contains(uri))
114 seq->setId(d->resources[uri]->id());
125 LiteralPtr lit(
new Literal(text));
134 removeStatement(statement->subject(), statement->predicate(), statement->object());
139 QString key = QString::fromLatin1(
"%1-%2-%3")
140 .arg(QString::number(subject->id()))
141 .arg(QString::number(predicate->id()))
142 .arg(QString::number(object->id()));
143 d->removeFromHashes(key);
149 ResourcePtr subjInternal = subject;
151 if (!d->nodes.contains(subjInternal->id()))
153 subjInternal = ResourcePtr( subject->clone() );
154 subjInternal->setModel(*
this);
155 d->addToHashes(subjInternal);
158 PropertyPtr predInternal = predicate;
160 if (!d->nodes.contains(predInternal->id()))
162 predInternal = PropertyPtr( predicate->clone() );
163 predInternal->setModel(*
this);
164 d->addToHashes(predInternal);
167 NodePtr objInternal = object;
169 if (!d->nodes.contains(objInternal->id()))
171 objInternal = NodePtr( object->clone() );
172 objInternal->setModel(*
this);
173 d->addToHashes(objInternal);
178 QString key = QString::fromLatin1(
"%1-%2-%3")
179 .arg(QString::number(subjInternal->id()))
180 .arg(QString::number(predInternal->id()))
181 .arg(QString::number(objInternal->id()));
185 if (!d->statements.contains(key))
187 stmt = StatementPtr(
new Statement(subjInternal, predInternal, objInternal) );
188 d->addToHashes(stmt, key);
192 stmt = d->statements[key];
200 return d->statements.isEmpty();
203 bool Model::resourceHasProperty(
const Resource* resource, PropertyPtr property)
const
205 return d->resourceHasProperty( resource, property );
208 bool Model::ModelPrivate::resourceHasProperty(
const Resource* resource, PropertyPtr property)
const
211 if (!resources.contains(resource->uri()))
214 QList<StatementPtr> stmts = stmtsBySubject[resource->uri()];
215 QList<StatementPtr>::ConstIterator it = stmts.constBegin();
216 QList<StatementPtr>::ConstIterator end = stmts.constEnd();
218 for ( ; it != end; ++it)
220 if (*((*it)->predicate()) == *property)
227 StatementPtr Model::resourceProperty(
const Resource* resource, PropertyPtr property)
const
229 return d->resourceProperty(resource, property);
232 StatementPtr Model::ModelPrivate::resourceProperty(
const Resource* resource, PropertyPtr property)
const
234 QList<StatementPtr> stmts = stmtsBySubject[resource->uri()];
235 QList<StatementPtr>::ConstIterator it = stmts.constBegin();
236 QList<StatementPtr>::ConstIterator end = stmts.constEnd();
238 for ( ; it != end; ++it)
240 if (*((*it)->predicate()) == *property)
244 return nullStatement;
247 QList<StatementPtr> Model::resourceProperties(
const Resource* resource, PropertyPtr property)
const
249 return d->resourceProperties( resource, property );
252 QList<StatementPtr> Model::ModelPrivate::resourceProperties(
const Resource* resource, PropertyPtr property)
const
254 QList<StatementPtr> res;
255 QList<StatementPtr> stmts = stmtsBySubject[resource->uri()];
256 QList<StatementPtr>::ConstIterator it = stmts.constBegin();
257 QList<StatementPtr>::ConstIterator end = stmts.constEnd();
259 for ( ; it != end; ++it)
261 if (*((*it)->predicate()) == *property)
271 return d->statements.values();
278 QList<StatementPtr> stmts = d->statements.values();
279 QList<StatementPtr>::ConstIterator it = stmts.constBegin();
280 QList<StatementPtr>::ConstIterator end = stmts.constEnd();
282 for ( ; it != end; ++it)
284 info += QString::fromLatin1(
"<%1> <%2> ").arg((*it)->subject()->uri()).arg((*it)->predicate()->uri());
286 if ((*it)->object()->isLiteral())
288 info += QString::fromLatin1(
"\"%1\"\n").arg((*it)->asString());
292 info += QString::fromLatin1(
"<%1>\n").arg((*it)->asResource()->uri());
302 QList<ResourcePtr> list;
304 QList<StatementPtr> stmts = d->statements.values();
305 QList<StatementPtr>::ConstIterator it = stmts.constBegin();
306 QList<StatementPtr>::ConstIterator end = stmts.constEnd();
308 for ( ; it != end; ++it)
310 if (*((*it)->predicate()) == *(
RDFVocab::self()->
type()) && *((*it)->object()) == *type )
311 list.append((*it)->subject());
319 return d->nodeByID(
id);
322 NodePtr Model::ModelPrivate::nodeByID(uint _id)
const
324 if (!nodes.contains(_id))
330 return nodes.value(_id);
336 return d->resourceByID(
id);
339 ResourcePtr Model::ModelPrivate::resourceByID(uint _id)
const
341 if (!nodes.contains(_id))
347 NodePtr node = nodes.value(_id);
348 if (node->isResource())
349 return boost::static_pointer_cast<Resource>(node);
357 return d->propertyByID(
id);
360 PropertyPtr Model::ModelPrivate::propertyByID(uint _id)
const
362 if (!nodes.contains(_id))
368 NodePtr node = nodes.value(_id);
369 if (node->isProperty())
370 return boost::static_pointer_cast<Property>(node);
378 return d->literalByID(
id);
382 LiteralPtr Model::ModelPrivate::literalByID(uint _id)
const
384 if (!nodes.contains(_id))
390 NodePtr node = nodes.value(_id);
391 if (node->isLiteral())
392 return boost::static_pointer_cast<Literal>(node);
Model()
default constructor, creates an empty model containing no statements
Resources are the entities in the RDF graph.
An RDF statement, consisting of a triple (subject, predicate, object).
An RDF model, a set of RDF statements.
virtual PropertyPtr createProperty(const QString &uri)
creates a property and associates it with this model.
a property is node type that represents properties of things, like "name" is a property of a person...
Model & operator=(const Model &other)
assigns another model.
virtual NodePtr nodeByID(uint id) const
searches the model for a node by ID.
virtual SequencePtr createSequence(const QString &uri=QString())
creates a sequence and associates it with this model.
bool operator==(const Model &other) const
Returns whether two models objects represent the same model (i.e.
virtual QString debugInfo() const
/** a debug string listing the contained statements for debugging purposes
Sequence container, a sequence contains an ordered list of RDF nodes.
virtual ~Model()
destructor
virtual StatementPtr addStatement(ResourcePtr subject, PropertyPtr predicate, NodePtr object)
adds a statement to the model.
virtual ResourcePtr resourceByID(uint id) const
searches the model for a resource by ID.
virtual bool isEmpty() const
returns whether this model is empty, i.e.
virtual QList< ResourcePtr > resourcesWithType(ResourcePtr type) const
returns all resources of a given type.
virtual LiteralPtr literalByID(uint id) const
searches the model for a literal by ID.
virtual void removeStatement(ResourcePtr subject, PropertyPtr predicate, NodePtr object)
removes a statement from the model.
virtual PropertyPtr propertyByID(uint id) const
searches the model for a property by ID.
a node type representing simple string values.
virtual QList< StatementPtr > statements() const
returns a list of the statements in this model.
virtual LiteralPtr createLiteral(const QString &text)
creates a literal and associates it with this model.
virtual ResourcePtr createResource(const QString &uri=QString())
creates a resource and associates it with this model.
static RDFVocab * self()
returns the singleton instance
PropertyPtr type()
the rdf:type property (A rdf:type B means A is instance of B)