how to dump query results into nt format in virtuoso

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. 

 

转载于:https://www.cnblogs.com/RuiYan/p/4516142.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值