<commit_before>import Asset from './asset'

import { carve, assign, singularize, pluralize, isArray, humanize, titleize  } from '../util'
import parser from './document/parser'
import indexer from './document/indexer'
import transformer from './document/transformer'
import content_interface from './document/content_interface'
import * as query_interface from './document/query_interface'

import { DomWrapper } from './parsers/html'

import cache from './document/cache'

const EXTENSIONS = ['md', 'markdown', 'markd']
const GLOB = '**/*.{' + EXTENSIONS.join(',') + '}'

export class Document extends Asset {
  static EXTENSIONS = EXTENSIONS;

  static GLOB = GLOB;

  constructor (uri, options = {}) {
    super(uri, options)

    this.lazy('content', () => content_interface(this, this), false)

    this.parser = parser
    this.indexer = indexer
    this.transformer = transformer

    this.lazy('parsed', () => this.parse(this.raw))
    this.lazy('indexed', () => this.index(this.parsed, this))
    this.lazy('transformed', () => this.transform(this.indexed, this))
  }

  assetWasImported () {
    if (this.modelClass) {
      this.decorate()
      this.loadEntity()
    }
  }

  decorate () {

  }
  /**
   * Convert this document into an Entity and load it into the store
  */
  loadEntity () {
    let asset = this
    var entity

    this.ensureIndexes()

    try {
      entity = this.modelClass.run({ document: this, asset: this }, {project: this.project})
    } catch (error) {
      console.log(`Error building entity from document: ${ this.id }: ${ error.message }`)
    }

    return this.modelClass.entities[this.id] = Object.assign({}, entity, {
        get path () {
            return asset.paths.projectRequire
        },
        get id () {
           return asset.id
        }<commit_msg>log error stacktrace in loadEntity method<commit_after>import Asset from './asset'

import { carve, assign, singularize, pluralize, isArray, humanize, titleize  } from '../util'
import parser from './document/parser'
import indexer from './document/indexer'
import transformer from './document/transformer'
import content_interface from './document/content_interface'
import * as query_interface from './document/query_interface'

import { DomWrapper } from './parsers/html'

import cache from './document/cache'

const EXTENSIONS = ['md', 'markdown', 'markd']
const GLOB = '**/*.{' + EXTENSIONS.join(',') + '}'

export class Document extends Asset {
  static EXTENSIONS = EXTENSIONS;

  static GLOB = GLOB;

  constructor (uri, options = {}) {
    super(uri, options)

    this.lazy('content', () => content_interface(this, this), false)

    this.parser = parser
    this.indexer = indexer
    this.transformer = transformer

    this.lazy('parsed', () => this.parse(this.raw))
    this.lazy('indexed', () => this.index(this.parsed, this))
    this.lazy('transformed', () => this.transform(this.indexed, this))
  }

  assetWasImported () {
    if (this.modelClass) {
      this.decorate()
      this.loadEntity()
    }
  }

  decorate () {

  }
  /**
   * Convert this document into an Entity and load it into the store
  */
  loadEntity () {
    let asset = this
    var entity

    this.ensureIndexes()

    try {
      entity = this.modelClass.run({ document: this, asset: this }, {project: this.project})
    } catch (error) {
      console.log(`Error building entity from document: ${ this.id }: ${ error.message }`)
      console.log(error.stack)
    }

    return this.modelClass.entities[this.id] = Object.assign({}, entity, {
        get path () {
            return asset.paths.projectRequire
        },
        get id () {
           return asset.id
        }
{'fraction_non_alphanumeric': 0.14328358208955225, 'fraction_numerical': 0.0, 'mean_word_length': 3.028415300546448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5240', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1106, 'n_words': 286}