<commit_before># /=====================================================================\ #
# |  NNexus Autolinker                                                  | #
# | High-level external API                                             | #
# |=====================================================================| #
# | Part of the Planetary project: http://trac.mathweb.org/planetary    | #
# |  Research software, produced as part of work done by:               | #
# |  the KWARC group at Jacobs University                               | #
# | Copyright (c) 2012                                                  | #
# | Released under the MIT License (MIT)                                | #
# |---------------------------------------------------------------------| #
# | Adapted from the original NNexus code by                            | #
# |                                  <NAME> and <NAME>     | #
# |---------------------------------------------------------------------| #
# | <NAME> <<EMAIL>>                  #_#     | #
# | http://kwarc.info/people/dginev                            (o o)    | #
# \=========================================================ooo==U==ooo=/ #

package NNexus;
use strict;
use warnings;

use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(linkentry);
our ($INSTALLDIR) = grep(-d $_, map("$_/NNexus", @INC));

use NNexus::DB;
use NNexus::Job;
our %snapshot_credentials =
(
 "dbms" => "SQLite",
 "dbname" => "$INSTALLDIR/resources/database/snapshot.db",
 "dbuser" => "nnexus",
 "dbpass" => "<PASSWORD>",
 "dbhost" => "localhost",
) if $INSTALLDIR;

# TODO: Use a snapshot by default
sub linkentry {
  my ($body,%options) = @_;
  my $db = $options{db};
  $options{embed} //= 1;
  $options{format} //= 'html';
  return $body unless ($db || %snapshot_credentials);
  $db = NNexus::DB->new(%snapshot_credentials) unless $db;
  my $job = NNexus::Job->new(function=>'linkentry',body=>$body,db=>$db,%options);
  $job->execute;
  return $job->result;
}

1;
__END__
<commit_msg> leftover commit - indexentry routine for NNexus scripting<commit_after># /=====================================================================\ #
# |  NNexus Autolinker                                                  | #
# | High-level external API                                             | #
# |=====================================================================| #
# | Part of the Planetary project: http://trac.mathweb.org/planetary    | #
# |  Research software, produced as part of work done by:               | #
# |  the KWARC group at Jacobs University                               | #
# | Copyright (c) 2012                                                  | #
# | Released under the MIT License (MIT)                                | #
# |---------------------------------------------------------------------| #
# | Adapted from the original NNexus code by                            | #
# |                                  <NAME> and <NAME>     | #
# |---------------------------------------------------------------------| #
# | <NAME> <<EMAIL>>                  #_#     | #
# | http://kwarc.info/people/dginev                            (o o)    | #
# \=========================================================ooo==U==ooo=/ #

package NNexus;
use strict;
use warnings;

use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(linkentry indexentry);
our ($INSTALLDIR) = grep(-d $_, map("$_/NNexus", @INC));

use NNexus::DB;
use NNexus::Job;
our %snapshot_credentials =
(
 "dbms" => "SQLite",
 "dbname" => "$INSTALLDIR/resources/database/snapshot.db",
 "dbuser" => "nnexus",
 "dbpass" => "<PASSWORD>",
 "dbhost" => "localhost",
) if $INSTALLDIR;

sub linkentry {
  my ($body,%options) = @_;
  my $db = delete $options{db};
  $options{embed} //= 1;
  $options{format} //= 'html';
  return $body unless ($db || %snapshot_credentials);
  $db = NNexus::DB->new(%snapshot_credentials) unless $db;
  my $job = NNexus::Job->new(function=>'linkentry',body=>$body,db=>$db,%options);
  $job->execute;
  return $job->result;
}

sub indexentry {
  my (%options) = @_;
  my $db = delete $options{db};
  return [] unless ($db || %snapshot_credentials);
  $db = NNexus::DB->new(%snapshot_credentials) unless $db;
  my $job = NNexus::Job->new(function=>'index',db=>$db,%options);
  $job->execute;
  return $job->result;
}

1;
__END__

{'fraction_non_alphanumeric': 0.29364533149805, 'fraction_numerical': 0.0027529249827942187, 'mean_word_length': 1.8515369522563767, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1012033', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1198, 'n_words': 271}