<commit_before>var graph = require('./graph');
var normalizeUri = require('./normalize-uri');
var async = require('async');
var fs = require('fs');
var consolidate = require('./consolidate');

// http://localhost:3001/peopleFromOrgsFromPerson?id=dbpedia_sg/V1Y4VAZZtj8x
// http://localhost:3001/peopleFromOrgsFromPerson?id=nevenfuncties/E1ShlRdWS2ze

// https://api.transparantnederland.nl/peopleFromOrgsFromPerson?id=http://nl.dbpedia.org/resource/Rita_Verdonk

exports.peopleFromOrgsFromPerson = function (query, callback) {
  var organizations = query.type || ['tnl:Organization', 'tnl:Public', 'tnl:PoliticalParty', 'tnl:Commercial', 'tnl:NonProfit'];
  var relations = ['tnl:related', 'tnl:member', 'tnl:boardmember', 'tnl:advisor', 'tnl:commissioner', 'tnl:employee', 'tnl:lobbyist'];

  // console.log(JSON.stringify(query));

  if (query.id) {
    graph.peopleFromOrgsFromPerson(normalizeUri(query.id).normalized, relations, organizations, query.concurrent, function (err, results) {
      if (err) {
        callback(err);
      } else {
        graph.expand(results.ids, function (err, concepts) {
          callback(err, consolidate(concepts, results));
        });
      }
    });
  } else {
    callback('Please supply an `id`');
  }
};


exports.shortestPath = function (query, callback) {
  if (query.id) {
    graph.equivalentIDs(normalizeUri(query.id).normalized, ['_'], function (err, ids) {
      if (err) {
        callback(err);
      } else {
        callback(err, ids);
      }
    });
  } else {
    callback('Please supply an `id`');
  }
};


exports.equivalentIDs = function (query, callback) {
  if (query.id) {
    graph.equivalentIDs(normalizeUri(query.id).normalized, ['_'], function (err, ids) {
      if (err) {
        callback(err);
      } else {
        callback(err, ids);
      }
    });
  } else {
    callback('Please supply an `id`');
  }
};

// http://localhost:3001/equivalentNodes?id=shops/bert-bankras
exports.equivalentNodes = function (query, callback) {
  if (query.id) {
    ids = [normalizeUri(query.id).normalized];
    graph.expand(ids, function (err, concepts) {
      callback(err, concepts);
    });
  } else {
    callback('Please supply an `id`');
  }
};


exports.peopleFromOrg = function (query, callback) {
  var results;
  var relations = ['tnl:related', 'tnl:member', 'tnl:boardmember', 'tnl:advisor', 'tnl:commissioner', 'tnl:employee', 'tnl:lobbyist'];

  return async.waterfall([
    getpeopleFromOrg,
    expandGraph
  ], done);

  function getpeopleFromOrg(cb) {
    graph.peopleFromOrg(normalizeUri(query.id).normalized, relations, cb);
  }

  function expandGraph(r, cb) {
    results = r;
    graph.expand(r.ids, cb);
  }

  function done(err, concepts) {
    callback(err, consolidate(concepts, results));
  }
};


// http://localhost:3001/orgsFromPerson?id=urn:hgid:dbpedia_sg/4y9XLJGcPHg
exports.orgsFromPerson = function (query, callback) {
  var results;
  var organizations = query.type || ['tnl:Organization', 'tnl:Public', 'tnl:PoliticalParty', 'tnl:Commercial', 'tnl:NonProfit'];
  var relations = ['tnl:related', 'tnl:member', 'tnl:boardmember', 'tnl:advisor', 'tnl:commissioner', 'tnl:employee', 'tnl:lobbyist'];

  return async.waterfall([
    getOrgsFromPerson,
    expandGraph
  ], done);

  function getOrgsFromPerson(cb) {
    graph.orgsFromPerson(normalizeUri(query.id).normalized, relations, organizations, cb);
  }

  function expandGraph(r, cb) {
    results = r;
    graph.expand(results.ids, cb);
  }

  function done(err, concepts) {
    callback(err, consolidate(concepts, results));
  }
};
<commit_msg>include 'spokesperson' relation in queries<commit_after>var graph = require('./graph');
var normalizeUri = require('./normalize-uri');
var async = require('async');
var fs = require('fs');
var consolidate = require('./consolidate');

// http://localhost:3001/peopleFromOrgsFromPerson?id=dbpedia_sg/V1Y4VAZZtj8x
// http://localhost:3001/peopleFromOrgsFromPerson?id=nevenfuncties/E1ShlRdWS2ze

// https://api.transparantnederland.nl/peopleFromOrgsFromPerson?id=http://nl.dbpedia.org/resource/Rita_Verdonk

exports.peopleFromOrgsFromPerson = function (query, callback) {
  var organizations = query.type || ['tnl:Organization', 'tnl:Public', 'tnl:PoliticalParty', 'tnl:Commercial', 'tnl:NonProfit'];
  var relations = ['tnl:related', 'tnl:member', 'tnl:boardmember', 'tnl:advisor', 'tnl:commissioner', 'tnl:employee', 'tnl:lobbyist', 'tnl:spokesperson'];

  // console.log(JSON.stringify(query));

  if (query.id) {
    graph.peopleFromOrgsFromPerson(normalizeUri(query.id).normalized, relations, organizations, query.concurrent, function (err, results) {
      if (err) {
        callback(err);
      } else {
        graph.expand(results.ids, function (err, concepts) {
          callback(err, consolidate(concepts, results));
        });
      }
    });
  } else {
    callback('Please supply an `id`');
  }
};


exports.shortestPath = function (query, callback) {
  if (query.id) {
    graph.equivalentIDs(normalizeUri(query.id).normalized, ['_'], function (err, ids) {
      if (err) {
        callback(err);
      } else {
        callback(err, ids);
      }
    });
  } else {
    callback('Please supply an `id`');
  }
};


exports.equivalentIDs = function (query, callback) {
  if (query.id) {
    graph.equivalentIDs(normalizeUri(query.id).normalized, ['_'], function (err, ids) {
      if (err) {
        callback(err);
      } else {
        callback(err, ids);
      }
    });
  } else {
    callback('Please supply an `id`');
  }
};

// http://localhost:3001/equivalentNodes?id=shops/bert-bankras
exports.equivalentNodes = function (query, callback) {
  if (query.id) {
    ids = [normalizeUri(query.id).normalized];
    graph.expand(ids, function (err, concepts) {
      callback(err, concepts);
    });
  } else {
    callback('Please supply an `id`');
  }
};


exports.peopleFromOrg = function (query, callback) {
  var results;
  var relations = ['tnl:related', 'tnl:member', 'tnl:boardmember', 'tnl:advisor', 'tnl:commissioner', 'tnl:employee', 'tnl:lobbyist', 'tnl:spokesperson'];

  return async.waterfall([
    getpeopleFromOrg,
    expandGraph
  ], done);

  function getpeopleFromOrg(cb) {
    graph.peopleFromOrg(normalizeUri(query.id).normalized, relations, cb);
  }

  function expandGraph(r, cb) {
    results = r;
    graph.expand(r.ids, cb);
  }

  function done(err, concepts) {
    callback(err, consolidate(concepts, results));
  }
};


// http://localhost:3001/orgsFromPerson?id=urn:hgid:dbpedia_sg/4y9XLJGcPHg
exports.orgsFromPerson = function (query, callback) {
  var results;
  var organizations = query.type || ['tnl:Organization', 'tnl:Public', 'tnl:PoliticalParty', 'tnl:Commercial', 'tnl:NonProfit'];
  var relations = ['tnl:related', 'tnl:member', 'tnl:boardmember', 'tnl:advisor', 'tnl:commissioner', 'tnl:employee', 'tnl:lobbyist', 'tnl:spokesperson'];

  return async.waterfall([
    getOrgsFromPerson,
    expandGraph
  ], done);

  function getOrgsFromPerson(cb) {
    graph.orgsFromPerson(normalizeUri(query.id).normalized, relations, organizations, cb);
  }

  function expandGraph(r, cb) {
    results = r;
    graph.expand(results.ids, cb);
  }

  function done(err, concepts) {
    callback(err, consolidate(concepts, results));
  }
};

{'fraction_non_alphanumeric': 0.16284498146368254, 'fraction_numerical': 0.006316078539063573, 'mean_word_length': 4.072423398328691, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6365071', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2454, 'n_words': 433}