Пример #1
0
    def load(self, directory=None):
        """Load raw data from json file.

        Parameters
        ----------
        directory : str or SCDB, optional
            Folder or database object specifying the save location.
        """

        directory = check_directory(directory, 'raw')

        data = parse_json_data(os.path.join(directory, check_ext(self.label, '.json')))

        self.term = Term(*next(data)['term'])

        for dat in data:
            self.add_data('ids', dat['id'])
            self.add_data('titles', dat['title'])
            self.add_data('journals', dat['journal'])
            self.add_data('authors', dat['authors'])
            self.add_data('words', dat['words'])
            self.add_data('keywords', dat['keywords'])
            self.add_data('years', dat['year'])
            self.add_data('dois', dat['doi'])

        self._check_results()
Пример #2
0
    def _set_up_logging(self, logging, directory):
        """Set up for URL logging.

        Parameters
        ----------
        logging : {None, 'print', 'store', 'file'}
            What kind of logging, if any, to do for requested URLs.
        directory : SCDB or str or None
            A string or object containing a file path.
        """

        if logging in [None, 'print']:
            log = None

        elif logging == 'store':
            log = []

        elif logging == 'file':
            log = open(
                os.path.join(check_directory(directory, 'logs'),
                             check_ext('requester_log', '.txt')), 'w')
            log.write('REQUESTER LOG - STARTED AT:  ' + self.start_time)

        else:
            raise ValueError('Logging type not understood.')

        return logging, log
Пример #3
0
    def load(self, directory=None):
        """Load raw data from json file.

        Parameters
        ----------
        directory : str or SCDB, optional
            Folder or database object specifying the save location.

        Examples
        --------
        Load an ``Articles`` object, assuming an :class:`~.SCDB` organization named 'lisc_db':

        >>> from lisc.utils import SCDB
        >>> articles = Articles('frontal lobe')
        >>> articles.load(SCDB('lisc_db')) # doctest:+SKIP
        """

        directory = check_directory(directory, 'raw')

        data = parse_json_data(
            os.path.join(directory, check_ext(self.label, '.json')))

        self.term = Term(*next(data)['term'])

        for datum in data:
            self.add_data('ids', datum['id'])
            self.add_data('titles', datum['title'])
            self.add_data('journals', datum['journal'])
            self.add_data('authors', datum['authors'])
            self.add_data('words', datum['words'])
            self.add_data('keywords', datum['keywords'])
            self.add_data('years', datum['year'])
            self.add_data('dois', datum['doi'])

        self._check_results()
Пример #4
0
    def save(self, directory=None):
        """Save out a json file with all attached data.

        Parameters
        ----------
        directory : str or SCDB, optional
            Folder or database object specifying the save location.

        Examples
        --------
        Save an ``Articles`` object, using a temporary directory:

        >>> from tempfile import TemporaryDirectory
        >>> articles = Articles('frontal lobe')
        >>> with TemporaryDirectory() as dirpath:
        ...     articles.save(directory=dirpath)
        """

        directory = check_directory(directory, 'raw')

        with open(os.path.join(directory, check_ext(self.label, '.json')),
                  'w') as outfile:
            json.dump({'term': self.term}, outfile)
            outfile.write('\n')
            for art in self:
                json.dump(art, outfile)
                outfile.write('\n')
Пример #5
0
    def save_summary(self, directory=None):
        """Save out a summary of the collected words data.

        Parameters
        ----------
        directory : str or SCDB object, optional
            Folder or database object specifying the save location.
        """

        directory = check_directory(directory, 'summary')

        with open(os.path.join(directory, check_ext(self.label, '.json')), 'w') as outfile:
            json.dump(self.summary, outfile)
Пример #6
0
    def save(self, directory=None):
        """Save out a json file with all attached data.

        Parameters
        ----------
        directory : str or SCDB, optional
            Folder or database object specifying the save location.
        """

        directory = check_directory(directory, 'raw')

        with open(os.path.join(directory, check_ext(self.label, '.json')), 'w') as outfile:
            json.dump({'term' : self.term}, outfile)
            outfile.write('\n')
            for art in self:
                json.dump(art, outfile)
                outfile.write('\n')
Пример #7
0
    def save_summary(self, directory=None):
        """Save out a summary of the collected words data.

        Parameters
        ----------
        directory : str or SCDB or None, optional
            Folder or database object specifying the save location.

        Examples
        --------
        Save a summary for a term, assuming an initialized ``ArticlesAll`` object with data::

        >>> articles_all.create_summary() # doctest:+SKIP
        >>> articles_all.save_summary() # doctest:+SKIP
        """

        directory = check_directory(directory, 'summary')

        with open(os.path.join(directory, check_ext(self.label, '.json')),
                  'w') as outfile:
            json.dump(self.summary, outfile)