<commit_before>const _ = require('lodash');
const debug = require('debug')('I3C:Portal:extractPageView');
const fs = require('fs');
const path = require('path');
const Promise = require('bluebird');
const routesInfo = require('@quoin/expressjs-routes-info');
const urlTemplate = require('url-template');

const createObjResource = require('./create-obj-resource');

// FIXME: For debug only.
const RANDOM_IMAGE = urlTemplate.parse('http://lorempixel.com/{Width}/{Height}/{ImageURL}/');
const IMAGE_PATH = urlTemplate.parse('/public/iic_images/{ImageURL}');
const CONTENT_LINK_RE = /{{(.*?),(.*?),(.*?)}}/g;

function contentLinkReplacer(match, label, type, id) {
    const href = routesInfo.expand('entity', {id, type});
    return `<a href="${href}">${label}</a>`;
}

function parseLinks(overviews) {
    if (overviews) {
        return overviews.map((overview) => {
            if (overview && overview.Content && overview.Content.match(CONTENT_LINK_RE)) {
                let contentBasicProperty = _.filter(overview.basicProperties, (prop) => prop.name === 'Content');
                overview.containsHTML = contentBasicProperty.length && contentBasicProperty[0].propertyType === 'text';
                if (overview.containsHTML) {
                    overview.Content = overview.Content.replace(CONTENT_LINK_RE, contentLinkReplacer);
                }
            }
            return overview;
        });
    }
    return overviews;
}

function extractRelationship(req, resource, persistence, hsEntity, entity) {
    const relationship = hsEntity.getRelationship();

    return Promise.resolve()
        .then(() => relationship.getDocuments(persistence, entity))
        .then((references) => {
            return Promise.map(references, (reference) => {
                const referenceResource = createObjResource(reference, true);
                if (hsEntity.style === 'Preview') {
                    const referenceEntity = hsEntity.getRelationship().getTargetEntity();<commit_msg>Modified to match code conventions for the pull request<commit_after>const _ = require('lodash');
const debug = require('debug')('I3C:Portal:extractPageView');
const fs = require('fs');
const path = require('path');
const Promise = require('bluebird');
const routesInfo = require('@quoin/expressjs-routes-info');
const urlTemplate = require('url-template');

const createObjResource = require('./create-obj-resource');

// FIXME: For debug only.
const RANDOM_IMAGE = urlTemplate.parse('http://lorempixel.com/{Width}/{Height}/{ImageURL}/');
const IMAGE_PATH = urlTemplate.parse('/public/iic_images/{ImageURL}');
const CONTENT_LINK_RE = /{{(.*?),(.*?),(.*?)}}/g;

function contentLinkReplacer(match, label, type, id) {
    const href = routesInfo.expand('entity', {id, type});
    return `<a href="${href}">${label}</a>`;
}

function parseLinks(overviews) {
    if (overviews) {
        return overviews.map((overview) => {
            if (overview && overview.Content && overview.Content.match(CONTENT_LINK_RE)) {
                const contentBasicProperty = _.filter(overview.basicProperties, (prop) => prop.name === 'Content');
                overview.containsHTML = contentBasicProperty.length && contentBasicProperty[0].propertyType === 'text';
                if (overview.containsHTML) {
                    overview.Content = overview.Content.replace(CONTENT_LINK_RE, contentLinkReplacer);
                }
            }
            return overview;
        });
    }
    return overviews;
}

function extractRelationship(req, resource, persistence, hsEntity, entity) {
    const relationship = hsEntity.getRelationship();

    return Promise.resolve()
        .then(() => relationship.getDocuments(persistence, entity))
        .then((references) => {
            return Promise.map(references, (reference) => {
                const referenceResource = createObjResource(reference, true);
                if (hsEntity.style === 'Preview') {
                    const referenceEntity = hsEntity.getRelationship().getTargetEntity();
{'fraction_non_alphanumeric': 0.15014866204162536, 'fraction_numerical': 0.0009910802775024777, 'mean_word_length': 3.3928182807399345, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '1667765', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1080, 'n_words': 219}