<commit_before>'use strict';

import chemspider from './chemspider';
import chemexper from './chemexper';

import ui from 'src/util/ui';

const defaultOptions = {
    chemexper: true,
    chemspider: true
};

module.exports = {
    chemspider: chemspider,
    chemexper: chemexper,
    choose(term, options) {
        options = Object.assign({}, defaultOptions, options);
        const sources = [];
        if(options.chemspider) sources.push({promise: chemspider.search(term)});
        if(options.chemexper) sources.push({promise: chemexper.search(term)});
        return ui.choose(sources, {
            asynchronous: true,
            noConfirmation: true,
            returnRow: true,
            columns: [
                {
                    id: 'description',
                    name: 'description',
                    jpath: ['$content', 'general', 'description']
                },
                {
                    id: 'molfile',
                    name: 'molfile',
                    jpath: ['$content', 'general', 'molfile'],
                    rendererOptions: {
                        forceType: 'mol2d'
                    }

                },
                {
                    id: 'names',
                    name: 'names',
                    jpath: ['$content', 'general'],
                    rendererOptions: {
                        forceType: 'object',<commit_msg>add roc search<commit_after>'use strict';

import chemspider from './chemspider';
import chemexper from './chemexper';

import ui from 'src/util/ui';

const defaultOptions = {
    chemexper: true,
    chemspider: true
};

module.exports = {
    chemspider: chemspider,
    chemexper: chemexper,
    choose(term, options) {
        options = Object.assign({}, defaultOptions, options);
        const sources = [];
        if(options.chemspider) sources.push({promise: chemspider.search(term)});
        if(options.chemexper) sources.push({promise: chemexper.search(term)});
        if(options.roc) {
            const roc = options.roc;
            const rocPromise =  roc.view('entryByKindAndId', {
                startkey: ['sample', [term]],
                endkey: ['sample', [term, {}]]
            }).then(data => {
                data.forEach(d => d.id = d._id);
                data.forEach(d => d.source = 'sample');
                return data;
            });
            sources.push({promise: rocPromise});
        }
        return ui.choose(sources, {
            asynchronous: true,
            noConfirmation: true,
            returnRow: true,
            columns: [
                {
                    id: 'description',
                    name: 'description',
                    jpath: ['$content', 'general', 'description']
                },
                {
                    id: 'molfile',
                    name: 'molfile',
                    jpath: ['$content', 'general', 'molfile'],
                    rendererOptions: {
                        forceType: 'mol2d'
                    }

                },
                {
                    id: 'names',
                    name: 'names',
                    jpath: ['$content', 'general'],
                    rendererOptions: {
                        forceType: 'object',
{'fraction_non_alphanumeric': 0.12465627864344637, 'fraction_numerical': 0.0006110601894286587, 'mean_word_length': 1.3570914326853851, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '3189479', 'n_tokens_mistral': 877, 'n_tokens_neox': 834, 'n_words': 179}