<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import uuid
import logging
from datetime import datetime

from .. import base
logger = logging.getLogger(__name__)


class Indexer(object):

    # Public

    def __init__(self, warehouse):
        self.__warehouse = warehouse

    def index(self, target, **kwargs):

        # Get method
        try:
            method = getattr(self, 'index_%s' % target)
        except AttributeError:
            message = 'Indexer %s doesn\'t support %s target.'
            message = message % (self, target)
            raise ValueError(message)

        # Index data
        id = method(item)

        return id

    def index_source(self, name, type):

        # Get index
        index = self.warehouse['index_source'].find_one(name=name, type=type)

        # Create index
        if index is None:
            index = dict(name=name, type=type)
            index['meta_id'] = uuid.uuid4().hex
            index['meta_created'] = datetime.now()  # TODO: fix timezone
            index['meta_updated'] = datetime.now()  # TODO: fix timezone
            index['name'] = name
            index['type'] = type
            self.warehouse['index_source'].insert(index, ensure=True)
            logger.debug('Indexed - source: %s' % item['meta_id'])

        # Return id
        return index['meta_id']

    def index_trial(self, nct_id=None, euctr_id=None,
            isrctn_id=None, scientific_title=None):

        # Get item
        item = None
        for key in ['nct_id', 'euctr_id', 'isrctn_id', 'scientific_title']:
            value = locals()[key]
            if not value:
                continue
            item = self.warehouse['index_trials'].find_one(**{key: value})
            if item is not None:
                break

        # Create item
        if item is None:
            item = dict(name=name, type=type)
            item['meta_id'] = uuid.uuid4().hex
            item['meta_created'] = datetime.now()  # TODO: fix timezone
            item['meta_updated'] = datetime.now()  # TODO: fix timezone
            item['nct_id'] = nct_id
            item['euctr_id'] = euctr_id
            item['isrctn_id'] = isrctn_id
            item['scientific_title'] = scientific_title
            self.warehouse['index_trials'].insert(item, ensure=True)
            logger.debug('Indexed - trial: %s' % item['meta_id'])

        # Return id
        return item['meta_id']<commit_msg>added stub methods to indexer<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import uuid
import logging
from datetime import datetime

from .. import base
logger = logging.getLogger(__name__)


class Indexer(object):

    # Public

    def __init__(self, warehouse):
        self.__warehouse = warehouse

    def index(self, target, **kwargs):

        # Get method
        try:
            method = getattr(self, 'index_%s' % target)
        except AttributeError:
            message = 'Indexer %s doesn\'t support %s target.'
            message = message % (self, target)
            raise ValueError(message)

        # Index data
        id = method(item)

        return id

    def index_source(self, name, type):

        # Get index
        index = self.warehouse['index_source'].find_one(name=name, type=type)

        # Create index
        if index is None:
            index = dict(name=name, type=type)
            index['meta_id'] = uuid.uuid4().hex
            index['meta_created'] = datetime.now()  # TODO: fix timezone
            index['meta_updated'] = datetime.now()  # TODO: fix timezone
            index['name'] = name
            index['type'] = type
            self.warehouse['index_source'].insert(index, ensure=True)
            logger.debug('Indexed - source: %s' % item['meta_id'])

        # Return id
        return index['meta_id']

    def index_trial(self, nct_id=None, euctr_id=None,
            isrctn_id=None, scientific_title=None):

        # Get item
        item = None
        for key in ['nct_id', 'euctr_id', 'isrctn_id', 'scientific_title']:
            value = locals()[key]
            if not value:
                continue
            item = self.warehouse['index_trials'].find_one(**{key: value})
            if item is not None:
                break

        # Create item
        if item is None:
            item = dict(name=name, type=type)
            item['meta_id'] = uuid.uuid4().hex
            item['meta_created'] = datetime.now()  # TODO: fix timezone
            item['meta_updated'] = datetime.now()  # TODO: fix timezone
            item['nct_id'] = nct_id
            item['euctr_id'] = euctr_id
            item['isrctn_id'] = isrctn_id
            item['scientific_title'] = scientific_title
            self.warehouse['index_trials'].insert(item, ensure=True)
            logger.debug('Indexed - trial: %s' % item['meta_id'])

        # Return id
        return item['meta_id']

    def index_problem(self, name, type):
        pass

    def index_intervention(self, name, type):
        pass

    def index_location(self, name, type):
        pass

    def index_organisation(self, name, type):
        pass

    def index_person(self, name, type):
        pass
{'fraction_non_alphanumeric': 0.11135571454778939, 'fraction_numerical': 0.001100715465052284, 'mean_word_length': 2.1387449625791595, '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': '4898384', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1554, 'n_words': 402}