Objects

In Python everything is an object thus everything metaknowledge produces is an object. There are three objects that have been created specifically for it, objects created this way are call classes. The three are Record a single WOS record, RecordCollection a group of Records and Citation a single WOS citation.

Lets import metaknowledge and read a file

[1]:
import metaknowledge as mk
RC = mk.RecordCollection('../savedrecs.txt') # '..' is one directory above the current one

Now we can look at how the different objects relate to this file.

Record object

Record is an object that contains a simple WOS record, for example a journal article, book, or conference proceedings. They are what RecordCollections contain. To see an individual Record at random from a RecordCollection you can use peak()

[2]:
R = RC.peak()

A single Record can give you all the information it contains about its record. If for example you want its authors.

[3]:
print(R.authorsFull)
print(R.AF)
['BREVIK, I']
['BREVIK, I']

Converting a Record to a string will give its title

[4]:
print(R)
EXPERIMENTS IN PHENOMENOLOGICAL ELECTRODYNAMICS AND THE ELECTROMAGNETIC ENERGY-MOMENTUM TENSOR

If you try to access a tag the Record does not have it will return None

[5]:
print(R.GP)
None

There are two ways of getting each tag, one is using the WOS 2 letter abbreviation and the second is to use the human readable name. There is no standard for the human readable names, so they are specific to metaknowledge. To see how the WOS names map to the long names look at tagFuncs. If you want all the tags a Record has use iter.

[6]:
print(R.__iter__())
['PT', 'AU', 'AF', 'TI', 'SO', 'LA', 'DT', 'C1', 'CR', 'NR', 'TC', 'Z9', 'PU', 'PI', 'PA', 'SN', 'J9', 'JI', 'PY', 'VL', 'IS', 'BP', 'EP', 'DI', 'PG', 'WC', 'SC', 'GA', 'UT']

RecordCollection object

RecordCollection is the object that metaknowledge uses the most. It is your interface with the data you want.

To iterate over all of the Records you can use a for loop

[7]:
for R in RC:
    print(R)
EXPERIMENTS IN PHENOMENOLOGICAL ELECTRODYNAMICS AND THE ELECTROMAGNETIC ENERGY-MOMENTUM TENSOR
OBSERVATION OF SHIFTS IN TOTAL REFLECTION OF A LIGHT-BEAM BY A MULTILAYERED STRUCTURE
ANGULAR SPECTRUM AS AN ELECTRICAL NETWORK
SHIFTS OF COHERENT-LIGHT BEAMS ON REFLECTION AT PLANE INTERFACES BETWEEN ISOTROPIC MEDIA
DISCUSSIONS OF PROBLEM OF PONDEROMOTIVE FORCES
A Novel Method for Enhancing Goos-Hanchen Shift in Total Internal Reflection
Optical properties of nanostructured thin films
Simple technique for measuring the Goos-Hanchen effect with polarization modulation and a position-sensitive detector
CONSERVATION OF ANGULAR MOMENT WITH SIX COMPONENTS AND ASYMMETRICAL IMPULSE ENERGY TENSORS
INTERFERENCE THEORY OF REFLECTION FROM MULTILAYERED MEDIA
Longitudinal and transverse effects of nonspecular reflection
TRANSVERSE DISPLACEMENT OF A TOTALLY REFLECTED LIGHT-BEAM AND PHASE-SHIFT METHOD
MECHANICAL INTERPRETATION OF SHIFTS IN TOTAL REFLECTION OF SPINNING PARTICLES
WHY ENERGY FLUX AND ABRAHAMS PHOTON MOMENTUM ARE MACROSCOPICALLY SUBSTITUTED FOR MOMENTUM DENSITY AND MINKOWSKIS PHOTON MOMENTUM
SPIN ANGULAR-MOMENTUM OF A FIELD INTERACTING WITH A PLANE INTERFACE
Numerical study of the displacement of a three-dimensional Gaussian beam transmitted at total internal reflection. Near-field applications
LONGITUDINAL AND TRANSVERSE DISPLACEMENTS OF A BOUNDED MICROWAVE BEAM AT TOTAL INTERNAL-REFLECTION
EXCHANGED MOMENTUM BETWEEN MOVING ATOMS AND A SURFACE-WAVE - THEORY AND EXPERIMENT
ASYMMETRICAL MOMENTUM-ENERGY TENSORS AND 6-COMPONENT ANGULAR-MOMENTUM IN PROBLEM CONCERNING 2 PHOTON MOMENTA AND MAGNETODYNAMIC EFFECT PROBLEM
Experimental observation of the Imbert-Fedorov transverse displacement after a single total reflection
RESONANCE EFFECTS ON TOTAL INTERNAL-REFLECTION AND LATERAL (GOOS-HANCHEN) BEAM DISPLACEMENT AT THE INTERFACE BETWEEN NONLOCAL AND LOCAL DIELECTRIC
Goos-Hanchen shift as a probe in evanescent slab waveguide sensors
THEORETICAL NOTES ON AMPLIFICATION OF TRANSVERSE SHIFT BY TOTAL REFLECTION ON MULTILAYERED SYSTEM
INTERNAL PHOTON IMPULSE OF DIELECTRIC AND ON COUPLE APPLIED TO ANISOTROPIC CRYSTAL
SPIN ANGULAR-MOMENTUM OF A FIELD INTERACTING WITH A PLANE INTERFACE
CALCULATION AND MEASUREMENT OF FORCES AND TORQUES APPLIED TO UNIAXIAL CRYSTAL BY EXTRAORDINARY WAVE
Goos-Hanchen and Imbert-Fedorov shifts for leaky guided modes
PREDICTION OF A RESONANCE-ENHANCED LASER-BEAM DISPLACEMENT AT TOTAL INTERNAL-REFLECTION IN SEMICONDUCTORS
GENERAL STUDY OF DISPLACEMENTS AT TOTAL REFLECTION
NONLINEAR TOTALLY REFLECTING PRISM COUPLER - THERMOMECHANIC EFFECTS AND INTENSITY-DEPENDENT REFRACTIVE-INDEX OF THIN-FILMS
DISPLACEMENT OF A TOTALLY REFLECTED LIGHT-BEAM - FILTERING OF POLARIZATION STATES AND AMPLIFICATION
Transverse displacement at total reflection near the grazing angle: a way to discriminate between theories

The individual Records are index by their WOS numbers so you can access a specific one in the collection if you know its number.

[8]:
RC.getWOS("WOS:A1979GV55600001")
[8]:
<metaknowledge.record.Record at 0x7f07784be860>

Citation object

Citation is an object to contain the results of parsing a citation. They can be created from a Record

[9]:
Cite = R.createCitation()
print(Cite)
Pillon F, 2005, APPL PHYS B-LASERS O, V80, P355, DOI 10.1007/s00340-005-1728-2

Citations allow for the raw strings of citations to be manipulated easily by metaknowledge.

Filtering

The for loop shown above is the main way to filter a RecordCollection, that said there are a few builtin filters, e.g. yearSplit(), but the for loop is an easily generalized way of filtering that is relatively simple to read so it the main way you should filter. An example of the workflow is as follows:

First create a new RecordCollection

[10]:
RCfiltered = mk.RecordCollection()

Then add the records that meet your condition, in this case that their title’s start with 'A'

[11]:
for R in RC:
    if R.title[0] == 'A':
        RCfiltered.addRec(R)
[12]:
print(RCfiltered)
Collection of 3 records

Now you have a RecordCollection RCfiltered of all the Records whose titles begin with 'A'.

One note about implementing this, the above code does not handle the case in which the title is missing i.e. R.title is None. You will have to deal with this on your own.

Two builtin functions to filter collections are yearSplit() and localCitesOf(). To get a RecordCollection of all Records between 1970 and 1979:

[13]:
RC70 = RC.yearSplit(1970, 1979)
print(RC70)
Collection of 19 records

The second function localCitesOf() takes in an object that a Citation can be created from and returns a RecordCollection of all the Records that cite it. So to see all the records that cite "Yariv A., 1971, INTRO OPTICAL ELECTR".

[14]:
RCintroOpt = RC.localCitesOf("Yariv A., 1971, INTRO OPTICAL ELECTR")
print(RCintroOpt)
Collection of 1 records

Exporting RecordCollections

Now you have a filtered RecordCollection you can write it as a file with writeFile()

[15]:
 RCfiltered.writeFile("Records_Starting_with_A.txt")

The written file is identical to one of those produced by WOS.

If you wish to have a more useful file use writeCSV() which creates a CSV file of all the tags as columns and the Records as rows. IF you only care about a few tags the onlyTheseTags argument allows you to control the tags.

[16]:
selectedTags = ['TI', 'UT', 'CR', 'AF']

This will give only the title, WOS number, citations, and authors.

[17]:
RCfiltered.writeCSV("Records_Starting_with_A.csv", onlyTheseTags = selectedTags)

The last export feature is for using metaknowledge with other packages, in particular pandas, which you will learn about later, but others should also work. makeDict() creates a dictionary with tags as keys and lists as values with each index of the lists corresponding to a Record. pandas can accept these directly to make DataFrames.

[18]:
import pandas
recDataFrame = pandas.DataFrame(RC.makeDict())