scopus

Overview

Functions

metaknowledge.scopus.scopusHandlers.isScopusFile(infile, checkedLines=2, maxHeaderDiff=3)

Determines if infile is the path to a Scopus csv file. A file is considerd to be a Scopus file if it has the correct encoding (utf-8 with BOM (Byte Order Mark)) and within the first checkedLines a line contains the complete header, the list of all header entries in order is found in `scopus.scopusHeader <#metaknowledge.scopus>`__.

Note this is for csv files not plain text files from scopus, plain text files are not complete.

Parameters

infile : str

The path to the targets file

checkedLines : optional [int]

default 2, the number of lines to check for the header

maxHeaderDiff : optional [int]

default 3, maximum number of different entries in the potetial file from the current known header metaknowledge.scopus.scopusHeader, if exceeded an False will be returned

Returns

bool

True if the file is a Scopus csv file
metaknowledge.scopus.scopusHandlers.scopusParser(scopusFile)

Parses a scopus file, scopusFile, to extract the individual lines as ScopusRecords.

A Scopus file is a csv (Comma-separated values) with a complete header, see `scopus.scopusHeader <#metaknowledge.scopus>`__ for the entries, and each line after it containing a record’s entry. The string valued entries are quoted with double quotes which means double quotes inside them can cause issues, see scopusRecordParser() for more information.

Parameters

scopusFile : str

A path to a valid scopus file, use isScopusFile() to verify

Returns

set[ScopusRecord]

Records for each of the entries

Special Functions

Tag Functions

metaknowledge.scopus.tagProcessing.tagFunctions.citeValue(val)
metaknowledge.scopus.tagProcessing.tagFunctions.commaSpaceSeperated(val)
metaknowledge.scopus.tagProcessing.tagFunctions.grantValue(val)
metaknowledge.scopus.tagProcessing.tagFunctions.integralValue(val)
metaknowledge.scopus.tagProcessing.tagFunctions.semicolonSeperated(val)
metaknowledge.scopus.tagProcessing.tagFunctions.semicolonSpaceSeperated(val)
metaknowledge.scopus.tagProcessing.tagFunctions.stringValue(val)

Backend

class metaknowledge.scopus.recordScopus.ScopusRecord(inRecord, sFile='', sLine=0, header=None)

Bases: metaknowledge.mkRecord.ExtendedRecord

Class for full Scopus entries.

This class is an ExtendedRecord capable of generating its own id number. You should not create them directly, but instead use scopusParser() on a scopus CSV file.

authGenders(countsOnly=False, fractionsMode=False, _countsTuple=False)

Creates a dict mapping 'Male', 'Female' and 'Unknown' to lists of the names of all the authors.

Parameters

countsOnly : optional bool

Default False, if True the counts (lengths of the lists) will be given instead of the lists of names

fractionsMode : optional bool

Default False, if True the fraction counts (lengths of the lists divided by the total number of authors) will be given instead of the lists of names. This supersedes countsOnly

Returns

dict[str:str or int]

The mapping of genders to author’s names or counts
authors
bibString(maxLength=1000, WOSMode=False, restrictedOutput=False, niceID=True)

Makes a string giving the Record as a bibTex entry. If the Record is of a journal article (PT J) the bibtext type is set to 'article', otherwise it is set to 'misc'. The ID of the entry is the WOS number and all the Record’s fields are given as entries with their long names.

Note This is not meant to be used directly with LaTeX none of the special characters have been escaped and there are a large number of unnecessary fields provided. niceID and maxLength have been provided to make conversions easier.

Note Record entries that are lists have their values seperated with the string ' and '

Parameters

maxLength : optional [int]

default 1000, The max length for a continuous string. Most bibTex implementation only allow string to be up to 1000 characters (source), this splits them up into substrings then uses the native string concatenation (the '#' character) to allow for longer strings

WOSMode : optional [bool]

default False, if True the data produced will be unprocessed and use double curly braces. This is the style WOS produces bib files in and mostly macthes that.

restrictedOutput : optional [bool]

default False, if True the tags output will be limited to tose found in metaknowledge.commonRecordFields

niceID : optional [bool]

default True, if True the ID used will be derived from the authors, publishing date and title, if False it will be the UT tag

Returns

str

The bibTex string of the Record
copy()

Correctly copies the Record

Returns

Record

A completely decoupled copy of the original
createCitation(multiCite=False)

Overwriting the general citation creator to deal with scopus weirdness.

Creates a citation string, using the same format as other WOS citations, for the Record by reading the relevant special tags ('year', 'J9', 'volume', 'beginningPage', 'DOI') and using it to create a Citation object.

Parameters

multiCite : optional [bool]

Default False, if True a tuple of Citations is returned with each having a different one of the records authors as the author

Returns

Citation

A Citation object containing a citation for the Record.
encoding()

An abstractmethod, gives the encoding string of the record.

Returns

str

The encoding
get(tag, default=None, raw=False)

Allows access to the raw values or is an Exception safe wrapper to __getitem__.

Parameters

tag : str

The requested tag

default : optional [Object]

Default None, the object returned when tag is not found

raw : optional [bool]

Default False, if True the unprocessed value of tag is returned

Returns

Object

The processed value of tag or default
static getAltName(tag)

An abstractmethod, gives the alternate name of tag or None

Parameters

tag : str

The requested tag

Returns

str

The alternate name of tag or None
getCitations(field=None, values=None, pandasFriendly=True)

Creates a pandas ready dict with each row a different citation and columns containing the original string, year, journal and author’s name.

There are also options to filter the output citations with field and values

Parameters

field : optional str

Default None, if given all citations missing the named field will be dropped.

values : optional str or list[str]

Default None, if field is also given only those citations with one of the strings given in values will be included.

e.g. to get only citations from 1990 or 1991: field = year, values = [1991, 1990]

pandasFriendly : optional bool

Default True, if False a list of the citations will be returned instead of the more complicated pandas dict

Returns

dict

A pandas ready dict with all the citations
id
items(raw=False)

Like items for dicts but with a raw option

Parameters

raw : optional [bool]

Default False, if True the KeysView contains the raw values as the values

Returns

KeysView

The key-value pairs of the record
keys() → a set-like object providing a view on D's keys
sourceFile
sourceLine
specialFuncs(key)

An abstractmethod, process the special tag, key using the whole Record

Parameters

key : str

One of the special tags: 'authorsFull', 'keywords', 'grants', 'j9', 'authorsShort', 'volume', 'selfCitation', 'citations', 'address', 'abstract', 'title', 'month', 'year', 'journal', 'beginningPage' and 'DOI'

Returns

The processed value of key
subDict(tags, raw=False)

Creates a dict of values of tags from the Record. The tags are the keys and the values are the values. If the tag is missing the value will be None.

Parameters

tags : list[str]

The list of tags requested

raw : optional [bool]

default False if True the retuned values of the dict will be unprocessed

Returns

dict

A dictionary with the keys tags and the values from the record
static tagProcessingFunc(tag)

An abstractmethod, gives the function for processing tag

Parameters

tag : optional [str]

The tag in need of processing

Returns

function

The function to process the raw tag
title
values(raw=False)

Like values for dicts but with a raw option

Parameters

raw : optional [bool]

Default False, if True the ValuesView contains the raw values

Returns

ValuesView

The values of the record
writeRecord(f)

An abstractmethod, writes the record in its original form to infile

Parameters

infile : writable file

The file to be written to
metaknowledge.scopus.recordScopus.scopusRecordParser(record, header=None)

The parser ScopusRecords use. This takes a line from scopusParser() and parses it as a part of the creation of a ScopusRecord.

Note this is for csv files downloaded from scopus not the text records as those are less complete. Also, Scopus uses double quotes (") to quote strings, such as abstracts, in the csv so double quotes in the string must be escaped. For reasons not fully understandable by mortals they choose to use two double quotes in a row ("") to represent an escaped double quote. This parser does not unescape these quotes, but it does correctly handle their interacts with the outer double quotes.

Parameters

record : str

string ending with a newline containing the record’s entry

Returns

dict

A dictionary of the key-vaue pairs in the entry