summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-05-11 23:32:18 +0000
committerDavid Robillard <d@drobilla.net>2011-05-11 23:32:18 +0000
commit3feaad1a898d40e54f3ef7e076a05dd960eefefa (patch)
tree3c4e557a8ca63b78470d530e0efe10263cee9bc5
parent9f6becfdd80dfe4cf1d99d0aefa8b257eb1b0c8d (diff)
downloadsord-3feaad1a898d40e54f3ef7e076a05dd960eefefa.tar.gz
sord-3feaad1a898d40e54f3ef7e076a05dd960eefefa.tar.bz2
sord-3feaad1a898d40e54f3ef7e076a05dd960eefefa.zip
Pass environment to sord write methods for CURIE abbreviation.
git-svn-id: http://svn.drobilla.net/sord/trunk@108 3d64ff67-21c5-427c-a301-fe4f08042e5a
-rw-r--r--sord/sord.h3
-rw-r--r--sord/sordmm.hpp13
-rw-r--r--src/sordi.c21
-rw-r--r--src/syntax.c12
4 files changed, 31 insertions, 18 deletions
diff --git a/sord/sord.h b/sord/sord.h
index 68c0289..8174f55 100644
--- a/sord/sord.h
+++ b/sord/sord.h
@@ -435,6 +435,7 @@ sord_quad_match(const SordQuad x, const SordQuad y);
SORD_API
bool
sord_read_file(SordModel* model,
+ SerdEnv* env,
const uint8_t* uri,
SordNode* graph,
const uint8_t* blank_prefix);
@@ -445,6 +446,7 @@ sord_read_file(SordModel* model,
SORD_API
bool
sord_read_file_handle(SordModel* model,
+ SerdEnv* env,
FILE* fd,
const uint8_t* base_uri,
SordNode* graph,
@@ -456,6 +458,7 @@ sord_read_file_handle(SordModel* model,
SORD_API
bool
sord_read_string(SordModel* model,
+ SerdEnv* env,
const uint8_t* str,
const uint8_t* base_uri);
diff --git a/sord/sordmm.hpp b/sord/sordmm.hpp
index d37d6e5..854e647 100644
--- a/sord/sordmm.hpp
+++ b/sord/sordmm.hpp
@@ -390,9 +390,10 @@ public:
inline const Node& base_uri() const { return _base; }
- inline void load_file(const std::string& uri);
+ inline void load_file(SerdEnv* env, const std::string& uri);
- inline void load_string(const char* str,
+ inline void load_string(SerdEnv* env,
+ const char* str,
size_t len,
const std::string& base_uri,
const std::string lang = "turtle");
@@ -432,12 +433,14 @@ Model::Model(World& world, const std::string& base_uri)
}
inline void
-Model::load_string(const char* str,
+Model::load_string(SerdEnv* env,
+ const char* str,
size_t len,
const std::string& base_uri,
const std::string lang)
{
sord_read_string(_c_obj,
+ env,
(const uint8_t*)str,
(const uint8_t*)base_uri.c_str());
}
@@ -448,10 +451,10 @@ inline Model::~Model()
}
inline void
-Model::load_file(const std::string& data_uri)
+Model::load_file(SerdEnv* env, const std::string& data_uri)
{
// FIXME: blank prefix
- sord_read_file(_c_obj, (const uint8_t*)data_uri.c_str(), NULL,
+ sord_read_file(_c_obj, env, (const uint8_t*)data_uri.c_str(), NULL,
(const uint8_t*)"b");
}
diff --git a/src/sordi.c b/src/sordi.c
index 1f663ea..235c67a 100644
--- a/src/sordi.c
+++ b/src/sordi.c
@@ -120,8 +120,9 @@ main(int argc, char** argv)
SordWorld* world = sord_world_new();
SordModel* sord = sord_new(world, SORD_SPO|SORD_OPS, false);
+ SerdEnv* env = serd_env_new();
- bool success = sord_read_file(sord, input, NULL, NULL);
+ bool success = sord_read_file(sord, env, input, NULL, NULL);
printf("Loaded %zu statements\n", sord_num_nodes(world));
@@ -131,13 +132,20 @@ main(int argc, char** argv)
return 1;
}
- SerdEnv* env = serd_env_new();
+ SerdEnv* write_env = serd_env_new();
+
SerdWriter* writer = serd_writer_new(
- SERD_TURTLE, SERD_STYLE_ABBREVIATED|SERD_STYLE_RESOLVED,
- env, &base_uri, file_sink, stdout);
+ SERD_TURTLE,
+ SERD_STYLE_ABBREVIATED|SERD_STYLE_RESOLVED|SERD_STYLE_CURIED,
+ write_env, &base_uri, file_sink, stdout);
+
+ // Write @prefix directives
+ serd_env_foreach(env,
+ (SerdPrefixSink)serd_writer_set_prefix,
+ writer);
- // Query
- SordQuad pat = { 0, 0, 0, 0 };
+ // Write statements
+ SordQuad pat = { 0, 0, 0, 0 };
SordIter* iter = sord_find(sord, pat);
for (; !sord_iter_end(iter); sord_iter_next(iter)) {
SordQuad tup;
@@ -156,6 +164,7 @@ main(int argc, char** argv)
serd_writer_free(writer);
serd_env_free(env);
+ serd_env_free(write_env);
sord_free(sord);
diff --git a/src/syntax.c b/src/syntax.c
index 1964d24..ff2f248 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -207,6 +207,7 @@ sord_file_uri_to_path(const uint8_t* uri)
SORD_API
bool
sord_read_file(SordModel* model,
+ SerdEnv* env,
const uint8_t* uri,
SordNode* graph,
const uint8_t* blank_prefix)
@@ -223,7 +224,8 @@ sord_read_file(SordModel* model,
return false;
}
- const bool ret = sord_read_file_handle(model, fd, uri, graph, blank_prefix);
+ const bool ret = sord_read_file_handle(
+ model, env, fd, uri, graph, blank_prefix);
fclose(fd);
return ret;
}
@@ -231,6 +233,7 @@ sord_read_file(SordModel* model,
SORD_API
bool
sord_read_file_handle(SordModel* model,
+ SerdEnv* env,
FILE* fd,
const uint8_t* base_uri_str_in,
SordNode* graph,
@@ -244,8 +247,6 @@ sord_read_file_handle(SordModel* model,
fprintf(stderr, "Invalid base URI <%s>\n", base_uri_str);
}
- SerdEnv* env = serd_env_new();
-
SerdNode base_uri_node = serd_node_from_string(SERD_URI, base_uri_str);
serd_env_set_base_uri(env, &base_uri_node);
@@ -263,7 +264,6 @@ sord_read_file_handle(SordModel* model,
const SerdStatus ret = serd_reader_read_file(state.reader, fd, base_uri_str);
serd_reader_free(state.reader);
- serd_env_free(env);
free(base_uri_str);
return (ret == SERD_SUCCESS);
@@ -272,6 +272,7 @@ sord_read_file_handle(SordModel* model,
SORD_API
bool
sord_read_string(SordModel* model,
+ SerdEnv* env,
const uint8_t* str,
const uint8_t* base_uri_str_in)
{
@@ -283,8 +284,6 @@ sord_read_string(SordModel* model,
fprintf(stderr, "Invalid base URI <%s>\n", base_uri_str);
}
- SerdEnv* env = serd_env_new();
-
SerdNode base_uri_node = serd_node_from_string(SERD_URI, base_uri_str);
serd_env_set_base_uri(env, &base_uri_node);
@@ -298,7 +297,6 @@ sord_read_string(SordModel* model,
const SerdStatus status = serd_reader_read_string(state.reader, str);
serd_reader_free(state.reader);
- serd_env_free(env);
free(base_uri_str);
return (status == SERD_SUCCESS);