@@ -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