/usr/include/dataquay/PropertyObject.h is in libdataquay-dev 0.9-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Dataquay
A C++/Qt library for simple RDF datastore management.
Copyright 2009-2012 Chris Cannam.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Chris Cannam
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization.
*/
#ifndef _DATAQUAY_PROPERTY_OBJECT_H_
#define _DATAQUAY_PROPERTY_OBJECT_H_
#include <QString>
#include <QStringList>
#include <QHash>
#include <QVariant>
#include <QVariantList>
#include "Node.h"
namespace Dataquay
{
class Transaction;
class Store;
/**
* \class PropertyObject PropertyObject.h <dataquay/PropertyObject.h>
*
* PropertyObject is a helper class for managing RDF properties of an
* object URI -- that is, triples that share a common subject and
* possibly a common prefix for the predicate, and that have only one
* value for each subject-predicate combination. This could be of use
* in situations where properties of a single object URI are referred
* to often. This class provides set and get methods that act
* directly upon the backing datastore, optionally using a
* transaction. See CacheingPropertyObject for a cacheing
* alternative.
*
* PropertyObject is constructed using a "property prefix" (a string)
* and "my URI" (a URI). The URI is used by the property object as
* the subject for all RDF triples.
*
* All the property handling methods then also take a "property name",
* which is a string. If this name contains no ':' character, it will
* be prefixed with the property prefix that was supplied to the
* PropertyObject constructor before being subjected to prefix
* expansion in the RDF store. The result is then used as the
* predicate for the RDF triple. If the name does contain a ':', it
* is passed for expansion directly (the prefix is not prepended
* first). As an exception, if the prefix is the special name "a",
* it will be expanded (by the store) as "rdf:type".
*
* Example: If the property prefix is "myprops:" and the property name
* passed to getProperty is "some_property", the returned value from
* getProperty will be the result of matching on the triple (myUri,
* "myprops:some_property", ()). Hopefully, the RDF store will have
* already been told about the "myprops" prefix and will know how to
* expand it.
*
* Example: If the property prefix is "http://example.com/property/"
* and the property name passed to getProperty is "some_property", the
* returned value from getProperty will be the result of matching on
* the triple (myUri, "http://example.com/property/some_property", ()).
*
* Example: If the property prefix is "myprops:" and the property name
* passed to getProperty is "yourprops:some_property", the returned
* value from getProperty will be the result of matching on the triple
* (myUri, "yourprops:some_property", ()). The property prefix is not
* used at all in this example because the property name contains ':'.
*/
class PropertyObject
{
public:
/**
* Construct a PropertyObject acting on the given Store, with the
* default prefix for properties taken from the global default
* (see setDefaultPropertyPrefix) and the given "subject" URI.
*/
PropertyObject(Store *s, Uri myUri);
/**
* Construct a PropertyObject acting on the given Store, with the
* default prefix for properties taken from the global default
* (see setDefaultPropertyPrefix) and the given "subject" URI
* (which will be prefix expanded).
*/
PropertyObject(Store *s, QString myUri);
/**
* Construct a PropertyObject acting on the given Store, with the
* default prefix for properties taken from the global default
* (see setDefaultPropertyPrefix) and the given "subject" node.
* This is provided so as to permit querying the properties of
* blank nodes or nodes returned from other queries.
*/
PropertyObject(Store *s, Node myNode);
/**
* Construct a PropertyObject acting on the given Store, with the
* given default prefix (which will itself be prefix expanded) for
* properties and the given "subject" URI.
*/
PropertyObject(Store *s, QString propertyPrefix, Uri myUri);
/**
* Construct a PropertyObject acting on the given Store, with the
* given default prefix for properties and the given "subject"
* URI (which will be prefix expanded).
*/
PropertyObject(Store *s, QString propertyPrefix, QString myUri);
/**
* Construct a PropertyObject acting on the given Store, with the
* given default prefix for properties and the given node as its
* subject. This is provided so as to permit querying the
* properties of blank nodes or nodes returned from other queries.
*/
PropertyObject(Store *s, QString propertyPrefix, Node myNode);
~PropertyObject();
/**
* Return the node passed to the constructor (or derived from the
* URI passed to the constructor).
*/
Node getNode() const;
/**
* Return the rdf:type of my URI, if any. If more than one is
* defined, return the first one found.
*/
Uri getObjectType() const;
/**
* Return the rdf:type of my URI, if any, querying through the
* given transaction. If more than one is defined, return the
* first one found.
*/
Uri getObjectType(Transaction *tx) const;
/**
* Return true if the property object has the given property. That
* is, if the store contains at least one triple whose subject and
* predicate match those for my URI and the expansion of the given
* property name.
*/
bool hasProperty(QString name) const;
/**
* Return true if the property object has the given property,
* querying through the given transaction. That is, if the store
* contains at least one triple whose subject and predicate match
* those for my URI and the expansion of the given property name.
*/
bool hasProperty(Transaction *tx, QString name) const;
/**
* Get the value of the given property. That is, if the store
* contains at least one triple whose subject and predicate match
* those for my URI and the expansion of the given property name,
* convert the object part of the first such matching triple to a
* QVariant via Node::toVariant and return that value. If there
* is no such match, return QVariant().
*/
QVariant getProperty(QString name) const;
/**
* Get the value of the given property, querying through the given
* transaction. That is, if the store contains at least one
* triple whose subject and predicate match those for my URI and
* the expansion of the given property name, convert the object
* part of the first such matching triple to a QVariant via
* Node::toVariant and return that value. If there is no such
* match, return QVariant().
*/
QVariant getProperty(Transaction *tx, QString name) const;
/**
* Get the value of the given property as a list. That is, if the
* store contains at least one triple whose subject and predicate
* match those for my URI and the expansion of the given property
* name, convert the object parts of all such matching triples to
* QVariant via Node::toVariant and return a list of the resulting
* values. If there is no such match, return an empty list.
*
* Note that the order of variants in the returned list is
* arbitrary and may change from one call to the next.
*/
QVariantList getPropertyList(QString name) const;
/**
* Get the value of the given property as a list, querying through
* the given transaction. That is, if the store contains at least
* one triple whose subject and predicate match those for my URI
* and the expansion of the given property name, convert the
* object parts of all such matching triples to QVariant via
* Node::toVariant and return a list of the resulting values. If
* there is no such match, return QVariant().
*
* Note that the order of variants in the returned list is
* arbitrary and may change from one call to the next.
*/
QVariantList getPropertyList(Transaction *tx, QString name) const;
/**
* Get the node for the given property. That is, if the store
* contains at least one triple whose subject and predicate match
* those for my URI and the expansion of the given property name,
* return the object part of the first such matching triple. If
* there is no such match, return Node().
*/
Node getPropertyNode(QString name) const;
/**
* Get the node for the given property, querying through the given
* transaction. That is, if the store contains at least one
* triple whose subject and predicate match those for my URI and
* the expansion of the given property name, return the object
* part of the first such matching triple. If there is no such
* match, return Node().
*/
Node getPropertyNode(Transaction *tx, QString name) const;
/**
* Get the nodes for the given property. That is, if the store
* contains at least one triple whose subject and predicate match
* those for my URI and the expansion of the given property name,
* return the object parts of all such matching triples. If there
* is no such match, return an empty list.
*
* Note that the order of nodes in the returned list is arbitrary
* and may change from one call to the next.
*/
Nodes getPropertyNodeList(QString name) const;
/**
* Get the nodes for the given property, querying through the
* given transaction. That is, if the store contains at least one
* triple whose subject and predicate match those for my URI and
* the expansion of the given property name, return the object
* parts of all such matching triples. If there is no such match,
* return an empty list.
*
* Note that the order of nodes in the returned list is arbitrary
* and may change from one call to the next.
*
*!!! NB this is misnamed -- this looks up a set rather than a list
*/
Nodes getPropertyNodeList(Transaction *tx, QString name) const;
/**
* Get the names of this object's properties beginning with our
* property prefix. That is, find all triples in the store whose
* subject matches my URI and whose predicate begins with our
* property prefix, and return a list of the remainder of their
* predicate URIs following the property prefix.
*/
QStringList getPropertyNames() const;
/**
* Get the names of this object's properties beginning with our
* property prefix, querying through the given transaction. That
* is, find all triples in the store whose subject matches my URI
* and whose predicate begins with our property prefix, and return
* a list of the remainder of their predicate URIs following the
* property prefix.
*/
QStringList getPropertyNames(Transaction *tx) const;
/**
* Set the given property to the given value. That is, first
* remove from the store any triples whose subject and predicate
* match those for my URI and the expansion of the given property
* name, then insert a new triple whose object part is the result
* of converting the given variant to a node via
* Node::fromVariant.
*/
void setProperty(QString name, QVariant value);
/**
* Set the given property to the given URI. That is, first
* remove from the store any triples whose subject and predicate
* match those for my URI and the expansion of the given property
* name, then insert a new triple whose object part is the URI.
*/
void setProperty(QString name, Uri uri);
/**
* Set the given property to the given node. That is, first
* remove from the store any triples whose subject and predicate
* match those for my URI and the expansion of the given property
* name, then insert a new triple whose object part is the node.
*/
void setProperty(QString name, Node node);
/**
* Set the given property to the given value through the given
* transaction. That is, first remove from the store any triples
* whose subject and predicate match those for my URI and the
* expansion of the given property name, then insert a new triple
* whose object part is the result of converting the given variant
* to a node via Node::fromVariant.
*/
void setProperty(Transaction *tx, QString name, QVariant value);
/**
* Set the given property to the given URI through the given
* transaction. That is, first remove from the store any triples
* whose subject and predicate match those for my URI and the
* expansion of the given property name, then insert a new triple
* whose object part is the URI.
*/
void setProperty(Transaction *tx, QString name, Uri uri);
/**
* Set the given property to the given node through the given
* transaction. That is, first remove from the store any triples
* whose subject and predicate match those for my URI and the
* expansion of the given property name, then insert a new triple
* whose object part is the node.
*/
void setProperty(Transaction *tx, QString name, Node node);
/**
* Set the given property to the given values. That is, first
* remove from the store any triples whose subject and predicate
* match those for my URI and the expansion of the given property
* name, then insert a new triple for each variant in the value
* list, whose object part is the result of converting that
* variant to a node via Node::fromVariant.
*/
void setPropertyList(QString name, QVariantList values);
/**
* Set the given property to the given values through the given
* transaction. That is, first remove from the store any triples
* whose subject and predicate match those for my URI and the
* expansion of the given property name, then insert a new triple
* for each variant in the value list, whose object part is the
* result of converting that variant to a node via
* Node::fromVariant.
*/
void setPropertyList(Transaction *tx, QString name, QVariantList values);
/**
* Set the given property to the given nodes. That is, first
* remove from the store any triples whose subject and predicate
* match those for my URI and the expansion of the given property
* name, then insert a new triple for each node in the list, whose
* object part is that node.
*/
void setPropertyList(QString name, Nodes nodes);
/**
* Set the given property to the given nodes through the given
* transaction. That is, first remove from the store any triples
* whose subject and predicate match those for my URI and the
* expansion of the given property name, then insert a new triple
* for each node in the list, whose object part is that node.
*/
void setPropertyList(Transaction *tx, QString name, Nodes nodes);
/**
* Remove the given property. That is, remove from the store any
* triples whose subject and predicate match those for my URI and
* the expansion of the given property name.
*/
void removeProperty(QString name);
/**
* Remove the given property. That is, remove from the store any
* triples whose subject and predicate match those for my URI and
* the expansion of the given property name.
*/
void removeProperty(Transaction *tx, QString name);
/**
* Return the Store object that will be used for modifications in
* the given transaction. If the transaction is not
* NoTransaction, then the returned Store will simply be the
* transaction itself; otherwise it will be the store that was
* passed to the constructor.
*/
Store *getStore(Transaction *tx) const;
/**
* Return the URI used for the "predicate" part of any triple
* referring to the given property name. See the general
* PropertyObject documentation for details of how these names are
* expanded.
*/
Uri getPropertyUri(QString name) const;
/**
* Set the global default property prefix. This will be used as
* the prefix for all PropertyObjects subsequently constructed
* using the two-argument (prefixless) constructors.
*/
static void setDefaultPropertyPrefix(QString prefix);
private:
Store *m_store;
QString m_pfx;
Uri m_upfx;
Node m_node;
static QString m_defaultPrefix;
};
/**
* \class CacheingPropertyObject PropertyObject.h <dataquay/PropertyObject.h>
*
* CacheingPropertyObject is a helper class for managing RDF
* properties of an object URI -- that is, triples that share a common
* subject and possibly a common prefix for the predicate, and that
* have only one value for each subject-predicate combination.
*
* This class caches results from the datastore and so may be faster
* than PropertyObject, but it can only be used in contexts where it
* is known that no other agent may be modifying the same set of
* properties. Its set of available functions is more limited than
* PropertyObject also: it has no Transaction-based functions.
*
* See PropertyObject for individual method documentation.
*/
class CacheingPropertyObject
{
public:
CacheingPropertyObject(Store *s, Uri myUri);
CacheingPropertyObject(Store *s, QString myUri);
CacheingPropertyObject(Store *s, QString propertyPrefix, Uri myUri);
CacheingPropertyObject(Store *s, QString propertyPrefix, QString myUri);
CacheingPropertyObject(Store *s, QString propertyPrefix, Node myUri);
Uri getObjectType() const;
bool hasProperty(QString name) const;
QVariant getProperty(QString name) const;
QVariantList getPropertyList(QString name) const;
Node getPropertyNode(QString name) const;
Nodes getPropertyNodeList(QString name) const;
QStringList getPropertyNames() const;
void setProperty(QString name, QVariant value);
void setProperty(QString name, Uri value);
void setProperty(QString name, Node node);
void setPropertyList(QString name, QVariantList values);
void setPropertyList(QString name, Nodes nodes);
void removeProperty(QString name);
Uri getPropertyUri(QString name) const;
private:
PropertyObject m_po;
typedef QHash<Uri, Nodes> Properties;
mutable Properties m_cache; // note: value is never empty
mutable bool m_cached;
void encache() const;
};
}
#endif
|