Reading FilesΒΆ

First we need to import metaknowledge like we saw in lesson 1.

[1]:
import metaknowledge as mk

we only need metaknowledge for now so no need to import everything

The files from the Web of Science (WOS) can be loaded into a RecordCollections by creating a RecordCollection with the path to the files given to it as a string.

[2]:
RC = mk.RecordCollection("savedrecs.txt")
repr(RC)
[2]:
'savedrecs'

You can also read a whole directory, in this case it is reading the current working directory

[3]:
RC = mk.RecordCollection(".")
repr(RC)
[3]:
'files-from-.'

metaknowledge can detect if a file is a valid WOS file or not and will read the entire directory and load only those that have the right header. You can also tell it to only read a certain type of file, by using the extension argument.

[4]:
RC = mk.RecordCollection(".", extension = "txt")
repr(RC)
[4]:
'txt-files-from-.'

Now you have a RecordCollection composed of all the WOS records in the selected file(s).

[5]:
print("RC is a " + str(RC))
RC is a Collection of 32 records

You might have noticed I used two different ways to display the RecordCollection. repr(RC) will give you where metaknowledge thinks the collection came from. While str(RC) will give you a nice string containing the number of Records.