metaknowledge
metaknowledge copied to clipboard
'RecordCollection' object has no attribute 'addRec'
First, thank you so much for this package.
I have been following along with the example pages and have been able to successfully plot a network diagram and identify communities with louvain detection. However, now I am running into a problem:
I want to plot a subset of my corpus, so referred to your documentation on filtering with a for loop, like so:
RCfiltered = mk.RecordCollection()
for R in RC:
if R.title[0] == 'A':
RCfiltered.addRec(R)
However, I am getting an error message:
AttributeError: 'RecordCollection' object has no attribute ‘addRec'
I have tried changing “addRec” to “add”, since I have seen that syntax elsewhere with other record collection objects, with seemingly no success. Any suggestions to move forward?
Hi palermog. It is the case that this example is dated and addRec is deprecated, sorry about that, but RCfiltered.add(R) does work on my end. Can you provide the code as you're using it? Thanks!
Closing for lack of activity. Feel free to re-open.
This doesn't seem to work in the example notebook - I had previously tried RCfiltered.add(R)
on a non-empty existing RecordCollection()
, which worked and still works. But with an empty mk.RecordCollection()
object, there is no error message, yet the RecordCollection
remains empty. The only reason I can guess that this would work on a non-empty collection but not an empty one is that the type of the empty RecordCollection()
might not be matching the WOS
record type that's being added, although I would expect an error. Perhaps empty RecordCollection
s should be initialized with object
as the default allowed type. We will have to look into this one.
In the meantime, filtering can currently be done by reversing the logic:
RCfiltered = RC.copy()
for R in RC:
if R.title[0] != 'A':
RCfiltered.discard(R)
Be sure to iterate over the original RC
object, as they are sets
under the hood and you can't modify a set
that you're iterating through.