SASSY  0.0
Software Architecture Support System
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
rdfxx.h
Go to the documentation of this file.
1 
2 /* RDF C++ API
3  *
4  * rdfxx.h
5  *
6  * Copyright 2017 Brenton Ross
7  *
8  * -----------------------------------------------------------------------------
9  * LICENSE
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this library. If not, see <http://www.gnu.org/licenses/>.
23  *
24  * -----------------------------------------------------------------------------
25  */
26 
33 
34 #ifndef RDFXX_H
35 #define RDFXX_H
36 
37 #include <memory>
38 #include <string>
39 #include <map>
40 
41 #include <rdfxx/except.h>
42 
44 namespace rdf
45 {
46 
47 //
48 // NOTE: Class names use the following convention:
49 // Name_ is an abstract class
50 // _Name is its implementation (private to the implementation)
51 // Name is a shared pointer to a child of Name_ or a simple class.
52 // NameRef is a weak pointer to a child of Name_
53 //
54 
55 // Forward declarations of abstract base classes
56 class World_;
57 class Model_;
58 class Node_;
59 class ResourceNode_;
60 class LiteralNode_;
61 class BlankNode_;
62 class Parser_;
63 class Query_;
64 class QueryResults_;
65 class Serializer_;
66 class Statement_;
67 class Stream_;
68 class URI_;
69 
70 class QueryString;
71 class Literal;
72 
73 //
74 // Shared pointers for use by the client applications
75 //
77 using World = std::shared_ptr< World_ >;
78 
80 using WorldRef = std::weak_ptr< World_ >;
81 
83 using NodeRef = std::weak_ptr< Node_ >;
84 
86 using QueryResults = std::shared_ptr< QueryResults_ >;
87 
89 using StatementRef = std::weak_ptr< Statement_ >;
90 
91 // ---------------------------------------------------------------
92 
94 enum class Concept
95 {
96  // Containers
97  Container, Bag, Sequence, Alternative, aboutEach,
98 
99  // Collections
100  List, first, rest, nil,
101 
102  // Reification
103  Statement, object, predicate, subject,
104 
105  // Classes
106  Resource, Class, subClassOf, type, Property, subPropertyOf,
107  domain, range, ConstraintProperty, ConstraintResource,
108 
109  // Descriptive stuff
110  Description, label, seeAlso, comment, isDefinedBy
111 
112  // probably not useful in our models
113  // RDF, value, Literal, XMLLiteral, NodeID, li,
114  // aboutEachPrefix, // depricated
115 };
116 
117 // ---------------------------------------------------------------
118 //
119 // The following declarations allow the user to create an object
120 // and its associated shared pointer as if it were an ordinary object
121 //
122 // ---------------------------------------------------------------
123 
126 
127 class URI : public std::shared_ptr< URI_ >
128 {
129 public:
131  URI() : std::shared_ptr< URI_ >( nullptr ) {}
132 
134  URI( URI_* );
135 
137  URI( World, const std::string &uri_string );
138 
140  URI( World, Concept );
141 
143  URI( const std::string & filename, World );
144 
146  // useful for conversion between prefix and namespace forms.
147  URI( const std::string &uri_string, URI source_uri, URI base_uri );
148 
150  URI( URI base_uri, const std::string &uri_string );
151 
153  URI( const std::string &local_name, URI basr_uri );
154 };
155 
156 // ---------------------------------------------------------------
157 
160 
161 class Model : public std::shared_ptr< Model_ >
162 {
163 public:
165  Model() : std::shared_ptr< Model_ >( nullptr ) {}
166 
168  Model( Model_* );
169 
171  //
172  // Options: Apparently in the format of XML attributes.
173  // It is not documented as to what they are or how they are used.
174  //
175  // storage_type - name of storage factory
176  // "file", "memory", "hashes", "sqlite"
177  // storage_name - an identifier, eg filename or database name
178  // options - whatever needed for initialisation
179  Model( World, const std::string & storage_type,
180  const std::string & storage_name = "",
181  const std::string & storage_options = "",
182  const std::string & model_options = "" );
183 };
184 
185 // ---------------------------------------------------------------
186 
188 using Node = std::shared_ptr< Node_ >;
189 
192 
193 class ResourceNode : public std::shared_ptr< ResourceNode_ >
194 {
195 public:
197  ResourceNode( World, URI );
198 
201 
203  ResourceNode( World, int );
204 
206  ResourceNode( Node resourceNode );
207 };
208 
211 
212 class LiteralNode : public std::shared_ptr< LiteralNode_ >
213 {
214 public:
216  LiteralNode( World, const Literal & );
217 
219  LiteralNode( Node literalNode );
220 };
221 
224 
225 
226 class BlankNode : public std::shared_ptr< BlankNode_ >
227 {
228 public:
230  BlankNode( World, const std::string &id = "" );
231 
233  BlankNode( Node blankNode );
234 };
235 
236 // ---------------------------------------------------------------
237 
240 
241 
242 class Statement : public std::shared_ptr< Statement_ >
243 {
244 public:
246  Statement();
247 
249  Statement(World);
250 
252  Statement(World, Node subject, Node predicate, Node object);
253 
255  Statement( Statement_* );
256 
259 };
260 
261 // ---------------------------------------------------------------
262 
265 
266 
267 class Parser : public std::shared_ptr< Parser_ >
268 {
269 public:
270 
271  // name is the name of a parsing engine:
272  // Use listParsers() to get names.
273  // Empty string for default.
274  //
275 
277  Parser( World, const std::string & name,
278  const std::string & syntax_mime = std::string() );
279 
281  Parser( World, const std::string & name, URI syntax_uri );
282 };
283 
284 // ---------------------------------------------------------------
285 
288 
289 
290 class Serializer : public std::shared_ptr< Serializer_ >
291 {
292 public:
294  Serializer();
295 
298 
300  Serializer( World, const std::string & name = "rdfxml",
301  const std::string & syntax_mime = "" );
302 
304  Serializer( World, const std::string & name, URI syntax_uri );
305 };
306 
307 // ---------------------------------------------------------------
308 
311 
312 
313 class Stream : public std::shared_ptr< Stream_ >
314 {
315 public:
317  Stream();
318 
320  Stream( World );
321 
323  Stream( Stream_* );
324 
326  Stream( World, Parser, URI, URI base );
327 };
328 
329 // ---------------------------------------------------------------
330 
333 
334 
335 class Query : public std::shared_ptr< Query_ >
336 {
337 public:
339  Query( World, const std::string & query, const std::string & lang = "sparql" );
340 
342  Query( World, const std::string & query, URI base_uri, const std::string & lang = "sparql" );
343 };
344 
345 // ---------------------------------------------------------------
346 //
347 // Callback abstract classes
348 //
349 // ---------------------------------------------------------------
350 
353 
355 {
356 public:
358  virtual ~ErrorClient(){}
359 
361  virtual void handleError( const std::string & message ) = 0;
362 
364  virtual void handleWarning( const std::string & message ) = 0;
365 };
366 
367 // ---------------------------------------------------------------
368 
371 
377 class Universe
378 {
379  // see world.cpp for the implementation
380 private:
381  Universe(){}
382 
383  // TODO - protect with mutex
384  std::map< std::string, World > worlds;
385 public:
387  static Universe& instance();
388 
390  World world( const std::string & name );
391 };
392 
393 // ---------------------------------------------------------------
394 
397 
402 
403 struct Format
404 {
405  // resources
406  bool usePrefixes;
408 
409  // blank
410  std::string blank;
411 
412  // literal
413  bool quotes;
415  std::string prefLang;
417 };
418 
419 // ---------------------------------------------------------------
420 
423 
424 
425 class Prefixes
426 {
427  // see world.cpp for the implementation
428 private:
429  WorldRef world;
430  URI base_uri;
431  std::map< std::string, URI > uriForPrefix;
432  std::map< std::string, std::string > prefixForURI;
433  static int anonCounter;
434 public:
436  Prefixes( World );
437 
438  // methods for the base URI which usually corresponds to the
439  // file.
440 
442  void base( URI uri ) { base_uri = uri; }
443 
445  void anonymous( URI uri );
446 
448  void base( const std::string & filename ); // appends # to normalised file name
449 
451  URI base() const { return base_uri; }
452 
454  bool isBase( URI ) const;
455 
457  std::string removeBase( URI ) const;
458 
459  // methods for accessing the internal maps
460 
462  void insert( const std::string &prefix, URI );
463 
465  URI find( const std::string & );
466 
468  std::string find( URI );
469 
471  void update( const std::string &oldPrefix, const std::string &newPrefix, URI );
472 
474  void remove( const std::string & );
475 
476  // methods for converting between the prefix and normal forms
477 
479  URI uriForm( const std::string & );
480 
482  std::string prefixForm( URI );
483 
485  std::map< std::string, URI >::iterator begin() { return uriForPrefix.begin(); }
486 
488  std::map< std::string, URI >::iterator end() { return uriForPrefix.end(); }
489 };
490 
491 // ---------------------------------------------------------------
492 
494 
495 enum class DataType
496 {
497  UNDEF, // use when cannot find a match
498  PlainLiteral, // default
499  XMLLiteral,
500  XHTML, // must be valid well formed XML fragment
501 
502  // Core Types
503  String, Boolean, Decimal, Integer,
504 
505  // IEEE floating point
506  Double, Float,
507 
508  // Time and Data
509  Data, Time, DateTime, DateTimeStamp,
510 
511  // Recurring and partial dates
512  Year, Month, Day, YearMonth, MonthDay, Duration, YearMonthDuration,
513  DayTimeDuration,
514 
515  // Limited range integers
516  Byte, Short, Int, Long, UnsignedByte, UnsignedShort, UnsignedLong,
517  PositiveInteger, NonNegativeInteger, NegativeInteger, NonPositiveInteger,
518 
519  // Encoded binary data
520  HexBinary, Base64Binary,
521 
522  // Miscellaneous
523  AnyURI, Language, NormalizedString, Token, NMTOKEN, Name, NCName
524 };
525 
526 // ---------------------------------------------------------------
527 
528 //
529 // This object holds the various components of an RDF or XML literal
530 // value. This includes the value, the language, and the data type.
531 //
532 
535 
536 
537 class Literal
538 {
539  // see node.cpp for the implementation
540  static std::map< DataType, std::string > xsd_types;
541  static std::map< DataType, std::string > names;
542  static void initXSDtypes();
543 private:
544 
545  std::string mLanguage; // eg "en" for English
546  DataType mDataType;
547 
548  std::string mValue;
549 
550 public:
552  Literal(); // empty
553 
555  Literal( const std::string &val ); // plain, English
556 
558  Literal( const char *val ) : Literal(std::string(val)) {}
559 
561  Literal( const std::string &val, const std::string &lan ); // plain
562 
564  Literal( const std::string &val, DataType, const std::string &lan = "en" );
565 
567  Literal( int, DataType );
568 
570  Literal( double, DataType );
571 
573  explicit Literal( bool );
574 
576  void language( const std::string & lang ) { mLanguage = lang; }
577 
579  void dataType( DataType t ) { mDataType = t; }
580 
582  void value( const std::string & v ) { mValue = v; }
583 
585  std::string toString() const;
586 
588  std::string toString( const Format & ) const;
589 
591  DataType dataType() const { return mDataType; }
592 
594  URI dataTypeURI( World ) const;
595 
597  std::string language() const { return mLanguage; }
598 
600  std::string asString() const { return mValue; }
601 
603  int asInteger() const;
604 
606  double asDouble() const;
607 
609  bool asBoolean() const;
610  // TODO - more conversions as required
611 
613  static std::string toXSD( DataType );
614  static std::string toTypeName( DataType );
615 
617  static DataType toDataType( const std::string & xsd_type );
618  static DataType asDataType( const std::string & type_name );
619 
620  static std::vector< std::string > getDataTypeNames();
621 };
622 
623 // ---------------------------------------------------------------
624 //
625 // The following abstract classes provide the functional interface
626 // to the underlying librdf C library.
627 //
628 
629 // ---------------------------------------------------------------
630 
633 
634 
635 class World_
636 {
637 public:
639  virtual ~World_(){}
640 
642  virtual void registerErrorClient( ErrorClient *, bool warnings, bool errors ) = 0;
643 
645  virtual void deregisterErrorClient( ErrorClient * ) = 0;
646 
648  virtual Serializer defaultSerializer() = 0;
649 
651  virtual Prefixes & prefixes() = 0;
652 };
653 
654 // ---------------------------------------------------------------
655 
656 
659 
660 
661 class Model_
662 {
663 public:
665  virtual ~Model_(){}
666 
668  virtual World getWorld() = 0;
669 
671  virtual int size() const = 0;
672 
674  virtual bool sync() = 0;
675 
677  virtual Stream toStream() = 0;
678 
679  // Methods for modifying the model.
680 
682  virtual bool add( Node subject, Node predicate, Node object ) = 0;
683 
685  virtual bool add( Statement ) = 0;
686 
688  virtual bool remove( Statement ) = 0;
689 
691  virtual bool update( Statement old, Statement _new ) = 0;
692 
694  virtual bool contains( Statement )const = 0;
695 
696  // lots of useful functions for navigating the graph.
697 
699  virtual std::vector< Node > predicates( Node subject, Node object ) = 0;
700 
702  virtual std::vector< Node > objects( Node subject, Node predicate ) = 0;
703 
705  virtual std::vector< Node > subjects( Node predicate, Node object ) = 0;
706 
708  virtual std::vector< Node > arcsIn( Node object ) = 0;
709 
711  virtual std::vector< Node > arcsOut( Node subject ) = 0;
712 
713  // TODO - add and remove sub-models
714 };
715 
716 // ---------------------------------------------------------------
717 
720 
721 
722 class Node_
723 {
724 public:
726  virtual ~Node_() {}
727 
729  virtual std::string toString() const = 0;
730 
732  virtual std::string toString(const Format &) const = 0;
733 
735  virtual URI toURI() const = 0;
736 
738  virtual bool isLiteral() const = 0;
739 
741  virtual bool isBlank() const = 0;
742 
744  virtual bool isResource() const = 0;
745 
746  // TODO operator ==
747 };
748 // TODO operator == (Node, Node)
749 // TODO operator << ( ostream &, Node )
750 
753 
754 
755 class ResourceNode_ : public Node_
756 {
757 public:
759  virtual std::string toString() const = 0;
760 
762  virtual std::string toString(const Format &) const = 0;
763 
765  virtual URI toURI() const = 0;
766 
768  virtual int listItemOrdinal() const = 0;
769 };
770 
773 
774 
775 class LiteralNode_ : public Node_
776 {
777 public:
779  virtual std::string toString() const = 0;
780 
782  virtual std::string toString(const Format &) const = 0;
783 
785  virtual Literal toLiteral() const = 0;
786 };
787 
790 
791 
792 class BlankNode_ : public Node_
793 {
794 public:
796  virtual std::string toString() const = 0;
797 
799  virtual std::string toString(const Format &) const = 0;
800 };
801 
802 // ---------------------------------------------------------------
803 
806 
807 
808 class Parser_
809 {
810 public:
812  virtual ~Parser_() {}
813 
815  virtual bool parseIntoModel( Model, URI uri, URI base_uri ) = 0;
816 
818  static std::vector< std::string > listParsers( World );
819 };
820 
821 // ---------------------------------------------------------------
822 
825 
826 
827 class Query_
828 {
829 public:
831  virtual ~Query_() {}
832 
834  virtual bool setLimit(int) = 0;
835 
837  virtual int getLimit() const = 0;
838 
840  virtual QueryResults execute( Model ) = 0;
841 };
842 
843 // ---------------------------------------------------------------
844 
847 
848 
850 {
851 public:
853  virtual int count() const = 0;
854 
856  virtual std::string getBoundName(int offset) const = 0;
857 
859  virtual Node getBoundValue(int offset) const = 0;
860 
862  virtual Node getBoundValue( const std::string & name ) const = 0;
863 
865  virtual std::string toString() const = 0;
866 };
867 
868 // ---------------------------------------------------------------
869 
872 
873 
875 {
876 public:
878  virtual ~QueryResults_() {}
879 
881  virtual bool success() const = 0;
882 
884  // Default syntax URI is SPARQL XML
885  virtual std::string toString() = 0;
886 
888  virtual std::string toString( URI syntax, URI base ) = 0;
889 
892 
893  class iterator : public std::iterator< std::forward_iterator_tag, QueryResult_ >
894  {
895  private:
896  QueryResult_ *query_result;
897  public:
899  explicit iterator( QueryResult_* qr );
900 
902  iterator();
903 
905  iterator & operator = ( const QueryResult_ & ) = delete;
906 
908  virtual QueryResult_ & operator *() const;
909 
911  virtual iterator & operator ++ ();
912 
914  virtual iterator & operator ++ ( int );
915 
917  virtual bool operator == ( const iterator & ) const;
918 
920  virtual bool operator != ( const iterator & ) const;
921  };
922 
924  virtual iterator begin() const = 0;
925 
927  virtual iterator end() const = 0;
928 };
929 
930 // ---------------------------------------------------------------
931 
934 
935 
937 {
938 private:
939  std::map<std::string, std::string> prefixes;
940  std::string variables;
941  std::vector<std::string> conditions;
942  std::string order;
943 
944  std::string get_string();
945 
946 public:
949 
950  // TODO - use Prefixes to set prefixes for the query
952  void addPrefix( const std::string & id, const std::string & uri);
953 
955  void setVariables( const std::string & variables);
956 
958  void addCondition( const std::string & condition);
959 
961  void orderBy( const std::string & order);
962 
964  operator std::string();
965 };
966 
967 // ---------------------------------------------------------------
968 
971 
972 
974 {
975 public:
977  virtual ~Serializer_() {}
978 
980  virtual bool setNamespace( URI, const std::string & prefix ) = 0;
981 
983  virtual bool toFile( const std::string &filename, Model ) = 0;
984 
986  virtual bool toFile( const std::string &filename, Model, URI base_uri ) = 0;
987 
988  // TODO static int listSerializers( std::vector< std::string > & );
989 };
990 
991 // ---------------------------------------------------------------
992 
995 
996 
998 {
999 public:
1001  virtual ~Statement_() {}
1002 
1004  virtual Statement copy() const = 0;
1005 
1007  virtual void subject( Node n ) = 0;
1008 
1010  virtual NodeRef subject() const = 0;
1011 
1013  virtual void predicate( Node n ) = 0;
1014 
1016  virtual NodeRef predicate() const = 0;
1017 
1019  virtual void object( Node n ) = 0;
1020 
1022  virtual NodeRef object() const = 0;
1023 
1025  virtual bool isComplete() const = 0;
1026 
1028  virtual bool match( Statement ) const = 0;
1029 
1031  virtual void clear() = 0;
1032 
1034  virtual std::string toString() const = 0;
1035 
1037  virtual std::string toString( const Format &) const = 0;
1038 
1040  virtual bool operator == ( Statement ) const = 0;
1041 };
1042 
1044 bool operator == ( Statement, Statement );
1045 
1046 // TODO operator << ( ostream &, Node )
1047 
1048 // ---------------------------------------------------------------
1049 
1052 
1053 
1054 class Stream_
1055 {
1056 public:
1058  virtual ~Stream_() {}
1059 
1061  virtual bool end() = 0;
1062 
1064  virtual bool next() = 0;
1065 
1067  // statement only valid until next() or closed.
1068  virtual StatementRef current() = 0;
1069 
1070  // TODO - iterator interface
1071 };
1072 
1073 // ---------------------------------------------------------------
1074 
1077 
1078 
1079 class URI_
1080 {
1081 public:
1083  virtual ~URI_() {}
1084 
1086  virtual URI copy() const = 0;
1087 
1089  virtual URI trim( World ) const = 0;
1090 
1092  virtual std::string toString() const = 0;
1093 
1095  virtual bool operator == (URI)const = 0;
1096 
1098  virtual bool isFileName() const = 0;
1099 
1101  virtual std::string toFileName() const = 0;
1102 };
1103 
1105 bool operator == ( URI, URI );
1106 
1107 // TODO operator << ( ostream &, Node )
1108 
1109 // ---------------------------------------------------------------
1110 
1111 //
1113 
1114 // Class C (child) is the implementation of the abstract class P (parent)
1115 // T is the type for the librdf pointer.
1116 // Requires C to have a type conversion operator that returns the
1117 // appropriate pointer.
1118 //
1119 template < class C, class P, typename T >
1120 T* deref( std::shared_ptr<C> a )
1121 {
1122  T* t = nullptr;
1123  P* c = static_cast< P* >( a.get() );
1124  if ( c ) t = *c;
1125  return t;
1126 }
1127 
1128 //
1130 
1134 //
1135 #define DEREF( A, b, c ) deref< A##_, _##A, b >( c )
1136 
1137 } // namespace rdf
1138 
1139 #endif
A shared pointer with constructors for the Query_ class.
Definition: rdfxx.h:335
virtual int count() const =0
Get the number of bound values in the result.
QueryString()
Create empty query.
Definition: rdfxx.h:948
Prefixes(World)
Constructor.
virtual bool match(Statement) const =0
Compare if the non-null nodes arethe same.
virtual std::vector< Node > objects(Node subject, Node predicate)=0
Get a list of objects that are linked to a subject by a particular predicate.
A shared pointer with constructors for the Serializer_ class.
Definition: rdfxx.h:290
virtual bool success() const =0
Check if the query got any results.
Literal(const char *val)
Create a PlainLiteral with English language.
Definition: rdfxx.h:558
T * deref(std::shared_ptr< C > a)
A template function that converts a shared pointer into the corresponding librdf pointer.
Definition: rdfxx.h:1120
void dataType(DataType t)
Set the data type.
Definition: rdfxx.h:579
virtual bool sync()=0
Save the model to its storage.
An exception object with stream semantics.
virtual URI toURI() const =0
Get the URI for a Node.
An abstract class defining the methods for an RDF URI.
Definition: rdfxx.h:1079
virtual ~ErrorClient()
Virtual destructor.
Definition: rdfxx.h:358
virtual bool isResource() const =0
Check if the node is a resource.
virtual bool isBlank() const =0
Check if the node is blank.
virtual Node getBoundValue(int offset) const =0
Get a value at a position.
virtual std::vector< Node > predicates(Node subject, Node object)=0
Get a list of predicates that link a subject and object.
void update(const std::string &oldPrefix, const std::string &newPrefix, URI)
Update a prefix and namespace.
virtual Statement copy() const =0
Clone the statement.
virtual std::string toString() const =0
Get a string representation.
virtual ~Node_()
Virtual destructor.
Definition: rdfxx.h:726
World world(const std::string &name)
Create, or return an existing world object.
virtual World getWorld()=0
Return a reference to the model&#39;s world.
virtual ~Stream_()
Virtual destructor.
Definition: rdfxx.h:1058
virtual int size() const =0
Get number of statements if possible. May return &lt;0 if not known.
void anonymous(URI uri)
insert an anonymous namespace
URI find(const std::string &)
Find the namespace URI with the supplied prefix.
virtual bool contains(Statement) const =0
Check if a statement is in the model.
bool angleBrackets
Enclose URI in &#39;&lt;&#39; ... &#39;&gt;&#39;.
Definition: rdfxx.h:407
std::shared_ptr< World_ > World
A shared pointer to a World object.
Definition: rdfxx.h:77
iterator()
Default constructor.
Stream()
Create a nullptr shared pointer.
virtual bool next()=0
Move to the next statement in the stream.
static Universe & instance()
Get a reference to the universe object.
DataType
A enumeration of the data types available for RDF literals.
Definition: rdfxx.h:495
Manages the prefixes and namespaces for a World.
Definition: rdfxx.h:425
A shared pointer with constructors for the LiteralNode_ class.
Definition: rdfxx.h:212
Concept
An enumeration of RDF and RDFS concepts.
Definition: rdfxx.h:94
virtual ~Serializer_()
Virtual destructor.
Definition: rdfxx.h:977
virtual iterator begin() const =0
Get iterator at start of result set.
A shared pointer with constructors for the Model_ class.
Definition: rdfxx.h:161
std::string prefixForm(URI)
Convert a URI and fragment to its prefix and fragment.
std::string language() const
Get the language.
Definition: rdfxx.h:597
virtual bool operator==(Statement) const =0
Compare with another statement.
virtual Stream toStream()=0
Get a pointer to a stream. The user controls its lifetime.
void base(URI uri)
Set the base URI.
Definition: rdfxx.h:442
Provide a C++ iterator over the results of a RDF query.
Definition: rdfxx.h:893
ResourceNode(World, URI)
Create resource node based on a URI.
DataType dataType() const
Get the data type.
Definition: rdfxx.h:591
virtual URI toURI() const =0
Get the URI for a Node.
An abstract class defining the methods for an RDF Stream.
Definition: rdfxx.h:1054
std::shared_ptr< QueryResults_ > QueryResults
A shared pointer to a set of query results.
Definition: rdfxx.h:86
bool asBoolean() const
Get the value as a boolean.
virtual ~QueryResults_()
Virtual destructor.
Definition: rdfxx.h:878
virtual ~World_()
Virtual destructor.
Definition: rdfxx.h:639
An abstract class defining the methods for an RDF Parser.
Definition: rdfxx.h:808
An abstract class defining the methods for an RDF Serializer.
Definition: rdfxx.h:973
virtual StatementRef current()=0
Get a reference to the current statement.
bool isBase(URI) const
Check if a URI is the base URI.
An abstract class defining the methods for an RDF Literal Node.
Definition: rdfxx.h:775
A shared pointer with constructors for the BlankNode_ class.
Definition: rdfxx.h:226
virtual std::string toString() const =0
Convert all the names and values to a string.
virtual void registerErrorClient(ErrorClient *, bool warnings, bool errors)=0
Register a client object to receive error and/or error messages.
virtual std::string toString() const =0
Get a string representation of the node.
virtual bool operator==(URI) const =0
Compare with another URI.
virtual ~URI_()
Virtual destructor.
Definition: rdfxx.h:1083
static DataType toDataType(const std::string &xsd_type)
Convert an xsd form into a data type.
std::string prefLang
Restrict to this language when there are alternatives.
Definition: rdfxx.h:415
Statement()
Create a nullptr based default statement.
An abstract class defining the methods for an RDF Statement.
Definition: rdfxx.h:997
virtual Serializer defaultSerializer()=0
Get a default serialiser - depreicated.
virtual bool setNamespace(URI, const std::string &prefix)=0
Add a namespace and prefix to the output.
virtual Literal toLiteral() const =0
Get the Literal data for the node.
bool operator==(Statement, Statement)
Check for equality of two statements.
URI uriForm(const std::string &)
Convert a prefix and fragment to a URI and fragment.
Instructions for converting a node to a string.
Definition: rdfxx.h:403
iterator & operator=(const QueryResult_ &)=delete
No assignment allowed for these iterators.
void addCondition(const std::string &condition)
Add a condition to the query.
virtual std::vector< Node > arcsIn(Node object)=0
Get a list of predicates connected to an object.
An abstract class defining the methods for an RDF Node.
Definition: rdfxx.h:722
virtual void handleError(const std::string &message)=0
The function that will be called when an error is detected.
void value(const std::string &v)
Set the value.
Definition: rdfxx.h:582
A class for assistingin the preparation of a SPARQL query.
Definition: rdfxx.h:936
An abstract class defining the methods for an RDF Resource Node.
Definition: rdfxx.h:755
std::weak_ptr< Statement_ > StatementRef
A weak shared pointer to a statement.
Definition: rdfxx.h:89
void addPrefix(const std::string &id, const std::string &uri)
Add a prefix and namespace to the query.
LiteralNode(World, const Literal &)
Create a literal node using a literal value.
Model()
Create an empty model.
Definition: rdfxx.h:165
virtual NodeRef predicate() const =0
Get a reference to the predicate node.
std::string toString() const
Default conversion to a string.
std::map< std::string, URI >::iterator end()
get the end iterator for the saves prefixes.
Definition: rdfxx.h:488
Literal()
Default constructor.
Serializer()
Create a nullptr shared pointer.
URI()
Default constructor.
Definition: rdfxx.h:131
BlankNode(World, const std::string &id="")
Create a blank node using a supplied identifier.
An abstract class defining the methods for an RDF Query.
Definition: rdfxx.h:827
virtual int getLimit() const =0
Get the max number of results to be returned.
virtual iterator & operator++()
Move to next result.
A shared pointer with constructors for the ResourceNode_ class.
Definition: rdfxx.h:193
Hold the value, language and data type for an RDF literal.
Definition: rdfxx.h:537
virtual std::string toString() const =0
Get a string representaion of the statement.
An abstract class defining the methods for a set of Query Results.
Definition: rdfxx.h:874
virtual ~Query_()
Virtual destructor.
Definition: rdfxx.h:831
bool quotes
Put values in quotes.
Definition: rdfxx.h:413
virtual QueryResult_ & operator*() const
Dereference the iterator to get a result.
std::weak_ptr< Node_ > NodeRef
A weak shared pointer to a Node object.
Definition: rdfxx.h:83
void setVariables(const std::string &variables)
Set the variables to search for.
std::string asString() const
Get the value as a string.
Definition: rdfxx.h:600
virtual bool operator!=(const iterator &) const
Check for inequality.
bool usePrefixes
Replace namespaces with prefixes.
Definition: rdfxx.h:406
Query(World, const std::string &query, const std::string &lang="sparql")
Create a query.
An abstract class defining the methods for an RDF Query Result.
Definition: rdfxx.h:849
virtual iterator end() const =0
Get iterator past the end of result set.
virtual ~Model_()
Virtual destructor.
Definition: rdfxx.h:665
An abstract class defining the methods for an RDF Model.
Definition: rdfxx.h:661
virtual URI trim(World) const =0
Strip off fragment.
virtual bool isFileName() const =0
Check if URI represents a file path.
bool showDataType
Include data type as for example: ^^xsd:integer.
Definition: rdfxx.h:416
double asDouble() const
Get the value as a double.
static std::string toXSD(DataType)
Convert a data type into an xsd form,.
virtual std::string getBoundName(int offset) const =0
Get the variable name at a position.
virtual bool add(Node subject, Node predicate, Node object)=0
Add the nodes of a statement to the model.
An abstract class defining the methods for an RDF World.
Definition: rdfxx.h:635
virtual bool toFile(const std::string &filename, Model)=0
Write the model to a file.
virtual void clear()=0
Remove the nodes.
bool showLanguage
Include language identifier as for example: &quot;@en&quot;.
Definition: rdfxx.h:414
static std::vector< std::string > listParsers(World)
Get a list of parser names with their syntax URIs.
virtual std::string toString() const =0
Get a string representation of the node.
virtual bool end()=0
Check if at the end of the stream.
virtual void deregisterErrorClient(ErrorClient *)=0
Remove a client that was to get error messages.
virtual URI copy() const =0
Clonethe URI.
virtual NodeRef subject() const =0
Get a reference to the subject node.
virtual int listItemOrdinal() const =0
Get the ordinal value for a list item.
A singleton class responsible for managing the World objects.
Definition: rdfxx.h:377
URI dataTypeURI(World) const
Get the data type as a URI.
virtual bool parseIntoModel(Model, URI uri, URI base_uri)=0
Parse a data source into a model.
A shared pointer with constructors for the Statement_ class.
Definition: rdfxx.h:242
virtual std::vector< Node > subjects(Node predicate, Node object)=0
Get a list of subjects that are linked to an object by a particular predicate.
URI base() const
Get the base URI.
Definition: rdfxx.h:451
A shared pointer with constructors for the Stream_ class.
Definition: rdfxx.h:313
Client that is notified of errors and/or warnings.
Definition: rdfxx.h:354
A shared pointer with constructors for the URI_ class.
Definition: rdfxx.h:127
virtual bool update(Statement old, Statement _new)=0
Update a statement in the model.
int asInteger() const
Get the value as an integer.
std::shared_ptr< Node_ > Node
A shared pointer to a Node object.
Definition: rdfxx.h:188
An abstract class defining the methods for an RDF blank Node.
Definition: rdfxx.h:792
virtual NodeRef object() const =0
Get a reference to the object node.
virtual void handleWarning(const std::string &message)=0
The function that will be called when a warning is detected.
virtual ~Statement_()
Virtual destructor.
Definition: rdfxx.h:1001
virtual std::string toString() const =0
Get a string representation of the node.
virtual bool isLiteral() const =0
Check if the node is a literal.
std::string removeBase(URI) const
Strip the base URI from a URI.
virtual std::string toFileName() const =0
Convert the URI to a file path name.
Parser(World, const std::string &name, const std::string &syntax_mime=std::string())
Create an RDF parser using the specified parsing engine.
virtual ~Parser_()
Virtual destructor.
Definition: rdfxx.h:812
virtual bool setLimit(int)=0
Set the max number of results returned.
std::string blank
Name to give blank nodes.
Definition: rdfxx.h:410
virtual std::vector< Node > arcsOut(Node subject)=0
Get a list of predicates connected to a ssubject.
virtual bool isComplete() const =0
Check if all three nodes are defined.
void insert(const std::string &prefix, URI)
Save a prefix and its corresponding namespace URI.
std::weak_ptr< World_ > WorldRef
A weak shared pointer to a World object.
Definition: rdfxx.h:80
virtual bool operator==(const iterator &) const
Check for equality.
void language(const std::string &lang)
Set the language.
Definition: rdfxx.h:576
virtual std::string toString() const =0
Get a string representation of the node.
virtual Prefixes & prefixes()=0
Get a reference to the saved prefixes.
void orderBy(const std::string &order)
Add an ordering clause to the query.
virtual std::string toString()=0
Convert all results to a string. This consumes the results.
std::map< std::string, URI >::iterator begin()
Get an iterator for the saved prefixes.
Definition: rdfxx.h:485
A shared pointer with constructors for the Parser_ class.
Definition: rdfxx.h:267
virtual QueryResults execute(Model)=0
Run the query on a model.