Пример #1
0
  void RdfStorePrivate::Save(std::string filename, std::string format)
  {
    if (format == "") format = "turtle";

    librdf_uri* baseUri = RdfUriToLibRdfUri(m_BaseUri);

    librdf_serializer* s = librdf_new_serializer(m_World, format.c_str(), nullptr, nullptr);

    if(!s)
    {
      mitkThrow() << "RDF Library Error";
    }

    for (PrefixMap::const_iterator i = m_Prefixes.begin(); i != m_Prefixes.end(); i++)
    {
      librdf_serializer_set_namespace(s, RdfUriToLibRdfUri(i->second), i->first.c_str());
    }

    FILE* f = fopen(filename.c_str(), "w+");

    librdf_serializer_serialize_model_to_file_handle(s, f, baseUri, m_Model);

    librdf_free_serializer(s);
    librdf_free_uri(baseUri);
    fclose(f);
  }
Пример #2
0
/*
 * Iterator function: map a [namespace, uri] tuple into a namespace registered with
 * the serializer_value, which is a librdf_serializer pointer cast as a VALUE.
 */
static VALUE
rleaf_set_serializer_ns( VALUE nspair, VALUE serializer_value ) {
	librdf_serializer *serializer = (librdf_serializer *)serializer_value;
	VALUE ns = Qnil;
	librdf_uri *nsuri;

	Check_Type( nspair, T_ARRAY );
	if ( RARRAY_LEN(nspair) != 2 )
		rb_raise( rb_eArgError, "namespace pair must be [key, value]" );

	ns    = rb_obj_as_string( rb_ary_entry(nspair, 0) );
	nsuri = rleaf_object_to_librdf_uri( rb_ary_entry(nspair, 1) );

	librdf_serializer_set_namespace( serializer, nsuri, (const char *)RSTRING_PTR(ns) );

	return Qnil;
}
Пример #3
0
int
lua_bindings_redland_serializer_set_namespace(lua_State *L) {
   librdf_serializer **pp_serializer
      =  (librdf_serializer **) luaL_checkudata(
            L
         ,  -2
         ,  serializer_userdata_type );

   const char *prefix =  NULL;
   lua_getfield(L, -1, "prefix");
   if (!lua_isnil(L, -1)) {
      prefix =  luaL_checkstring(L, -1);
   }
   lua_pop(L, 1);

   librdf_uri *p_uri =  NULL;
   lua_getfield(L, -1, "uri");
   if (!lua_isnil(L, -1)) {
      librdf_uri **pp_uri
         =  (librdf_uri **) luaL_checkudata(
               L
            ,  -1
            ,  uri_userdata_type );
      p_uri =  *pp_uri;
   }
   lua_pop(L, 1);

   lua_pop(L, 2);

   int result =  librdf_serializer_set_namespace(
         *pp_serializer
      ,  p_uri
      ,  prefix );
   lua_pushboolean(L, result);
   return 1;
}