The Network and Trajectories of Transitions

among Sentential Co-Occurrences of Noun Phrases in

Plato's Phaedrus

By Moses Boudourides & Sergios Lenis

IMPORTANT: To use this notebook, you'll need to

  1. Install IPython Notebook (easiest way: use Anaconda)
  2. Download this notebook and all other Python scripts used here from https://github.com/mboudour/WordNets/blob/master/Plato_Phaedrus_Network&Trajectories.ipynb
  3. Run ipython notebook in the same directory where notebook and scripts were put

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

Importing Python Modules

In [1]:
import random
import nltk
import codecs
from textblob import TextBlob
import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
from collections import Counter
import imp
# utilsdir='/home/sergios-len/Dropbox/Python Projects (1)/utils/'#tools.py'
utilsdir='/home/mab/Dropbox/Python Projects/utils/'

%matplotlib inline 
%load_ext autoreload
/usr/local/lib/python2.7/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')

I. Importing the Text of Plato's Phaedrus

In [2]:
filename = 'Plato_Phaedrus1.txt'
titlename = "Plato's Phaedrus"

f = codecs.open(filename, "r", encoding="utf-8").read()

num_lines = 0
num_words = 0
num_chars = 0
for line in f:
    words = line.split()
    num_lines += 1
    num_words += len(words)
    num_chars += len(line)
print "%s has number of words = %i and number of characters = %i" %(titlename,num_words,num_chars)

blob = TextBlob(f)
Plato's Phaedrus has number of words = 102009 and number of characters = 125944

II. Extracting the Most Frequent Noun Phrases in Plato's Phaedrus

In [3]:
all_sents=blob.sentences
occurdic=Counter()
for sen in all_sents:
    dd=sen.dict
    for np in dd['noun_phrases']:
        occurdic[np]+=1

df = pd.DataFrame(columns=["%s Noun Phrases" %titlename, "Frequencies"])
u=1
for l,v in occurdic.items(): 
    df.loc[u]=[l,v]
    u+=1

print "The total number of noun phrases in %s is %i." %(titlename,len(df))#len(npA))
df.sort(["Frequencies"], ascending=[0])

cut = 2
df = df[df['Frequencies']>cut].sort(["Frequencies"], ascending=[0])
print "The total number of noun phrases in %s with frequencies > %i is %i." %(titlename,cut,len(df))#len(npA))
df.sort(["Frequencies"], ascending=[0])
The total number of noun phrases in Plato's Phaedrus is 739.
The total number of noun phrases in Plato's Phaedrus with frequencies > 2 is 37.
/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py:15: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)
/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py:18: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)
/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py:20: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)
Out[3]:
Plato's Phaedrus Noun Phrases Frequencies
734 socrates 215
135 phaedrus 211
678 lysias 34
192 muses 11
737 god 9
299 zeus 7
677 true 5
540 well 5
441 fair youth 5
351 thamus 5
13 theuth 5
392 tisias 5
497 suppose 4
352 shall 4
381 matters stand 4
193 whole soul 4
486 homer 4
574 thrasymachus 4
169 nymphs 4
431 enough 4
174 odysseus 4
433 nestor 3
460 ilissus 3
461 true beauty 3
350 exactly 3
496 will 3
360 isocrates 3
509 midas 3
618 hippocrates 3
190 eros 3
182 boreas 3
699 good friend 3
717 acumenus 3
293 listen 3
353 who 3
254 stesichorus 3
306 pericles 3
In [4]:
%autoreload 2

selectedTerms={}
excluded = ['who','will','exactly','enough','shall','suppose','well']
for k in df["Plato's Phaedrus Noun Phrases"].tolist(): #df["Plato's Phaedrus Noun Phrases"].tolist():
    if k not in excluded:
        selectedTerms[k] = k.capitalize()
tool= imp.load_source('tools', utilsdir+'tools.py')
create_pandas_dataframe_from_text=tool.create_pandas_dataframe_from_text  

dfst,sec_prot,coccurlist,occurlist,dflines=create_pandas_dataframe_from_text(blob,selectedTerms,selectedTerms,titlename)
# print len(sec_prot.nodes()), sec_prot.nodes()
# dfst.sort_values(by='Frequencies').sort(["Frequencies"], ascending=[0])

prot_pol_sub=dflines[['protagonists','#_of_protagonists','polarity','subjectivity']].reset_index()
prot_pol_sub['sentence_id']=prot_pol_sub.index
prot_pol_sub=prot_pol_sub[['sentence_id','protagonists','#_of_protagonists','polarity','subjectivity']]

cuts = 1
prot_pol_sub = prot_pol_sub[prot_pol_sub['#_of_protagonists']>cuts]
lp = prot_pol_sub['protagonists'].tolist()
lpn = []
for i in lp:
    for j in i:
        lpn.append(j)
# len(set(lpn))
print "The total number of sentences in %s with at least %i selected noun phrases in each one of them is %i." %(titlename,cuts+1,len(prot_pol_sub))
prot_pol_sub.rename(columns={'protagonists':'list_of_selected_noun_phrases','#_of_protagonists':'#_of_selected_noun_phrases'},inplace=True)
prot_pol_sub.sort(["#_of_selected_noun_phrases"], ascending=[0]) #.drop('sentence_id', 1)
ddff = prot_pol_sub.drop('sentence_id', 1)
ddff.index.name = 'sentence_id'
ddff
The total number of sentences in Plato's Phaedrus with at least 2 selected noun phrases in each one of them is 27.
/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py:29: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)
Out[4]:
list_of_selected_noun_phrases #_of_selected_noun_phrases polarity subjectivity
sentence_id
6 [Acumenus, Lysias] 2 0.150000 0.491667
24 [Fair youth, Socrates, Lysias] 3 0.550000 0.775000
34 [Phaedrus, Lysias] 2 0.143750 0.547817
67 [Ilissus, Socrates, Boreas] 3 0.000000 0.000000
148 [Socrates, Zeus] 2 0.206667 0.351667
177 [Phaedrus, Lysias] 2 0.200000 0.200000
183 [Phaedrus, Lysias] 2 -0.033333 0.825000
209 [Muses, Good friend] 2 0.466667 0.500000
310 [Homer, Stesichorus] 2 0.000000 0.708333
312 [Homer, Stesichorus] 2 0.294444 0.455556
334 [Fair youth, Phaedrus] 2 0.350000 0.450000
455 [Phaedrus, Eros] 2 0.400000 0.800000
457 [Phaedrus, Lysias] 2 0.040000 0.406667
591 [Odysseus, Nestor] 2 0.000000 1.000000
593 [Thrasymachus, Odysseus, Nestor] 3 -0.250000 0.500000
706 [Nymphs, Lysias] 2 0.300000 0.750000
760 [Muses, Eros] 2 0.220833 0.330556
786 [Thrasymachus, Lysias] 2 0.500000 1.000000
864 [Socrates, Phaedrus] 2 0.068229 0.504167
871 [Thrasymachus, Lysias] 2 0.100000 1.000000
1015 [Thamus, Theuth] 2 -0.062500 0.187500
1016 [Theuth, Thamus] 2 -0.025000 0.450000
1018 [Theuth, Thamus] 2 0.530000 0.760000
1068 [Phaedrus, True] 2 0.350000 0.650000
1099 [Homer, Nymphs, Lysias] 3 -0.061728 0.545062
1119 [Isocrates, Phaedrus] 2 0.175000 0.575000
1127 [Isocrates, Lysias] 2 -0.125000 0.375000
In [5]:
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset

ndfl=dflines[dflines['#_of_protagonists']>0  ]

fig, ax = plt.subplots(figsize=[12, 10])
axes2 = zoomed_inset_axes(ax, 6, loc=5)  # zoom = 6

dflines['#_of_protagonists'].plot.hist(ax=ax)

ax.set_xlabel('#_of_Characters')
ax.set_ylabel('Frequency')
ax.set_title('Histogram of # of characters')

x1, x2, y1, y2 = 2.9, 3., 0, 25
axes2.set_xlim(x1, x2)
axes2.set_ylim(y1, y2)
ndfl['#_of_protagonists'].plot.hist(ax=axes2)
axes2.set_ylabel('Frequency')

mark_inset(ax, axes2, loc1=2, loc2=4, fc="none", ec="0.5")
axes3 = zoomed_inset_axes(ax, 6, loc=10)

x1, x2, y1, y2 = 2, 2.05, 0, 30
axes3.set_xlim(x1, x2)
axes3.set_ylim(y1, y2)
ndfl['#_of_protagonists'].plot.hist(ax=axes3)
axes3.set_ylabel('Frequency')

mark_inset(ax, axes3, loc1=2, loc2=4, fc="none", ec="0.5")

plt.show()
In [6]:
%autoreload 2

draw_network_node_color=tool.draw_network_node_color
sstt="%s Two-Mode Network of Sentences and Selected Noun Phrases" %titlename
pos=nx.spring_layout(sec_prot)
nds=[nd for nd in sec_prot.nodes() if isinstance(nd,int)]
prot=[nd for nd in sec_prot.nodes() if nd not in nds]

for en,nd in enumerate(nds):
    if en<len(nds)/2.:
        pos[nd][0]=-1
        pos[nd][1]=en*2./len(nds)
    else:
        pos[nd][0]=1
        pos[nd][1]=(en-len(nds)/2.)*2./len(nds)
for en ,nd in enumerate(prot):
    pos[nd][0]=0
    pos[nd][1]=en*1./len(prot)
    
possit=draw_network_node_color(sec_prot,sstt,pos=pos,with_edgewidth=False,withLabels=True,labfs=12,valpha=0.2,
                               ealpha=0.4,labelfont=15,with_node_weight=False,node_size_fixer=300.,node_col='polarity')
In [7]:
possit=draw_network_node_color(sec_prot,sstt,pos=pos,with_edgewidth=False,withLabels=True,labfs=12,valpha=0.2,
                               ealpha=0.4,labelfont=15,with_node_weight=False,node_size_fixer=300.,
                               node_col='subjectivity',colormat='Greens')

III. Constructing the Network of Sententially Co-Occurring Noun Phrases in Plato's Phaedrus

In [8]:
%autoreload 2

plist = prot_pol_sub['list_of_selected_noun_phrases'].tolist()
pplist=prot_pol_sub['polarity'].tolist()
nplist=prot_pol_sub['#_of_selected_noun_phrases'].tolist()
splist=prot_pol_sub['subjectivity'].tolist()

G = tool.make_graph_from_lists(plist,pplist,nplist,splist)
posg=nx.spring_layout(G,scale=50)#,k=0.55)#,iterations=20)

sstt="%s Network of Selected Noun Phrases \n(Sentences colored in polarity)" %titlename
possit=tool.draw_network(G,sstt,pos=posg,with_edgewidth=True,withLabels=True,labfs=15,valpha=0.2,ealpha=0.7,labelfont=15,
                   with_edgecolor=True,edgecolor='polarity',colormat='Blues')
In [9]:
sstt="%s Network of Selected Noun Phrases \n(Sentences colored in subjectivity)" %titlename
possit=tool.draw_network(G,sstt,pos=posg,with_edgewidth=True,withLabels=True,labfs=15,valpha=0.2,ealpha=0.7,labelfont=15,
                   with_edgecolor=True,edgecolor='subjectivity',colormat='Greys')

IV. Centralities of Nodes in the Network of Sententially Co-Occurring Noun Phrases in Plato's Phaedrus

In [10]:
centrali=tool.draw_centralities_subplots(G,pos=posg,withLabels=False,labfs=5,figsi=(15,22),ealpha=1,vals=True)

The table of Centralities of Nodes in the Network of Sententially Co-Occurring Noun Phrases in Plato's Phaedrus

In [11]:
dfc=pd.DataFrame()
u=0
for i,k in centrali.items():
    dfc.insert(u,i,k.values())
    u+=1
dfc.insert(0,'Nodes',centrali[centrali.keys()[0]].keys())
dfc
Out[11]:
Nodes closeness_centrality katz_centrality betweenness_centrality page_rank eigenvector_centrality degree_centrality
0 Homer 0.360000 -0.053608 0.089474 0.053734 1.533181e-01 0.15
1 Isocrates 0.376744 0.056198 0.000000 0.018958 1.874343e-01 0.10
2 Acumenus 0.337500 0.003975 0.000000 0.032971 3.916231e-02 0.05
3 Boreas 0.311538 -0.145885 0.000000 0.038794 4.661858e-02 0.10
4 Odysseus 0.270000 -0.029806 0.000000 0.045422 2.322199e-03 0.10
5 Ilissus 0.311538 -0.145885 0.000000 0.017870 2.271267e-01 0.10
6 Muses 0.261290 0.634843 0.089474 0.017259 1.451883e-02 0.10
7 Phaedrus 0.476471 0.085887 0.323684 0.047619 8.613205e-02 0.30
8 Zeus 0.305660 -0.057182 0.000000 0.029980 1.013023e-01 0.05
9 Lysias 0.522581 -0.092672 0.497368 0.032971 4.904428e-02 0.40
10 Stesichorus 0.261290 -0.004868 0.000000 0.083404 4.661858e-02 0.05
11 Nymphs 0.352174 -0.084968 0.000000 0.037175 2.448529e-01 0.10
12 Socrates 0.450000 -0.193255 0.247368 0.039802 8.845425e-02 0.30
13 Thamus 0.050000 -0.073199 0.000000 0.041417 2.205861e-19 0.05
14 Thrasymachus 0.368182 -0.088619 0.168421 0.050845 2.190857e-01 0.15
15 Theuth 0.050000 -0.073199 0.000000 0.047619 5.152251e-02 0.05
16 Good friend 0.205063 0.446330 0.000000 0.027987 2.205861e-19 0.05
17 Nestor 0.270000 -0.029806 0.000000 0.041417 5.152251e-02 0.10
18 True 0.317647 0.112546 0.000000 0.113585 5.385159e-01 0.05
19 Fair youth 0.415385 -0.061308 0.000000 0.026447 2.265966e-01 0.15
20 Eros 0.344681 0.498552 0.168421 0.154721 6.333739e-01 0.10

V. Communities of Nodes in the Network of Sententially Co-Occurring Noun Phrases in Plato's Phaedrus

In [12]:
%autoreload 2

part,nodper=tool.print_communities(G,sstt)

d=0.8 
dd=0.8
c=1.2
cc=1.4
alpha=0.2
ealpha=0.2
vcc={}
sstta="The %s Communities of %s Network of Selected Noun Phrases" %(max(part.values())+1,titlename)#sstt)

tool.draw_comms(G,G.nodes(),[],[],[] ,part,part,d,dd,c,cc,alpha,ealpha,nodper,sstta,titlefont=20,labelfont=17,valpha=0.5)
Number of communities of Plato's Phaedrus Network of Selected Noun Phrases 
(Sentences colored in subjectivity) = 6
Community partition of Plato's Phaedrus Network of Selected Noun Phrases 
(Sentences colored in subjectivity):
[[u'Homer', u'Stesichorus'], [u'Zeus', u'Socrates', u'Ilissus', u'Boreas'], [u'Nymphs', u'Fair youth', u'Isocrates', u'True', u'Acumenus', u'Phaedrus', u'Lysias'], [u'Muses', u'Good friend', u'Eros'], [u'Theuth', u'Thamus'], [u'Thrasymachus', u'Odysseus', u'Nestor']]
Community modularity of Plato's Phaedrus Network of Selected Noun Phrases 
(Sentences colored in subjectivity) = 0.4976

VII. Trajectories of Transitions among Sentential Co-Occurrences in Plato's Phaedrus

More about Transitions and Trajectories in Temporal Networks:

http://www.slideshare.net/MosesBoudourides/trajectories1

In [13]:
%autoreload 2

tool= imp.load_source('tools', utilsdir+'tools.py')
trj= imp.load_source('trajectories', utilsdir+'trajectories_t.py')
In [14]:
protagonists=prot_pol_sub.list_of_selected_noun_phrases.tolist()

start=range(1,len(protagonists)+1)
end=range(2,len(protagonists)+2)
polarities=prot_pol_sub.polarity.tolist()
subj=prot_pol_sub.subjectivity.tolist()

Transitions among Sentential Co-Occurrences of Phaedrus and Other Characters

In [15]:
qq=0
figi=None
search_name='Phaedrus'

G,ndls,pold,subjd=trj.creatTestGraph_pandas_bips(start,end,protagonists,search_name,polarities,subj)

trajpdfs=trj.main_work_search_name(G,ndls,qq,figi,search_name,verb=False,no_anala=True,plot_first_mode=False)
# trajpdfs=trj.main_work_search_name(G,ndls,qq,figi,search_name,verb=False,no_anala=False,plot_first_mode=False)
['Phaedrus']

Statistics of trajectories of first mode vertices

Phaedrus [[u'Lysias__3', u'Lysias__4'], [u'Lysias__3', u'Lysias__14'], [u'Lysias__3', u'Lysias__8'], [u'Lysias__3', u'Socrates__20'], [u'Lysias__3', u'True__25'], [u'Lysias__3', u'Isocrates__27'], [u'Lysias__6', u'Lysias__4'], [u'Lysias__6', u'Lysias__14'], [u'Lysias__6', u'Lysias__8'], [u'Lysias__6', u'Socrates__20'], [u'Lysias__6', u'True__25'], [u'Lysias__6', u'Isocrates__27'], [u'Socrates__19', u'Lysias__4'], [u'Socrates__19', u'Lysias__14'], [u'Socrates__19', u'Lysias__8'], [u'Socrates__19', u'Socrates__20'], [u'Socrates__19', u'True__25'], [u'Socrates__19', u'Isocrates__27'], [u'True__24', u'Lysias__4'], [u'True__24', u'Lysias__14'], [u'True__24', u'Lysias__8'], [u'True__24', u'Socrates__20'], [u'True__24', u'True__25'], [u'True__24', u'Isocrates__27'], [u'Isocrates__26', u'Lysias__4'], [u'Isocrates__26', u'Lysias__14'], [u'Isocrates__26', u'Lysias__8'], [u'Isocrates__26', u'Socrates__20'], [u'Isocrates__26', u'True__25'], [u'Isocrates__26', u'Isocrates__27'], [u'Fair youth__11', u'Lysias__4'], [u'Fair youth__11', u'Lysias__14'], [u'Fair youth__11', u'Lysias__8'], [u'Fair youth__11', u'Socrates__20'], [u'Fair youth__11', u'True__25'], [u'Fair youth__11', u'Isocrates__27']]
1 trajectories analyzed.
[u'Socrates', u'Fair youth', u'Isocrates', u'Eros', u'True', u'Lysias']

Statistics of trajectories of second mode vertices

Lysias [['Phaedrus__3', 'Phaedrus__4'], ['Phaedrus__3', 'Phaedrus__14'], ['Phaedrus__3', 'Phaedrus__8'], ['Phaedrus__13', 'Phaedrus__4'], ['Phaedrus__13', 'Phaedrus__14'], ['Phaedrus__13', 'Phaedrus__8'], ['Phaedrus__6', 'Phaedrus__4'], ['Phaedrus__6', 'Phaedrus__14'], ['Phaedrus__6', 'Phaedrus__8']]
1 trajectories analyzed.

Statistics of the Trajectory of Transitions among Sentential Co-Occurrences of Phaedrus and Other Characters

In [16]:
trajpdfs["['Phaedrus']"]
Out[16]:
Vertices fOriginator fTransmitter fTerminator fBlackHole fInvolvement pOriginator pTransmitter pTerminator pBlackHole lOriginator lTransmitter lTerminator lBlackHole lInvolvement Position RelPosition Betweenness
0 Socrates 1 0 1 1 1 1.000000 0 1 1.000000 1 0 1.000000 8 1.000000 1.000000 0.000000 0
1 Fair youth 1 0 0 0 1 1.000000 0 0 0.000000 3 0 0.000000 0 3.000000 1.000000 0.000000 0
2 Isocrates 1 0 1 1 1 1.000000 0 1 1.000000 1 0 1.000000 9 1.000000 1.000000 0.000000 0
3 Lysias 2 0 3 2 3 0.666667 0 1 0.666667 1 0 1.666667 6 1.666667 1.666667 33.333333 0
4 True 1 0 1 1 1 1.000000 0 1 1.000000 1 0 1.000000 4 1.000000 1.000000 0.000000 0
5 Eros 0 1 0 0 1 0.000000 1 0 0.000000 0 3 0.000000 0 3.000000 2.000000 50.000000 1

The Trajectory of Transitions among Sentential Co-Occurrences of Phaedrus and Other Characters:

Nodes are Co-Occurrences of Phaedrus with Other Characters

The Color of Nodes Corresponds to Sentential Sentiment Polarities Varying from Color Red (-1) to Color Green (1)

In [17]:
import igraph as ig

igraph_draw_traj=tool.igraph_draw_traj
filname='S_out_graphs/%s_graph.graphml' %search_name
g,visual_style,layout=igraph_draw_traj(filname,pold)

ig.plot(g,  **visual_style)
Out[17]:

The Color of Nodes Corresponds to Sentential Sentiment Subjectivities Varying from Color Red (0) to Color Green (1)

In [18]:
g,visual_style,layout=igraph_draw_traj(filname,subjd,polar=False,layout=layout)

ig.plot(g,  **visual_style)
Out[18]:

Transitions among Sentential Co-Occurrences of Lysias and Other Characters

In [19]:
qq=0
figi=None
search_name='Lysias'

G,ndls,pold,subjd=trj.creatTestGraph_pandas_bips(start,end,protagonists,search_name,polarities,subj)

trajpdfs=trj.main_work_search_name(G,ndls,qq,figi,search_name,verb=False,no_anala=True,plot_first_mode=False)
# trajpdfs=trj.main_work_search_name(G,ndls,qq,figi,search_name,verb=False,no_anala=False,plot_first_mode=False)
[u'Homer', u'Acumenus', u'Nymphs', u'Thrasymachus', u'Fair youth', u'Isocrates', u'Phaedrus']

Statistics of trajectories of first mode vertices

Phaedrus [['Lysias__3', 'Lysias__4'], ['Lysias__3', 'Lysias__14'], ['Lysias__3', 'Lysias__8'], ['Lysias__13', 'Lysias__4'], ['Lysias__13', 'Lysias__14'], ['Lysias__13', 'Lysias__8'], ['Lysias__6', 'Lysias__4'], ['Lysias__6', 'Lysias__14'], ['Lysias__6', 'Lysias__8']]
1 trajectories analyzed.
['Lysias']

Statistics of trajectories of second mode vertices

Lysias [[u'Phaedrus__13', u'Phaedrus__4'], [u'Phaedrus__13', u'Phaedrus__14'], [u'Phaedrus__13', u'Phaedrus__8'], [u'Phaedrus__13', u'Nymphs__17'], [u'Phaedrus__13', u'Isocrates__28'], [u'Phaedrus__13', u'Thrasymachus__19'], [u'Phaedrus__13', u'Thrasymachus__21'], [u'Phaedrus__13', u'Homer__26'], [u'Phaedrus__6', u'Phaedrus__4'], [u'Phaedrus__6', u'Phaedrus__14'], [u'Phaedrus__6', u'Phaedrus__8'], [u'Phaedrus__6', u'Nymphs__17'], [u'Phaedrus__6', u'Isocrates__28'], [u'Phaedrus__6', u'Thrasymachus__19'], [u'Phaedrus__6', u'Thrasymachus__21'], [u'Phaedrus__6', u'Homer__26'], [u'Acumenus__1', u'Phaedrus__4'], [u'Acumenus__1', u'Phaedrus__14'], [u'Acumenus__1', u'Phaedrus__8'], [u'Acumenus__1', u'Nymphs__17'], [u'Acumenus__1', u'Isocrates__28'], [u'Acumenus__1', u'Thrasymachus__19'], [u'Acumenus__1', u'Thrasymachus__21'], [u'Acumenus__1', u'Homer__26'], [u'Nymphs__16', u'Phaedrus__4'], [u'Nymphs__16', u'Phaedrus__14'], [u'Nymphs__16', u'Phaedrus__8'], [u'Nymphs__16', u'Nymphs__17'], [u'Nymphs__16', u'Isocrates__28'], [u'Nymphs__16', u'Thrasymachus__19'], [u'Nymphs__16', u'Thrasymachus__21'], [u'Nymphs__16', u'Homer__26'], [u'Isocrates__27', u'Phaedrus__4'], [u'Isocrates__27', u'Phaedrus__14'], [u'Isocrates__27', u'Phaedrus__8'], [u'Isocrates__27', u'Nymphs__17'], [u'Isocrates__27', u'Isocrates__28'], [u'Isocrates__27', u'Thrasymachus__19'], [u'Isocrates__27', u'Thrasymachus__21'], [u'Isocrates__27', u'Homer__26'], [u'Thrasymachus__18', u'Phaedrus__4'], [u'Thrasymachus__18', u'Phaedrus__14'], [u'Thrasymachus__18', u'Phaedrus__8'], [u'Thrasymachus__18', u'Nymphs__17'], [u'Thrasymachus__18', u'Isocrates__28'], [u'Thrasymachus__18', u'Thrasymachus__19'], [u'Thrasymachus__18', u'Thrasymachus__21'], [u'Thrasymachus__18', u'Homer__26'], [u'Thrasymachus__20', u'Phaedrus__4'], [u'Thrasymachus__20', u'Phaedrus__14'], [u'Thrasymachus__20', u'Phaedrus__8'], [u'Thrasymachus__20', u'Nymphs__17'], [u'Thrasymachus__20', u'Isocrates__28'], [u'Thrasymachus__20', u'Thrasymachus__19'], [u'Thrasymachus__20', u'Thrasymachus__21'], [u'Thrasymachus__20', u'Homer__26'], [u'Homer__25', u'Phaedrus__4'], [u'Homer__25', u'Phaedrus__14'], [u'Homer__25', u'Phaedrus__8'], [u'Homer__25', u'Nymphs__17'], [u'Homer__25', u'Isocrates__28'], [u'Homer__25', u'Thrasymachus__19'], [u'Homer__25', u'Thrasymachus__21'], [u'Homer__25', u'Homer__26']]
1 trajectories analyzed.

Statistics of the Trajectory of Transitions among Sentential Co-Occurrences of Lysias and Other Characters

In [20]:
trajpdfs["['Lysias']"]
Out[20]:
Vertices fOriginator fTransmitter fTerminator fBlackHole fInvolvement pOriginator pTransmitter pTerminator pBlackHole lOriginator lTransmitter lTerminator lBlackHole lInvolvement Position RelPosition Betweenness
0 Homer 1 0 1 1 1 1.000000 0 1 1.000000 1 0 1.000000 5 1.000000 1.000000 0.000000 0
1 Acumenus 1 0 0 0 1 1.000000 0 0 0.000000 3 0 0.000000 0 3.000000 1.000000 0.000000 0
2 Nymphs 1 0 1 1 1 1.000000 0 1 1.000000 1 0 1.000000 6 1.000000 1.000000 0.000000 0
3 Thrasymachus 2 0 2 2 2 1.000000 0 1 1.000000 1 0 1.000000 12 1.000000 1.000000 0.000000 0
4 Fair youth 0 1 0 0 1 0.000000 1 0 0.000000 0 3 0.000000 0 3.000000 2.000000 50.000000 1
5 Isocrates 1 0 1 1 1 1.000000 0 1 1.000000 1 0 1.000000 9 1.000000 1.000000 0.000000 0
6 Phaedrus 2 0 3 2 3 0.666667 0 1 0.666667 1 0 1.666667 8 1.666667 1.666667 33.333333 0

The Trajectory of Transitions among Sentential Co-Occurrences of Lysias and Other Characters:

Nodes are Co-Occurrences of Lysias with Other Characters

The Color of Nodes Corresponds to Sentential Sentiment Polarities Varying from Color Red (-1) to Color Green (1)

In [21]:
import igraph as ig

igraph_draw_traj=tool.igraph_draw_traj
filname='S_out_graphs/%s_graph.graphml' %search_name
g,visual_style,layout=igraph_draw_traj(filname,pold)

ig.plot(g,  **visual_style)
Out[21]:

The Color of Nodes Corresponds to Sentential Sentiment Subjectivities Varying from Color Red (0) to Color Green (1)

In [22]:
g,visual_style,layout=igraph_draw_traj(filname,subjd,polar=False,layout=layout)

ig.plot(g,  **visual_style)
Out[22]:

Transitions among Sentential Co-Occurrences of Socrates and Other Characters

In [23]:
qq=0
figi=None
search_name='Socrates'

G,ndls,pold,subjd=trj.creatTestGraph_pandas_bips(start,end,protagonists,search_name,polarities,subj)

trajpdfs=trj.main_work_search_name(G,ndls,qq,figi,search_name,verb=False,no_anala=True,plot_first_mode=False)
# trajpdfs=trj.main_work_search_name(G,ndls,qq,figi,search_name,verb=False,no_anala=False,plot_first_mode=False)
[u'Fair youth', u'Zeus', u'Phaedrus', u'Ilissus']

Statistics of trajectories of first mode vertices

Ilissus [['Socrates__4', 'Socrates__5']]
1 trajectories analyzed.
['Socrates']

Statistics of trajectories of second mode vertices

Socrates [[u'Fair youth__2', u'Fair youth__3'], [u'Fair youth__2', u'Phaedrus__20'], [u'Fair youth__2', u'Zeus__6'], [u'Phaedrus__19', u'Fair youth__3'], [u'Phaedrus__19', u'Phaedrus__20'], [u'Phaedrus__19', u'Zeus__6'], [u'Ilissus__4', u'Fair youth__3'], [u'Ilissus__4', u'Phaedrus__20'], [u'Ilissus__4', u'Zeus__6']]
1 trajectories analyzed.

Statistics of the Trajectory of Transitions among Sentential Co-Occurrences of Socrates and Other Characters

In [24]:
trajpdfs["['Socrates']"]
Out[24]:
Vertices fOriginator fTransmitter fTerminator fBlackHole fInvolvement pOriginator pTransmitter pTerminator pBlackHole lOriginator lTransmitter lTerminator lBlackHole lInvolvement Position RelPosition Betweenness
0 Fair youth 1 0 1 1 1 1 0 1 1 1 0 1 10 1 1 0 0
1 Zeus 0 0 1 0 1 0 0 1 0 0 0 2 0 2 2 100 0
2 Phaedrus 1 0 1 1 1 1 0 1 1 1 0 1 8 1 1 0 0
3 Ilissus 1 0 0 0 1 1 0 0 0 2 0 0 0 2 1 0 0

The Trajectory of Transitions among Sentential Co-Occurrences of Socrates and Other Characters:

Nodes are Co-Occurrences of Socrates with Other Characters

The Color of Nodes Corresponds to Sentential Sentiment Polarities Varying from Color Red (-1) to Color Green (1)

In [25]:
import igraph as ig

igraph_draw_traj=tool.igraph_draw_traj
filname='S_out_graphs/%s_graph.graphml' %search_name
g,visual_style,layout=igraph_draw_traj(filname,pold)

ig.plot(g,  **visual_style)
Out[25]:

The Color of Nodes Corresponds to Sentential Sentiment Subjectivities Varying from Color Red (0) to Color Green (1)

In [26]:
g,visual_style,layout=igraph_draw_traj(filname,subjd,polar=False,layout=layout)

ig.plot(g,  **visual_style)
Out[26]:
In [ ]: