码迷,mamicode.com
首页 > 其他好文 > 详细

how to dump query results into nt format in virtuoso

时间:2015-05-20 07:07:37      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

This is on ubuntu 14.04 LTS

1. you need to install virtuoso (you can refer to my previous post)

2. open your virtuoso service 

3. do 

./isql 1111

to invoke the virtuosl‘s isql interface

4. copy and past the following: (source: click me )

/**
 * Dumps the result of the given select-sparql query into a file
 * or a sequence of files based on a file size limit.
 *
 * @param query A select query. Only the first three variables in the projection will be dumped
 * @param out_file A base filename. ‘.nt‘ will be autmatically appended.
 * @param file_length_limit A result set is split to multiple files according to this limit.
 *        If it is greater 0 a sequence number will be appended to the filename.
 */
drop procedure dump_query_nt;
create procedure dump_query_nt(in query varchar, in out_file varchar, in file_length_limit integer := -1)
{
    declare file_name varchar;
    declare env, ses any;
    declare ses_len, max_ses_len, file_len, file_idx integer;
    declare state, msg, descs any;
    declare chandle any;
    declare sub any;
    declare sql any;
    set isolation = uncommitted;
    max_ses_len := 10000000;
    file_len := 0;
    file_idx := 1;

    if(file_length_limit >= 0) {
        file_name := sprintf (%s-%06d.nt, out_file, file_idx);
    } else {
        file_name := sprintf (%s.nt, out_file);
    }

    string_to_file (file_name || .query, query, -2);
    env := vector (0, 0, 0);
    ses := string_output ();


    state := 00000;
    sql := sprintf(sparql define input:storage "" %s, query);

    exec(sql, state, msg, vector (), 0, descs, null, chandle);
    if (state <> 00000) {
        signal (state, msg);
    }

    while(exec_next(chandle, state, msg, sub) = 0) {
        if (state <> 00000) {
            signal (state, msg);
        }

        http_nt_triple (env, sub[0], sub[1], sub[2], ses);
        ses_len := length (ses);

        if (ses_len > max_ses_len) {
            file_len := file_len + ses_len;
            if (file_length_limit >= 0 and file_len > file_length_limit) {
                string_to_file (file_name, ses, -1);
                file_len := 0;
                file_idx := file_idx + 1;
                file_name := sprintf (%s-%06d.nt, out_file, file_idx);
                env := vector (0, 0, 0);
            }
            else {
              string_to_file (file_name, ses, -1);
            }

            ses := string_output ();
        }
    }
    if (length (ses)) {
        string_to_file (file_name, ses, -1);
    }

    exec_close(chandle);
};

5. hit enter to regester this dump_query_nt function

6. an example of usage of this function is as follows:

dump_query_nt(Select ?s ?p ?o { ?s a ?c . ?s ?p ?o . }, /tmp/result);

you input this in the prompt, make sure /temp/result directory is accessible for virtuoso. you could go to virtuoso.ini (under certain directory) to config it. 

 

how to dump query results into nt format in virtuoso

标签:

原文地址:http://www.cnblogs.com/RuiYan/p/4516142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!