<commit_before>/* global rdf:true */
'use strict';


var LdpStore = function (rdf, options) {
  var self = this;

  if (options == null) {
    options = {};
  }

  self.parsers = {
    'application/ld+json': rdf.parseJsonLd,
    'application/n-triples': rdf.parseTurtle,
    'text/turtle': rdf.parseTurtle
  };
  self.serializers = {
    'application/ld+json': rdf.serializeJsonLd,
    'application/n-triples': rdf.serializeNTriples,
    'application/sparql-update': LdpStore.serializeSparqlUpdate,
    'text/turtle': rdf.serializeNTriples
  };
  self.defaultParser = 'text/turtle';
  self.defaultSerializer = 'text/turtle';
  self.request = rdf.defaultRequest;

  if ('request' in options) {
    self.request = options.request;
  }

  var buildAccept = function() {
    var accept = null;

    for (var mimeType in self.parsers) {
      if (accept == null) {
        accept = mimeType;
      } else {
        accept += ', ' + mimeType;
      }
    }

    return accept;
  };

  var httpSuccess = function (statusCode) {
    return (statusCode >= 200 && statusCode < 300);
  };

  self.graph = function (iri, callback, options) {
    if (options == null) {
      options = {};
    }

    self.request('GET', iri, {'Accept': buildAccept()}, null,
      function (statusCode, headers, content, error) {
        // error during request
        if (error != null) {
          return callback(null, 'request error: ' + error);
        }

        // http status code != success
        if (!httpSuccess(statusCode)) {
          // in case of GET allow statusCode of 0 for browser local load
          if (statusCode != 0) {
            return callback(null, 'status code error: ' + statusCode);
          }
        }

        // use default parser...
        var contentType = self.defaultParser;

        // ...if content-type is not given or unknown
        if ('content-type' in headers && headers['content-type'] in self.parsers) {
          contentType = headers['content-type'];
        }
        
        // and override if set in options
        if ('content-type' in options && options['content-type'] in self.parsers) {
          contentType = options['content-type'];
        }

        self.parsers[contentType](content, function (graph, error) {
          if (error != null) {
            return callback(null, 'parser error: ' + error);
          }

          // copy etag header to Graph object
          if ('useEtag' in options && options.useEtag && 'etag' in headers) {
            graph.etag = headers.etag;
          }

          callback(graph);
        }, iri);
      }
    );
  };

  self.match = function (iri, subject, predicate, object, callback, limit) {
    self.graph(iri, function (graph, error) {
      if (error != null) {
        return callback(null, error);
      }

      callback(graph.match(subject, predicate, object, limit));
    });
  };

  self.add = function (iri, graph, callback, options) {
    var
      method = 'PUT',<commit_msg>renamed forced content type option in LdpStore<commit_after>/* global rdf:true */
'use strict';


var LdpStore = function (rdf, options) {
  var self = this;

  if (options == null) {
    options = {};
  }

  self.parsers = {
    'application/ld+json': rdf.parseJsonLd,
    'application/n-triples': rdf.parseTurtle,
    'text/turtle': rdf.parseTurtle
  };
  self.serializers = {
    'application/ld+json': rdf.serializeJsonLd,
    'application/n-triples': rdf.serializeNTriples,
    'application/sparql-update': LdpStore.serializeSparqlUpdate,
    'text/turtle': rdf.serializeNTriples
  };
  self.defaultParser = 'text/turtle';
  self.defaultSerializer = 'text/turtle';
  self.request = rdf.defaultRequest;

  if ('request' in options) {
    self.request = options.request;
  }

  var buildAccept = function() {
    var accept = null;

    for (var mimeType in self.parsers) {
      if (accept == null) {
        accept = mimeType;
      } else {
        accept += ', ' + mimeType;
      }
    }

    return accept;
  };

  var httpSuccess = function (statusCode) {
    return (statusCode >= 200 && statusCode < 300);
  };

  self.graph = function (iri, callback, options) {
    if (options == null) {
      options = {};
    }

    self.request('GET', iri, {'Accept': buildAccept()}, null,
      function (statusCode, headers, content, error) {
        // error during request
        if (error != null) {
          return callback(null, 'request error: ' + error);
        }

        // http status code != success
        if (!httpSuccess(statusCode)) {
          // in case of GET allow statusCode of 0 for browser local load
          if (statusCode != 0) {
            return callback(null, 'status code error: ' + statusCode);
          }
        }

        // use default parser...
        var contentType = self.defaultParser;

        // ...if content-type is not given or unknown
        if ('content-type' in headers && headers['content-type'] in self.parsers) {
          contentType = headers['content-type'];
        }
        
        // and override if set in options
        if ('forcedContentType' in options && options.forcedContentType in self.parsers) {
          contentType = options.forcedContentType;
        }

        self.parsers[contentType](content, function (graph, error) {
          if (error != null) {
            return callback(null, 'parser error: ' + error);
          }

          // copy etag header to Graph object
          if ('useEtag' in options && options.useEtag && 'etag' in headers) {
            graph.etag = headers.etag;
          }

          callback(graph);
        }, iri);
      }
    );
  };

  self.match = function (iri, subject, predicate, object, callback, limit) {
    self.graph(iri, function (graph, error) {
      if (error != null) {
        return callback(null, error);
      }

      callback(graph.match(subject, predicate, object, limit));
    });
  };

  self.add = function (iri, graph, callback, options) {
    var
      method = 'PUT',
{'fraction_non_alphanumeric': 0.1328542780748663, 'fraction_numerical': 0.00267379679144385, 'mean_word_length': 2.2142857142857144, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '716519', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1760, 'n_words': 465}