<commit_before>:- module(
  ctriples_write_graph,
  [
    ctriples_write_graph/3 % +Write:or([atom,stream])
                           % ?Graph:atom
                           % +Options:list(nvpair)
  ]
).

/** <module> C-Triples write: graph

Writes the given graph (or all currently stored triples) to a source.

@author <NAME>
@version 2014/03-2014/06, 2014/08-2014/09
*/

:- use_module(library(lists)).
:- use_module(library(option)).
:- use_module(library(semweb/rdf_db)).

:- use_module(plRdf_ser(ctriples_write_generics)).

:- predicate_options(ctriples_write_graph/3, 3, [
     pass_to(write_graph/2, 2)
   ]).
:- predicate_options(write_graph/2, 2, [
     bnode_base(+atom),
     format(+oneof([quads,triples])),
     number_of_triples(-nonneg)
   ]).



%! ctriples_write_graph(
%!   +Source:or([atom,stream]),
%!   ?Graph:atom,
%!   +Options:list(nvpair)
%! ) is det.
% `Source` is either a file name or a write stream.
%
% The following options are supported:
%   * =|bnode_base(+atom)|=
%     Replace blank nodes with an IRI, defined as per
%     RDF 1.1 spec (see link below).
%   * =|format(-oneof([quads,triples]))|=
%     `quads` if at least one named graph occurs, `triples` otherwise.
%   * =|number_of_triples(-nonneg)|=
%     The number of triples that was written.
%
% @see http://www.w3.org/TR/2014/REC-rdf11-concepts-20140225/#section-skolemization

% Input is a stream.
ctriples_write_graph(Write, Graph, Options):-
  is_stream(Write), !,
  with_output_to(Write, write_graph(Graph, Options)).
% Input is a file.
% Open a stream in `write` mode.
ctriples_write_graph(File, Graph, Options):-
  is_absolute_file_name(File), !,
  setup_call_cleanup(
    open(File, write, Write),
    with_output_to(Write, write_graph(Graph, Options)),
    close(Write)
  ).


%! write_graph(?Graph:atom, +Options:list(nvpair)) is det.
% This assumes that we can write to current output.

write_graph(Graph, Options):-
  ctriples_write_begin(State, BNodePrefix, Options),

  option(format(Format), Options, triples),
<commit_msg>* [CTRIPLES_WRITE_GRAPH,EXT] More advanced determination of quads/triples format.<commit_after>:- module(
  ctriples_write_graph,
  [
    ctriples_write_graph/3 % +Write:or([atom,stream])
                           % ?Graph:atom
                           % +Options:list(nvpair)
  ]
).

/** <module> C-Triples write: graph

Writes the given graph (or all currently stored triples) to a source.

@author <NAME>
@version 2014/03-2014/06, 2014/08-2014/09
*/

:- use_module(library(lists)).
:- use_module(library(option)).
:- use_module(library(semweb/rdf_db)).

:- use_module(plRdf_ser(ctriples_write_generics)).

:- predicate_options(ctriples_write_graph/3, 3, [
     pass_to(write_graph/2, 2)
   ]).
:- predicate_options(write_graph/2, 2, [
     bnode_base(+atom),
     format(+oneof([quads,triples])),
     number_of_triples(-nonneg)
   ]).



%! ctriples_write_graph(
%!   +Source:or([atom,stream]),
%!   ?Graph:atom,
%!   +Options:list(nvpair)
%! ) is det.
% `Source` is either a file name or a write stream.
%
% The following options are supported:
%   * =|bnode_base(+atom)|=
%     Replace blank nodes with an IRI, defined as per
%     RDF 1.1 spec (see link below).
%   * =|format(-oneof([quads,triples]))|=
%     `quads` if at least one named graph occurs, `triples` otherwise.
%   * =|number_of_triples(-nonneg)|=
%     The number of triples that was written.
%
% @see http://www.w3.org/TR/2014/REC-rdf11-concepts-20140225/#section-skolemization

% Input is a stream.
ctriples_write_graph(Write, Graph, Options):-
  is_stream(Write), !,
  with_output_to(Write, write_graph(Graph, Options)).
% Input is a file.
% Open a stream in `write` mode.
ctriples_write_graph(File, Graph, Options):-
  is_absolute_file_name(File), !,
  setup_call_cleanup(
    open(File, write, Write),
    with_output_to(Write, write_graph(Graph, Options)),
    close(Write)
  ).


%! write_graph(?Graph:atom, +Options:list(nvpair)) is det.
% This assumes that we can write to current output.

write_graph(Graph, Options):-
  ctriples_write_begin(State, BNodePrefix, Options),
  
  % Decide whether triples or quadruples are written.
  (   option(format(Format), Options),
      nonvar(Format)
  ->  memberchk(Format, [quads,triples])
  ;   rdf(_, _, _, G),
      G \== user
  ->  Format = quads
  ;   Format = triples
  ),

{'fraction_non_alphanumeric': 0.14868603042876902, 'fraction_numerical': 0.022130013831258646, 'mean_word_length': 3.7524644030668126, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '806235', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1554, 'n_words': 330}