Skip to content

Commit 808b335

Browse files
committed
added new options to coAuth
Former-commit-id: f5de1bf
1 parent f7608a3 commit 808b335

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

metaknowledge/recordCollection.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def makeDict(self, onlyTheseTags = None, longNames = False, cleanedVal = True, n
471471
retDict[k].append(v)
472472
return retDict
473473

474-
def coAuthNetwork(self):
474+
def coAuthNetwork(self, detailedInfo = False, weighted = True, dropNonJournals = False, count = True):
475475
"""Creates a coauthorship network for the RecordCollection.
476476
477477
# Returns
@@ -487,34 +487,58 @@ def coAuthNetwork(self):
487487
progKwargs = {'dummy' : False}
488488
else:
489489
progKwargs = {'dummy' : True}
490+
if bool(detailedInfo):
491+
try:
492+
infoVals = []
493+
for tag in detailedInfo:
494+
infoVals.append(normalizeToTag(tag))
495+
except TypeError:
496+
infoVals = ['PY', 'TI', 'SO', 'VL', 'BP']
497+
def attributeMaker(Rec):
498+
attribsDict = {}
499+
for val in infoVals:
500+
attribsDict[val] = str(getattr(Rec, val))
501+
if count:
502+
attribsDict['count'] = 1
503+
return attribsDict
504+
else:
505+
if count:
506+
attributeMaker = lambda x: {'count' : 1}
507+
else:
508+
attributeMaker = lambda x: {}
490509
with _ProgressBar(*progArgs, **progKwargs) as PBar:
491510
for R in self:
492511
if PBar:
493512
pcount += 1
494513
PBar.updateVal(pcount/ len(self), "Analyzing: " + str(R))
514+
if dropNonJournals and not R.createCitation().isJournal():
515+
continue
495516
authsList = R.authorsFull
496517
if authsList:
497518
authsList = list(authsList)
519+
detailedInfo = attributeMaker(R)
498520
if len(authsList) > 1:
499521
for i, auth1 in enumerate(authsList):
500522
if auth1 not in grph:
501-
grph.add_node(auth1, count = 1)
502-
else:
523+
grph.add_node(auth1, attr_dict = detailedInfo)
524+
elif count:
503525
grph.node[auth1]['count'] += 1
504526
for auth2 in authsList[i + 1:]:
505527
if auth2 not in grph:
506-
grph.add_node(auth2, count = 1)
507-
else:
528+
grph.add_node(auth2, attr_dict = detailedInfo)
529+
elif count:
508530
grph.node[auth2]['count'] += 1
509-
if grph.has_edge(auth1, auth2):
531+
if grph.has_edge(auth1, auth2) and weighted:
510532
grph.edge[auth1][auth2]['weight'] += 1
511-
else:
533+
elif weighted:
512534
grph.add_edge(auth1, auth2, weight = 1)
535+
else:
536+
grph.add_edge(auth1, auth2)
513537
else:
514538
auth1 = authsList[0]
515539
if auth1 not in grph:
516-
grph.add_node(auth1, count = 1)
517-
else:
540+
grph.add_node(auth1, attr_dict = detailedInfo)
541+
elif count:
518542
grph.node[auth1]['count'] += 1
519543
if PBar:
520544
PBar.finish("Done making a co-authorship network")

0 commit comments

Comments
 (0)