Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'RecordCollection' object has no attribute 'addRec' #9

Open
palermog opened this issue Jan 29, 2020 · 3 comments
Open

'RecordCollection' object has no attribute 'addRec' #9

palermog opened this issue Jan 29, 2020 · 3 comments

Comments

@palermog
Copy link

palermog commented Jan 29, 2020

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?

@tcrick
Copy link
Collaborator

tcrick commented Feb 2, 2020

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!

@tcrick
Copy link
Collaborator

tcrick commented Jun 19, 2020

Closing for lack of activity. Feel free to re-open.

@tcrick tcrick closed this as completed Jun 19, 2020
@tcrick tcrick reopened this Jun 19, 2020
@tcrick
Copy link
Collaborator

tcrick commented Jun 19, 2020

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 RecordCollections 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants