2
* This file is part of Soprano Project
4
* Copyright (C) 2006 Daniele Galdi <daniele.galdi@gmail.com>
5
* Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; see the file COPYING.LIB. If
19
* not, write to the Free Software Foundation, Inc., 51 Franklin
20
* Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#include "redlandutil.h"
27
#include "statement.h"
28
#include "redlandworld.h"
31
Soprano::Node Soprano::Redland::Util::createNode( librdf_node *node )
33
if ( librdf_node_is_resource( node ) ) {
34
librdf_uri *uri = librdf_node_get_uri( node );
35
return Soprano::Node( QUrl::fromEncoded( (const char *)librdf_uri_as_string(uri), QUrl::StrictMode ) );
37
else if ( librdf_node_is_blank( node ) ) {
38
return Soprano::Node( QUrl::fromEncoded( (const char *)librdf_node_get_blank_identifier( node ), QUrl::StrictMode ), Node::BlankNode );
40
else if ( librdf_node_is_literal( node ) ) {
41
librdf_uri* datatype = librdf_node_get_literal_value_datatype_uri( node );
44
return Soprano::Node( Soprano::LiteralValue( (const char *)librdf_node_get_literal_value( node ) ) );
46
return Soprano::Node( Soprano::LiteralValue::fromString( QString::fromUtf8( (const char *)librdf_node_get_literal_value( node ) ),
47
QUrl::fromEncoded( (const char *)librdf_uri_as_string( datatype ),
49
QString::fromUtf8( librdf_node_get_literal_value_language( node ) ) );
52
return Soprano::Node();
55
librdf_node *Soprano::Redland::Util::createNode( const Node &node )
57
librdf_world *world = World::self()->worldPtr();
59
if ( node.isResource() ) {
60
return librdf_new_node_from_uri_string( world, (unsigned char *)node.uri().toEncoded().data() );
62
else if ( node.isBlank() ) {
63
return librdf_new_node_from_blank_identifier( world, (unsigned char *) node.uri().toEncoded().data() );
65
else if ( node.isLiteral() ) {
66
return librdf_new_node_from_typed_literal( world,
67
(unsigned char *)node.literal().toString().toUtf8().data(),
68
node.language().toUtf8().data(),
69
librdf_new_uri( world, (const unsigned char*)node.dataType().toEncoded().data() ) );
75
librdf_statement *Soprano::Redland::Util::createStatement( const Statement &statement )
77
librdf_world *world = World::self()->worldPtr();
79
librdf_node *subject = createNode( statement.subject() );
80
librdf_node *predicate = createNode( statement.predicate() );
81
librdf_node *object = createNode( statement.object() );
83
return librdf_new_statement_from_nodes( world, subject, predicate, object );
86
Soprano::Statement Soprano::Redland::Util::createStatement( librdf_statement *st )
88
librdf_node *subject = librdf_statement_get_subject( st );
89
librdf_node *predicate = librdf_statement_get_predicate( st );
90
librdf_node *object = librdf_statement_get_object( st );
92
return Soprano::Statement( createNode( subject), createNode( predicate), createNode( object ) );
95
const char *Soprano::Redland::Util::queryType( const Query &query )
97
if ( query.type() == Query::RDQL )
101
else if (query.type() == Query::SPARQL )
108
void Soprano::Redland::Util::freeNode( librdf_node* node )
111
librdf_free_node( node );
116
void Soprano::Redland::Util::freeStatement( librdf_statement* statement )
119
librdf_free_statement( statement );