www.openlinksw.com
docs.openlinksw.com

Book Home

Contents
Preface

Virtuoso Functions Guide

Administration
Aggregate Functions
Array Manipulation
BPEL APIs
Backup
Compression
Cursor
Date & Time Manipulation
Debug
Dictionary Manipulation
Encoding & Decoding
File Manipulation
Free Text
Hashing / Cryptographic
LDAP
Locale
Mail
Miscellaneous
Number
Phrases
RDF data
db.dba.rdf_64bit_upg...
db.dba.rdf_audit_met...
db.dba.rdf_backup_me...
db.dba.rdf_convert_r...
db.dba.rdf_datatype_...
db.dba.rdf_graph_col...
db.dba.rdf_graph_dif...
db.dba.rdf_graph_gro...
db.dba.rdf_graph_gro...
db.dba.rdf_langmatch...
db.dba.rdf_load_rdfa
db.dba.rdf_load_rdfx...
db.dba.rdf_load_rdfx...
db.dba.rdf_quad_uri
db.dba.rdf_quad_uri_...
db.dba.rdf_quad_uri_...
db.dba.rdf_regex
db.dba.rdf_restore_m...
db.dba.rdf_suo_apply...
db.dba.rdf_suo_diff_...
db.dba.rdf_triples_t...
db.dba.rdf_triples_t...
db.dba.rdf_ttl2hash
db.dba.rdf_void_stor...
db.dba.sparql_eval
db.dba.sparql_eval_t...
db.dba.sparql_rdb2rd...
db.dba.sparql_rdb2rd...
db.dba.sparql_rexec
db.dba.sparql_rexec_...
db.dba.sparql_rexec_...
db.dba.sparql_select...
db.dba.ttlp
db.dba.ttlp_mt
db.dba.ttlp_mt_local...
group_concat
isref
sample
__xml_get_ns_prefix
__xml_get_ns_uri
http_nt_triple
http_ttl_triple
iri_split
ld_dir
rdfs_rule_set
sparql_to_sql_text
Remote SQL Data Source
Replication
SOAP
SQL
String
Transaction
Type Mapping
UDDI
User Defined Types & The CLR
VAD
Virtuoso Java PL API
Virtuoso Server Extension Interface (VSEI)
Web & Internet
XML
XPATH & XQUERY

Functions Index

http_ttl_triple

outputs next triple to ses in TTL serialization.
http_ttl_triple (in env any, in arg1 any, in arg2 any, in arg3 any, in ses any);
Description

Outputs next triple to ses in TTL serialization. This function does not terminate the printed triple in hope that the next triple will has same "s" or pair of "s" and "p". So "intermediate" semicolon or comma can be used instead of "trailing" dot.

Parameters
env – An array of special format:
# vector (dict_new (some big size), 0, '', '', '', 0, 0, 0, 0), for ex.:
vector (dict_new (16000), 0, '', '', '', 0, 0, 0, 0);	
The first item of the vector is dictionary of declared namespaces. Its size should be big enough, but not greater than 16000 because the function will never try to create more than 8000 of namespaces for S and O and more than 8000 of namespaces for P and types. Thus 16000 max is possible grand total for all four.
arg1 – Triple subject.
arg2 – Triple predicate.
arg3 – Triple object.
ses – Session output.
Return Types

Any

Examples

Example 1

CREATE PROCEDURE dump_one_graph 
  ( IN  srcgraph           VARCHAR  , 
    IN  out_file           VARCHAR  , 
    IN  file_length_limit  INTEGER  := 1000000000
  )
  {
    DECLARE  file_name  varchar;
    DECLARE  env, ses      any;
    DECLARE  ses_len, 
             max_ses_len, 
             file_len, 
             file_idx      integer;
    SET ISOLATION = 'uncommitted';
    max_ses_len := 10000000;
    file_len := 0;
    file_idx := 1;
    file_name := sprintf ('%s%06d.ttl', out_file, file_idx);
    string_to_file ( file_name || '.graph', 
                     srcgraph, 
                     -2
                   );
    string_to_file ( file_name, 
                     sprintf ( '# Dump of graph <%s>, as of %s\n', 
                               srcgraph, 
                               CAST (NOW() AS VARCHAR)
                             ), 
                     -2
                   );
    env := vector (dict_new (16000), 0, '', '', '', 0, 0, 0, 0);
    ses := string_output ();
    FOR (SELECT * FROM ( SPARQL DEFINE input:storage "" 
                         SELECT ?s ?p ?o { GRAPH `iri(?:srcgraph)` { ?s ?p ?o } } 
                       ) AS sub OPTION (LOOP)) DO
      {
        http_ttl_triple (env, "s", "p", "o", ses);
        ses_len := length (ses);
        IF (ses_len > max_ses_len)
          {
            file_len := file_len + ses_len;
            IF (file_len > file_length_limit)
              {
                http (' .\n', ses);
                string_to_file (file_name, ses, -1);
                file_len := 0;
                file_idx := file_idx + 1;
                file_name := sprintf ('%s%06d.ttl', out_file, file_idx);
                string_to_file ( file_name, 
                                 sprintf ( '# Dump of graph <%s>, as of %s (part %d)\n', 
                                           srcgraph, 
                                           CAST (NOW() AS VARCHAR), 
                                           file_idx), 
                                 -2
                               );
                 env := vector (dict_new (16000), 0, '', '', '', 0, 0, 0, 0);
              }
            ELSE
              string_to_file (file_name, ses, -1);
            ses := string_output ();
          }
      }
    IF (LENGTH (ses))
      {
        http (' .\n', ses);
        string_to_file (file_name, ses, -1);
      }
  }
;

Example 2

create procedure dump_rdftriples_to_ttl(inout triples any, inout ses any)
{
  declare env any;
  declare tcount, tctr integer;
  tcount := length (triples);
  if (0 = tcount)
    {
      http ('# Empty TURTLE\n', ses);
      return;
    }
  env := vector (dict_new (__min (tcount, 16000)), 0, '', '', '', 0, 0, 0, 0);
  { whenever sqlstate '*' goto end_pred_sort;
    rowvector_subj_sort (triples, 1, 1);
end_pred_sort: ;
  }
  { whenever sqlstate '*' goto end_subj_sort;
    rowvector_subj_sort (triples, 0, 1);
end_subj_sort: ;
  }
  for (tctr := 0; tctr < tcount; tctr := tctr + 1)
    {
      http_ttl_triple (env, triples[tctr][0], triples[tctr][1], triples[tctr][2], ses);
    }
  http (' .', ses);
}
;