Hi

I created a new function *static Node createFromN3( const QString& n3 )*. It
creates a Soprano::Node from an N3 String. I've *tried *to document it in
the header file, but I'm not too sure if it's correct (the documentation).
It would be nice if somebody could go through it, please.

The Patch had a base directory of *kdesupport/soprano/soprano/
*
- Vishesh Handa
Index: node.cpp
===================================================================
--- node.cpp	(revision 1105231)
+++ node.cpp	(working copy)
@@ -25,9 +25,8 @@
 #include <QtCore/QString>
 #include <QtCore/QUrl>
 #include <QtCore/QDebug>
+#include <QtCore/QRegExp>
 
-
-
 class Soprano::Node::NodeData : public QSharedData
 {
 public:
@@ -424,7 +423,32 @@
     }
 }
 
+Soprano::Node Soprano::Node::createFromN3( const QString& n3 )
+{
+	if( n3.length() == 0 )
+		return Soprano::Node();
 
+	if( n3[0] == '<' ) {
+		// Resource <uri>
+		QString uri = n3.mid( 1, n3.length() -2 );
+		return Soprano::Node( QUrl(uri) );
+	}
+
+	if( n3[0] == '_' ) {
+		// Blank Node _:id
+		QString id = n3.mid(2);
+		return Soprano::Node(id);
+	}
+
+	//Literal
+	QRegExp regEx("\"(.*)\"..<(.*)>");
+	if(n3.indexOf(regEx) != -1) {
+		return Soprano::Node( Soprano::LiteralValue::fromString(regEx.cap(1), regEx.cap(2)) );
+	}
+
+	return Soprano::Node();
+}
+
 QDebug operator<<( QDebug s, const Soprano::Node& n )
 {
     switch( n.type() ) {
Index: node.h
===================================================================
--- node.h	(revision 1105231)
+++ node.h	(working copy)
@@ -366,7 +366,8 @@
          */
         static Node createLiteralNode( const LiteralValue& value );
 
-        /**
+		static Node createFromN3( const QString& n3 );
+		/**
          * Convenience method to create a literal node.
          * Using this method instead of the constructor
          * may result in better readable code.
_______________________________________________
Nepomuk mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/nepomuk

Reply via email to