Exemplo n.º 1
0
librdf_statement*
librdf_new_statement_from_statement(librdf_statement* statement)
{
  LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(statement, librdf_statement, NULL);

  if(!statement)
    return NULL;
  
  return raptor_statement_copy(statement);
}
Exemplo n.º 2
0
static int
raptor_json_serialize_statement(raptor_serializer* serializer, 
                                raptor_statement *statement)
{
  raptor_json_context* context = (raptor_json_context*)serializer->context;

  if(context->is_resource) {
    raptor_statement* s = raptor_statement_copy(statement);
    if(!s)
      return 1;
    return raptor_avltree_add(context->avltree, s);
  }

  if(context->need_subject_comma) {
    raptor_iostream_write_byte(',', serializer->iostream);
    raptor_json_writer_newline(context->json_writer);
  }

  /* start triple */
  raptor_json_writer_start_block(context->json_writer, '{');
  raptor_json_writer_newline(context->json_writer);

  /* subject */
  raptor_iostream_string_write((const unsigned char*)"\"subject\" : ",
                               serializer->iostream);
  switch(statement->subject->type) {
    case RAPTOR_TERM_TYPE_URI:
      raptor_json_writer_uri_object(context->json_writer,
                                    statement->subject->value.uri);
      break;
          
    case RAPTOR_TERM_TYPE_BLANK:
      raptor_json_writer_blank_object(context->json_writer,
                                      statement->subject->value.blank.string);
      break;

    case RAPTOR_TERM_TYPE_LITERAL:
    case RAPTOR_TERM_TYPE_UNKNOWN:
      default:
        raptor_log_error_formatted(serializer->world, RAPTOR_LOG_LEVEL_ERROR,
                                   NULL, 
                                   "Triple has unsupported subject term type %d", 
                                   statement->subject->type);
        break;
  }
  raptor_iostream_write_byte(',', serializer->iostream);
  raptor_json_writer_newline(context->json_writer);
  
  /* predicate */
  raptor_iostream_string_write((const unsigned char*)"\"predicate\" : ",
                               serializer->iostream);
  raptor_json_writer_uri_object(context->json_writer,
                                statement->predicate->value.uri);
  raptor_iostream_write_byte(',', serializer->iostream);
  raptor_json_writer_newline(context->json_writer);

  /* object */
  raptor_iostream_string_write((const unsigned char*)"\"object\" : ",
                               serializer->iostream);
  switch(statement->object->type) {
    case RAPTOR_TERM_TYPE_URI:
      raptor_json_writer_uri_object(context->json_writer,
                                    statement->object->value.uri);
      break;
          
    case RAPTOR_TERM_TYPE_LITERAL:
      raptor_json_writer_literal_object(context->json_writer,
                                        statement->object->value.literal.string,
                                        statement->object->value.literal.language, 
                                        statement->object->value.literal.datatype,
                                        "value", "type");
      break;

    case RAPTOR_TERM_TYPE_BLANK:
      raptor_json_writer_blank_object(context->json_writer,
                                      statement->object->value.blank.string);
      break;

    case RAPTOR_TERM_TYPE_UNKNOWN:
      default:
        raptor_log_error_formatted(serializer->world, RAPTOR_LOG_LEVEL_ERROR,
                                   NULL,
                                   "Triple has unsupported object term type %d", 
                                   statement->object->type);
        break;
  }
  raptor_json_writer_newline(context->json_writer);

  /* end triple */
  raptor_json_writer_end_block(context->json_writer, '}');

  context->need_subject_comma = 1;
  return 0;
}