<commit_before>var Variable = require("./variable");
var Transform = require("stream").Transform;
var CallbackStream = require("./callbackstream");

function Navigator(options) {
  if (!(this instanceof Navigator)) {
    return new Navigator(options);
  }

  this.db = options.db;
  this._conditions = [];
  this._lastElement = options.start;
  this._initialContext = {};


  var count = 0;
  this._nextVarId = function() {
    return "x" + count++;
  };
}

Navigator.prototype.archOut = function (predicate) {
  var variable = this.db.v(this._nextVarId());

  this._conditions.push({
    subject: this._lastElement,
    predicate: predicate,
    object: variable
  });

  this._lastElement = variable;

  return this;
};

Navigator.prototype.archIn = function (predicate) {
  var variable = this.db.v(this._nextVarId());

  this._conditions.push({
    subject: variable,
    predicate: predicate,
    object: this._lastElement
  });

  this._lastElement = variable;

  return this;
};

Navigator.prototype.bind  = function (value) {
  this._initialContext[this._lastElement.name] = value;
  return this;
};

Navigator.prototype.as = function (name) {
  this._lastElement.name = name;
  return this;
};

Navigator.prototype.stream = function () {
  var stream = new NavigatorStream({<commit_msg>DRYed up the Navigator.arch* methods.<commit_after>var Variable = require("./variable");
var Transform = require("stream").Transform;
var CallbackStream = require("./callbackstream");

function Navigator(options) {
  if (!(this instanceof Navigator)) {
    return new Navigator(options);
  }

  this.db = options.db;
  this._conditions = [];
  this._lastElement = options.start;
  this._initialContext = {};


  var count = 0;
  this._nextVar = function() {
    return this.db.v("x" + count++);
  };
}

function arch(varKey, lastKey) {
  return function(predicate) {
    var triple = {
      predicate: predicate
    };

    triple[varKey] = this._nextVar();
    triple[lastKey] = this._lastElement;

    this._conditions.push(triple);

    this._lastElement = triple[varKey];

    return this;
  };
}

Navigator.prototype.archOut = arch("object", "subject");
Navigator.prototype.archIn = arch("subject", "object");

Navigator.prototype.bind  = function (value) {
  this._initialContext[this._lastElement.name] = value;
  return this;
};

Navigator.prototype.as = function (name) {
  this._lastElement.name = name;
  return this;
};

Navigator.prototype.stream = function () {
  var stream = new NavigatorStream({
{'fraction_non_alphanumeric': 0.1423444976076555, 'fraction_numerical': 0.0007974481658692185, 'mean_word_length': 3.9196078431372547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7272509', 'n_tokens_mistral': 791, 'n_tokens_neox': 767, 'n_words': 165}