<commit_before>:- module(
  rdf_instance,
  [
    rdf_term_instance/3, % +Specific:compound
                         % +Generic:compound
                         % -Map:list(pair(bnode,rdf_term))
    rdf_term_instance/4, % +Specific:compound
                         % +Generic:compound
                         % +Map:list(pair(bnode,rdf_term))
                         % -NewMap:list(pair(bnode,rdf_term))
    rdf_term_variant/2, % +Term1:rdf_term
                        % +Term1:rdf_term
    rdf_triple_instance/3, % +Specific:compound
                           % +Generic:compound
                           % -NewMap:list(pair(bnode,rdf_term))
    rdf_triple_instance/4, % +Specific:compound
                           % +Generic:compound
                           % +Map:list(pair(bnode,rdf_term))
                           % -NewMap:list(pair(bnode,rdf_term))
    rdf_triple_variant/2 % +Triple1:compound
                         % +Triple2:compound
  ]
).

/** <module> RDF: Term and triple instances

Support for blank node mappings in RDF.

@author <NAME>
@version 2014/11
*/

:- use_module(library(ordsets)).
:- use_module(library(semweb/rdf_db), except([rdf_node/1])).

:- rdf_meta(rdf_term_variant(o,o)).
:- rdf_meta(rdf_term_instance(o,o,-)).
:- rdf_meta(rdf_term_instance(o,o,+,-)).
:- rdf_meta(rdf_triple_instance(t,t,-)).
:- rdf_meta(rdf_triple_instance(t,t,+,-)).
:- rdf_meta(rdf_triple_variant(t,t)).



% rdf_term_instance(
%!   +Specific:compound,
%!   +Generic:compound,
%!   -NewMap:list(pair(bnode,rdf_term))
%! ) is det.
%! rdf_term_instance(
%!   +Specific:compound,
%!   +Generic:compound,
%!   +Map:list(pair(bnode,rdf_term)),
%!   -NewMap:list(pair(bnode,rdf_term))
%! ) is det.

rdf_term_instance(Specific, Generic, NewMap):-
  rdf_term_instance(Specific, Generic, [], NewMap).

% Generic is not a blank node so Specific cannot be more specific.
rdf_term_instance(Name, Name, Map, Map):-
  \+ rdf_is_bnode(Name), !.
% Generic is a known blank node, use the existing mapping.
rdf_term_instance(Term, BNode, Map, Map):-
  ord_memberchk(BNode-Term, Map), !.
% Generic is a new blank node, add it to the mapping.
rdf_term_instance(Term, BNode, Map1, Map2):-
  ord_add_element(Map1, BNode-Term, Map2).



%! rdf_term_variant(+Term1:rdf_term, +Term1:rdf_term) is semidet.
% Succeeds if the given RDF terms are variants.
%
% Similar to Prolog term variants, i.e. =@=/2.

rdf_term_variant(BNode1, BNode2):-
  rdf_is_bnode(BNode1),
  rdf_is_bnode(BNode2), !.
rdf_term_variant(Term, Term).



%! rdf_triple_instance(
%!   +Specific:compound,
%!   +Generic:compound,
%!   -NewMap:list(pair(bnode,rdf_term))
%! ) is det.
%! rdf_triple_instance(
%!   +Specific:compound,
%!   +Generic:compound,
%!   +Map:list(pair(bnode,rdf_term)),
%!   -NewMap:list(pair(bnode,rdf_term))
%! ) is det.
% Returns a blank node mapping that maps blank nodes from Generic onto
%  terms in Specific so that Generic == Specific.

rdf_triple_instance(Specific, Generic, NewMap):-<commit_msg>1. FIXED: rdf_term_instance/[3,4] would map from non-blank nodes. 2. FIXED: rdf_term_instance/[3,4] would not copy non-blank nodes.<commit_after>:- module(
  rdf_instance,
  [
    rdf_term_instance/3, % +Specific:compound
                         % +Generic:compound
                         % -Map:list(pair(bnode,rdf_term))
    rdf_term_instance/4, % +Specific:compound
                         % +Generic:compound
                         % +Map:list(pair(bnode,rdf_term))
                         % -NewMap:list(pair(bnode,rdf_term))
    rdf_term_variant/2, % +Term1:rdf_term
                        % +Term1:rdf_term
    rdf_triple_instance/3, % +Specific:compound
                           % +Generic:compound
                           % -NewMap:list(pair(bnode,rdf_term))
    rdf_triple_instance/4, % +Specific:compound
                           % +Generic:compound
                           % +Map:list(pair(bnode,rdf_term))
                           % -NewMap:list(pair(bnode,rdf_term))
    rdf_triple_variant/2 % +Triple1:compound
                         % +Triple2:compound
  ]
).

/** <module> RDF: Term and triple instances

Support for blank node mappings in RDF.

@author <NAME>
@version 2014/11
*/

:- use_module(library(ordsets)).
:- use_module(library(semweb/rdf_db), except([rdf_node/1])).

:- rdf_meta(rdf_term_variant(o,o)).
:- rdf_meta(rdf_term_instance(o,o,-)).
:- rdf_meta(rdf_term_instance(o,o,+,-)).
:- rdf_meta(rdf_triple_instance(t,t,-)).
:- rdf_meta(rdf_triple_instance(t,t,+,-)).
:- rdf_meta(rdf_triple_variant(t,t)).



% rdf_term_instance(
%!   +Specific:compound,
%!   +Generic:compound,
%!   -NewMap:list(pair(bnode,rdf_term))
%! ) is det.
%! rdf_term_instance(
%!   +Specific:compound,
%!   +Generic:compound,
%!   +Map:list(pair(bnode,rdf_term)),
%!   -NewMap:list(pair(bnode,rdf_term))
%! ) is det.

rdf_term_instance(Specific, Generic, NewMap):-
  rdf_term_instance(Specific, Generic, [], NewMap).

% Generic and Specific are the same and are possibly a blank node.
rdf_term_instance(Name, Name, Map, Map):- !.
% Generic is a known blank node, use the existing mapping.
rdf_term_instance(Term, BNode, Map, Map):-
  ord_memberchk(BNode-Term, Map), !.
% Generic is a new blank node, add it to the mapping.
rdf_term_instance(Term, BNode, Map1, Map2):-
  rdf_is_bnode(BNode),
  ord_add_element(Map1, BNode-Term, Map2).



%! rdf_term_variant(+Term1:rdf_term, +Term1:rdf_term) is semidet.
% Succeeds if the given RDF terms are variants.
%
% Similar to Prolog term variants, i.e. =@=/2.

rdf_term_variant(BNode1, BNode2):-
  rdf_is_bnode(BNode1),
  rdf_is_bnode(BNode2), !.
rdf_term_variant(Term, Term).



%! rdf_triple_instance(
%!   +Specific:compound,
%!   +Generic:compound,
%!   -NewMap:list(pair(bnode,rdf_term))
%! ) is det.
%! rdf_triple_instance(
%!   +Specific:compound,
%!   +Generic:compound,
%!   +Map:list(pair(bnode,rdf_term)),
%!   -NewMap:list(pair(bnode,rdf_term))
%! ) is det.
% Returns a blank node mapping that maps blank nodes from Generic onto
%  terms in Specific so that Generic == Specific.

rdf_triple_instance(Specific, Generic, NewMap):-
{'fraction_non_alphanumeric': 0.14571709878569084, 'fraction_numerical': 0.01017394158188382, 'mean_word_length': 3.1519073569482288, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2090297', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2296, 'n_words': 381}