版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【原创】R语言数据分析可视化案例报告论文(附代码数据)
有问题到淘宝找“大数据部落”就可以了
社交网络复杂网络分析我们中的一些人期待着圣诞节的到来,我们中的一些人期待着《星球大战》系列中的新电影《原力觉醒》同时,我决定去看看从定量的角度全6-movie循环提取星球大战的社会网络,在每个电影和整个宇宙星球大战。在社会网络的结构揭示了原三部曲和前传之间的一些惊人的差异。*更新:阅读我对第七集《星球大战:原力觉醒》的分析。如果你对我如何提取数据的技术细节感兴趣,那就来看看我是如何做分析部分的。让我们从一些可视化开始。这是所有6部电影联合起来的社交网络:^admeQui-Gon■DarthV^d@rChewbaciOpennetworkLi*e^admeQui-Gon■DarthV^d@rChewbaciOpennetworkLi*e■ni-Pl1C-3PO.LettKanSoloYoucanopenthenetworkinafullwindowwhichwillshowaninteractivevisualizationofthenetworkwhereyoucandragindividualnodesaround.Ifyouhoverovertheindividualnodes,you'llseethenameofthecorrespondingcharacter.Herethenodesrepresentcharactersinthemovies.Thecharactersareconnectedbyalinkiftheybothspeakinthesamescene.Andthemorethecharactersspeaktogether,thethickerthelinkbetweenthem.Thesizeofeachnodecorrespondstothetotalnumberofscenesthecharacterappearsin.Imadeafewarguabledecisionsthough:AnakinandDarthVaderarerepresentedbytwoseparatenodes,becausethisdistinctionisimportanttothestory.Ontheotherhand,theEmperornodealsojointlyrepresentsPalpatineandDarthSidious.IalsomergedAmidalawithPadme.Theoriginaltrilogy(episodesIV,VandVI)ontherightismostlyseparatedinthenetworkfromtheprequeltrilogyontheleftbecausemostcharactersappearonlyinoneofthetrilogies.ThecrucialnodesthatareconnectingthetwonetworksareObi-WanKenobi,R2-D2andC-3PO.Especiallytherobotsseemtoplayanimportantsocialfunctionbecausetheyappearfrequentlyacrossallthemovies.Thestructuresofthetwosub-networksarealsodifferent.sTheoriginaltrilogyhasfewerimportantnodes(Luke,Han,Leia,Chewbacca,DarthVader)andtheyare【原创】【原创】R语言数据分析可视化案例报告论文(附代码数据)有问题到淘宝找“大数据部落”就可以了denselyinterconnectedbetweenthemselves.Theprequeltrilogyhasmorenodesoverall,withmanymoreconnections.I'lllookatindividualfilmsinmoredetaillaterinthepost.您可以在一个完整的窗口中打开网络,这将显示一个网络的交互式可视化,您可以在其中拖动单个节点。如果在单个节点上悬停,您将看到对应字符的名称。在这里,节点代表电影中的人物。如果两个角色在同一个场景中讲话,则这些字符是通过链接连接的。字符越多,它们之间的联系就越紧密。每个节点的大小对应于角色出现的场景总数。我做了一些有争议的决定,尽管Anakin和达斯•维德是由两个独立的节点来表示,因为这种区分是重要的故事。另一方面,皇帝结还共同代表帕尔帕廷和达斯•西迪厄斯。我也将阿米达拉与Padme。原三部曲(情节IV、V和VI)右边的是网络中的主要分离左侧的前传三部曲因为只有其中的三部曲出现最多的人物。这是连接两个网络ObiWanKenobi的关键节点,R2-D2和C-3PO。特别是机器人似乎发挥着重要的社会功能,因为它们经常出现在所有的电影中。两个子网络的结构也不同。少的原三部曲的重要节点(卢克,汉族,莱娅、巴卡、达斯维德),他们彼此之间的紧密结合。前传三部曲中有更多的节点的整体,更多的连接。我将在后面的文章中更详细地看各个电影。CharactertimelinesManyofthecharactersfeatureinmultiplemovies,soIalsocreatedacomparisonoftheirtimelinesacrosstheindividualepisodes.Thefollowinggraphicsshowswheretheindividualcharactersarementionedinthefilmscripts.Inorderofappearance,thesearethetimelinesofsomeofthemaincharacters:许多角色在多部电影中都有特点,所以我也在各个情节中创建了他们的时间线比较。下面的图形显示电影脚本中提到的各个字符的位置。在外观上,这是一些主要人物的时间线:HereIincludedallmentionsofeachcharacter,whichincludesothercharactersdiscussingtheirname.ItisinterestingtoseehowAnakinappearssimultaneouslywithDarthVaderduringEpisodeIII,andthenDarthVadertakesover.AnakinagainreappearstowardstheendofEpisodeVIwhenDarthVaderturnsawayfromtheDarkside.Thecharactersthatappearmostconsistentlyacrossallthefilmsarethesameonesthatareinthecentreofthesocialnetwork-Obi-Wan,C-3POandR2-D2.YodaandtheEmperoralsoappearacrossallofthefilmsbuttheydon'ttalkdirectlywithmanypeopleintheoriginaltrilogy,whichmovesthemoffthecentreinthesocialnetwork.在这里,我提到了每个角色的所有提到,其中包括其他字符讨论他们的名字。很有趣的是Anakin在第三集时是如何与达斯•维德同时出现的,然后达斯•维德接手了。Anakin在第六集结束时又重新出现了,达斯•维德转身离开黑暗面。出现最一致的所有的电影都是在社会网络的中心的ObiWan一样的人物,C-3PO和R2-D2。
YodaandtheEmperor也出现在所有的电影,但他们不说话直接与原三部曲里的许多人,使他们在社会网络的中心。Networksinindividualfilms个人电影中的网络Nowlet'slookatthenetworksinindividualfilms.Noticehowthenumberofnodesandcomplexityofthenetworkschangebetweentheprequelsandtheoriginalmovies.Again,alinkappearsbetweencharactersiftheyspeakwithinthesamescene.现在让我们看看个人电影中的网络。注意:节点和网络的复杂性的数量变化的前传和电影之间。同样,如果字符在同一场景中说话,则会出现字符之间的链接。Epd5ddEtTTiePhanlDmMenaoeEpisodeHAUackofIbeClaMKrwLwrkQI:#fihaSith■VtKlliEpri^cdorv^ANtiuHapfiPThVidirZEihcdtVThatm|E=iSlrilnElidLEpd5ddEtTTiePhanlDmMenaoeEpisodeHAUackofIbeClaMKrwLwrkQI:#fihaSith■VtKlliEpri^cdorv^ANtiuHapfiPThVidirZEihcdtVThatm|E=iSlrilnElidLImportanceofcharactersmorecharactersandmoreTheindividualnetworksagainshowthattheprequeltrilogyhasinteractionsoverall.Theoriginalepisodeshavelesscharacters,buttheyinteractmorewitheachother.morecharactersandmoreGeorgeLucassaid:ItreallyisthestoryofthetragedyofDarthVader,anditstartswhenhe'snine,anditendswhenhe'sdead.(source)ButisDarthVader/Anakinreallythecentralcharacter?Let'susesomemethodsfromnetworkanalysistoseewhoisreallyimportantinthestoriesandtheirsocialstructures.Icomputedtwomeasuresofimportanceinthenetworksforeachofthefilms:重要人物个人网络再次表明,前传三部曲有更多的人物和更多的互动的整体。原剧集的角色较少,但它们之间的互动更多。乔治卢卡斯说:“这确实是达斯•维德悲剧的故事,故事从他九岁开始,他死后就结束了。”但是达斯•维达/阿纳金真的是主角吗?让我们使用网络分析的一些方法,看看谁在故事和他们的社会结构中真的很重要。我计算了两个衡量网络中每一个电影的重要性:7Degreecentrality-thisissimplythenumberofconnectionsthenodehasinthenetwork.IntheStarWarsmovies,thiscorrespondstothetotalnumberofsceneswhereeachcharacterspeaks.度中心性-这仅仅是节点在网络中的连接数量。在星球大战电影中,这相当于每个角色说话的场景总数。7Betweenness-thismeasurelooksathowmanyshortestpathsinthenetworkleadthroughthenode.Forexample,imagineyouareLeiaandyouwanttosendamessagetoGreedo-theshortestpathhowtosenditisviaHanSolo,becauseheinteractedbothwithLeiaandwithGreedo.Onthe
otherhandifyouwanttosendamessagetoLuke,youdon'thavetogothroughHanbecauseLeiaknowsLukedirectly.ThebetweennesscentralityforHaniscomputedusingthenumberofshortestpathsbetweenallothercharactersthatpassthroughhim.中间性-这项措施着眼于网络中有多少条最短路径通过该节点。例如,假设你是莱娅和你想发送一个消息给Greedo的最短路径如何发送它通过HanSolo,因为他有Leia和Greedo的互动。另一方面,如果你想发送一个消息给卢克,你不必经过Han因为莱娅知道卢克直接。Han使用通过他的所有其他字符之间的最短路径数来进行计算。Thetwomeasuresbothshowhowimportantisacharacterinthenetwork.Thedegreecentralityshowshowmanypeopledoeseachcharacterinteractwithdirectly.Thebetweennessrelatesmoretohowintegraleachofthecharactersistothestory.Characterswithhighbetweennessconnectdifferentareasofthesocialnetwork.Forbothmeasures,highervaluesmeanmoreimportance.Herearethetop5charactersforeachmovie:这两项措施都显示了网络中人物的重要性。度中心表示每个字符直接与多少人交互。这中间涉及到如何整体的每一个人物的故事。中介性连接的社会网络的不同的区域。对干这两种度量,更高的值意味着更重要。下面是每部电影的前5个字符:Name□fE^ee1.QUI-GCM262.AKAklh23Name□fE^ee1.QUI-GCM262.AKAklh23XmAjaRLP4.L95.哪科EL6Betweenncfis1OUI-CjWfll.T2-majaji3.EMPtROH4.Episode15.HameDepwLMAKIN212Om-WAJM191IT4.K1DA.105MAHwiftCu10htimeBcTwttnn«51DBJ-wan2MpMF1MACLWhCU1Z7<JARjmR阳5.E^PLROREpisodeUNorreDefiret!1ANAKIN143l□BIUUAN注1RAILDACM4A13Jk11£10EpisodeHEISUfTKBcriwcnnMS1OBI-WNF*JDME1WULDffljftN^*5ItseemsthatAnakinisoverallthemostconnectedcharacterinthefirstthreefilms,basedonhisdegree.Heishowevernotveryintegraltotherelationsinthefilms!Hisbetweennessscoreissosmallhenevermakesittothetop-5characters.ThismeansthatalltheothercharactersinteractdirectlybetweenthemselvesratherthanthroughAnakin.Howdothesamemeasureslookfortheoriginaltrilogy?根据他的学位,Anakin似乎是前三部电影中最有联系的人物。然而,他并不是电影中关系中不可或缺的人物!他的得分是如此之小,他从不介了五大人物。这意味着所有其他字符直接在自己之间进行交互,而不是通过Anakin。同样的方法是如何寻找原始三部曲的?
NwIweLLKFHL7!l.Idtl;MA9.LUUS9d3L£»1gATHWUDEE1U±espo逐H*WIfiO3iL£IA9.7iiWTHWlDKUSt»D4.MH6.74:CHEwaaxAOEWHWX*1J0工RMJZ«.S8JH00NnMnUUKENnMnUUKEIS1LUICEULEUIEEDisniHWCERL2CMCID1l-KN1.1CIWBMK*¥RH>Ztl1IAN5.D3PCIDEpdsMLeIVEpisodeVEpiftwieVIIMjraBafmiiLuurtE15-2.昭M1£1C-K>11Q1.klAJI1Hereboththecentralitymeasuresshowverysimilarresults-Lukeisthemostcentralcharacteracrossallthefilms,andusingbothmeasures.Theorderofcharactersbasedonthetwomeasuresisalmostthesame.Thecentralityanalysisquantifiessomeofthethingswecouldseefromthesocialnetworks.Theprequeltrilogyhasmorecomplexsocialstructures,withmoreinterconnectedcharacters.ThisalsoleadstothefactthatAnakinisnotthatcentraltothestory-someofthestorylineshappenalongsideAnakin'sstory,orinvolveAnakinonlyontheside.Ontheotherhand,theoriginaltrilogyhasamoretight-knitstructure.Thereisasmallernumberofcentralcharactersandtheybindthestorytogether-thisresultsintotheagreementbetweenthedegreeandbetweennesscentralitymeasures.Perhapsthisispartofthereasonwhytheoriginaltrilogyismorepopular-theplotsaremoreconsistentanddrivenbythemaincharacters.Theprequelshaveamoredecentralizedstructureandnoclearhero.AlthoughthestoriesarelinkedbyAnakin,heisnotbindingtheothercharacterstogether.Howdothemeasureslookwhenwelookatthefullsocialnetworkfromalltheepisodestogether?Ilookedattwovariantsofthenetwork.InthefirstoneAnakinandDarthVaderappearastwoseparateindividuals,inthesecondImergedthemtogetherintoasingleperson.在这里,两个中心测量都显示出非常相似的结果——卢克是所有电影中最核心的人物,同时使用这两种方法。基于这两个度量的字符顺序几乎相同。中心性分析量化了我们从社交网络中可以看到的一些东西。前传三部曲有更复杂的社会结构与更多的关联特征。这也导致Anakin不是一些情节发生在Anakin的故事中,或是Anakin只能在一旁。另一方面,原始三部曲的结构更加紧凑。有少量的中心人物和他们的故事一起绑定结果进度和中介中心性措施之间的协议。也许这是原始三部曲更受欢迎的部分原因——情节更为一致,由主要人物推动。前传有更分散的结构并没有明确的英雄。虽然这些故事是由Anakin联系在一起的,但他并没有把其他的人物连在一起。当我们从所有的剧集中看完整的社交网络时,这些措施是怎么看的?我看了两种不同的网络第一个阿纳金和达斯•维德是两个独立的个体,第二个我把他们合并成一个人。
忡ameDegreeLANAKM42忡ameDegreeLANAKM422.R2HD2412O&I-WAN374.PADME345.C-3PO31Jointnetwork1AnakinmtiDairthVaderseparated忡NITVDogr&e1.□ARTHWDER592.R2-D2413.OBI-WAN574.PADME34S.C-3PO31Jointnetwork2AnakinandDarthVaderfusedNameBetweenness1OBI-WAN37042,PADME237.3aR2D2236.7C3PO222.9s.LUKE194ANameBetweenness,1.□BkWAN34B.72.G3POMil3.□ARTHVADER2415生R2^D2227.6S.PADME226.2IfwelookatAnakinandDarthVaderseparately,Anakinisstillthemostconnectedcharacterbuthe'snotcentraltothenetwork.Ifwemergethemtogether,thingsimproveabit.NowDarthVader/Anakinisthethirdmostimportantcharacterintermsofbetweenness.Overall,thesocialnetworksseemtoshowthattheStarWarsmoviesareactuallylinkedtogetherbyObi-WanKenobiratherthanDarthVader.如果我们分别看Anakin和达斯•维德,Anakin仍然是最有联系的人物,但他不是网络的核心人物。如果我们把它们合并在一起,情况就会有所改善。现在,达斯维德/阿纳金从中间最重要的第三个字。总的来说,社会网络似乎表明,星球大战电影实际上是由ObiWanKenobi而不是达斯•维德联系在一起的。HowIdidtheanalysisAsthisispartoftheF#Adventcalendar,IusedF#formostoftheanalysis.IcombinedittogetherwithD3.jsforthesocialnetworkvisualizations,andwithRforthenetworkcentralityanalysis.YoucanfindallthesourcecodeonmyGitHub.Becausethewholecodeturnedouttoberelativelylong,hereIlookonlyatsomeofthemoreinterestingparts.我是怎么做分析的?这是F#日历的一部分,我用F#大部分的分析。我把它连同社会网络可视化d3.js,和R的网络中心性分析。你可以在我的github找到所有的源代码。因为整个代码比较长,所以我只看一些更有趣的部分。ParsingthescreenplaysIstartedbydownloadingallthescriptsforthe6StarWarsmovies.TheyarefreelyavailablefromTheInternetMovieScriptDatabase(IMSDb),forexamplehere'sthescriptforEpisodeIV:TheNewHope.Thescreenplaysareonlyintheformofdraftsthatsometimesdifferfromtheactualfilms-thedifferencesarehowevernotverybig.我开始下载6星球大战电影的所有脚本。他们可以自由地从互联网电影数据库(imsdb脚本),例如这里的插曲四脚本:新的希望。剧本只在有时与实际电影的差异却不很大的汇票的形式。【原创】【原创】R语言数据分析可视化案例报告论文(附代码数据)有问题到淘宝找“大数据部落”就可以了【原创】【原创】R语言数据分析可视化案例报告论文(附代码数据)有问题到淘宝找“大数据部落”就可以了Thefirststepwastoparsethescreenplays.Tocomplicatethings,eachofthemusedaslightlydifferentformat.ThescreenplaysthemselveswereinHTML,eitherwithinthe<tdclass="srctext"></td>tags,orwithinthe<pre></pre>tags.Toextractthecontentsofeachscript,IusedtheHtmlParserfromF#DatalibrarywhichallowsaccessingindividualtagsinaHTMLdocumentusingstatementslike第一步是分析剧本。为了使事情复杂化,他们每个人都使用了稍微不同的格式。剧本本身是在HTML中,<tdclass="srctext"></td>tags,orwithinthe<pre></pre>tags无论是在<<TDclass=“srctext”></标签,或在<><>标记/预预。提取每个脚本的内容,我用HTML解析器从F#数据库,允许使用诸如HTML文档访问单独的标签1;openPSharp.Data2:leturl=M/scripts/Star-Wars-A-New-H叩m.htniL"3:HtmlDocument.LoadCurl).Descendants(rtpre")ThefullcodeforthispartisavailableintheparseScripts.fsfile.Thenextstepwastoextractrelevantinformationfromthescripts.Ingeneral,ascriptlookslikethis:对于这部分的完整代码在parsescripts.fs文件是可用的。下一步是从脚本中提取相关信息。一般来说,脚本如下所示:INT.GANTRY-OUTSIDECONTROLROOM-REACTORSHAFTLukemovesalongtherailinganduptothecontralroom^[…]LUKEHetoldmeenoughIItwasyouwhokilledhim,VADERNo.IamyourfatherHShockedTLukelooksatVaderinutterdisbelief,LUKENo.No.That'snottrue!That^impassibleIEachscenestartswithitssetting:INT.(interior)orEXT.(exterior)andthelocationofthescene.Thentherecanbesomefreetextdescribingwhatishappeningandhowdoesthescenelook.Inthedialogues,thenamesofcharactersarewrittenincapitalletters(sometimesalsoinbold),followedbywhattheyaresaying.ThemainsignpostsinthescreenplayaretheINT.andEXT.statementswhichserveassceneseparators.Thesewerewrittenconsistentlyinboldinallthe6scriptsandIusedthemtosplitthemintoindividualscenes:每一个场景开始设置:INT.(室内)或EXT.(外观)和场景的位置。然后就可以有一些免费的文字来描述正在发生的事情,以及场景的外观。在对话中,人物的名字用大写字母写(有时也用黑体字),后面跟着他们说的话。在剧本的主要标志是信息和外部报表作为场景分离器。在所有这6个脚本中,这些都是用粗体写的,我用它们把它们分割成单独的场景:1://splitthescriptbyscene2://eachscenestartswitheitherIMTBorEXTB3:lpt「吕匸splitBySeerue(script:string[J)scenes»4:letscenePattern=0-9]*(INTa|EXT.)+,5:letidx=6:script7:[>Seq-tryFindlndex(funlineRegex.Mstchdinie,scenePattern)PSuccess)8:matchidlxwith9:|Soflie1IQ:letrem^iiningScenes=script.[i*1+冃]11:letcurrentScene■script.[0.,i-1]12:spLitBy^cenerefnainingScenes(currentScene::scenes)13:|None!script::scenesThisisarecursivefunctionthattakesthefullscreenplayandlooksforthespecificpattern,whichisEXT.orINT.inbold,optionallyprecededbyascenenumber.Thefunctiongoesthroughthestringandwhenitencountersthescenebreak,itsplitsthestringintothecurrentsceneandtheremainingtext.Thenitrunsrecursivelyuntilallthescenesareextracted,usingthescenesvariableasanaccumulator.这是一个递归函数,以完整的剧本和寻找特定的模式,这是EXT.orINT.inbold前面可以使用场景的数量。函数通过字符串,当它遇到场景中断时,它将字符串分割为当前场景和剩余文本。然后递归地运行,直到所有场景被提取,使用场景变量作为累加器。GettinglistofcharactersThepreviousfunctiongavemealistofscenesforeachofthemovies.Extractingthecharactersoutofthemturnedouttobemoredifficult.SomeofthescenesfollowedtheformatthatIshowedintheexampleabove,someofthescenesonlyusedcharacternamesfollowedbyacolonandtheirdialogue,allwithinthesamelineinthetext.Theonlycommonpropertybetweenthedifferentformatswasthatthenameswerealwayswrittenincapitalletters.获取字符列表前一个功能给了我一张每部电影的场景列表。从中提取字符变得更加困难。有些场景遵循我在上面的例子中所展示的格式,一些场景只使用字符名,后面是冒号和它们的对话,它们都在文本的同一行中。不同格式之间唯一的共同属性是名字总是用大写字母写的。Iresortedtoregularexpressions,oneforeachscreenplayformat:1:f/Extractnamesofcharactersthatspeakinscenes・2://A)Extractnames-ofcharacte『s;intheformatH[ngme]:*3LetgetFomatlNamestext=4:letmatches=RegexrMatches(text.p,[M-Z0-9-]+*:")5letnames=6{foirminmatchesim.Value}7|aSeq.m^p(funn^me->nameaTrini([||1';8::||>Array,ofSeq9:Ih-namesiM::ifB)Extractnamesofcharactersintheformat"<b>[n^me]I2.LetgetFornat2Namestext=I3:letm=Regex.Matchftext,叫b;>[]*[/A-Z0-9-]+[I4:ifm.SuccessthenI5:letname=m,Value,Replacet1'^'!n<>)rReplate("</b>11^,,)<Truii{)I6.LL[|nmme|]:piriinEachoftheregularexpressionsmatchesnotonlycapitalletters,butalsonumbers,hypens,spacesandslashes.AllbecausethecharactersinStarWarsusenameslike"R2-D2"oreven"FODE/BEED".
每一个正则表达式匹配不仅大写字母,也是数字,连字符,空格和斜线。因为在星球大战人物使用的名字如“R2-D2”甚至“"FODE/BEED"”。Toactuallyextractthelistofcharactersthatappearacrossthefilms,Ialsohadtotakeintoaccountthefactthatmanycharactersusemultiplenames.SenatorPalpatineturnsintoDarthSidiousandthenintoTheEmperor,AmidaladisguisesherselfasPadme(ortheotherwayaround?).BecauseofthisImanuallyputtogetherasimplefilealiases.csvwhereIspecifiedwhichnamesIconsidertobethesame.Iusedtheseasamappingontoauniquenameforeachcharacter(exceptforAnakinandDarthVader).为了实际提取电影中出现的字符列表,我还得考虑到许多字符使用多个名称的事实。帕尔帕廷参议员变成达斯•西迪厄斯然后到皇帝,阿米达拉化装成Padme(或其他方式?)因为这我手动把一个简单的文件aliases.csv我指定的名字我认为是相同的。我把这些映射到每个字符的唯一名称(除了Anakin和达斯•维德)。1:LetaliMFiW=_SOURCE_DIRECTORV_+-Vdata/aliases.csvM2://Usecsvtypeprovidertc玄stheesvfilewithaliases3:typeAliases=CsvProvider<aLiasFile>4:5:ff/DictionaryforttcinslatingcharacternamesbetweenaliasesE:letali站Dixt=7:Aliases.LeadCaliasFile).Rows8:|>Seq.map(funrow->row.Alias,.row.Name)9:|>diet10:11:///Mapcharacternamesontouniquesetofnames12:letmapNamename=ifaliasDict.ContainsKey(name^thenaliasDict.[name]elsename13:14:ff/E)ctractcharacternamesfromthegivenscene15:letgetCharacterNames(scene:string[])=16:letnamesi=scene|aSeq.collectgetFormat1Names17:letname£2=Scene\>Seq.collectgetFonnat2hldines18:Seqrappendnames1names215:|>Seq.mapmapName20:|aSeq.distinctNowIcouldfinallyextractnamesofcharactersfromtheindividualscenes!Thefollowingfunctionextractsallthenamesofcharactersfromallthescreenplayurls.现在我终于可以从单个场景中提取人物的名字了!以下函数从所有脚本URL中提取所有字符的名称。1:l&tallName^>scriptUris|>List.map(fun(episode^url)1stitript=getScripturlletsuriptPartw=scriptElem^ntsOletmainScript■昙urIptParts|aSeq.map(funelement->element.ToStringf))|>Seq□toArray//Howeveryelementofthelistisasinglescenelet盘亡gfiEg■splitBySc&nemainScript[]//Extractnamesappearingineacrhscene£cene$|>List.mapgetCharacterHames|>Array.concat}|>Array,concat|>Seq.countByid|>Seq.filter(snd»)1)1/filteroutcharactersthatfipeakinonlyonesceneTheonlyremainingproblemwasthatmanyofthenameswerenotactualnames.Thelistwasfull
ofpeoplecalled"PILOT"or"OFFICER"or"CAPTAIN".AfterthisImanuallywentthroughtheresultsandfilteredoutthenamesthatwereactualnames.Thisresultedinthecharacters.csvfile.唯一剩下的问题是,许多名字不是真正的名字。名单上满是名为“飞行员”、“军官”或“船长”的人。在此之后,我手动检查结果并过滤掉实际名称的名称。这导致了characters.csv文件。InteractionsbetweencharactersToconstructthesocialnetworks,Iwantedtoextractalltheoccasionswhentwocharacterstalktoeachother.Thishappensiftwocharactersspeakwithinthesamescene(Idecidedtoignoresituationswhenpeopletalkwitheachotheroveratransmitter,andthereforeacrossscenes).ExtractingcharactersthatarepartofthesamedialoguewasnowsimplifiedbecauseIcouldjustlookatthelistofcharactersIputtogetherinthepreviousstep.字符之间的相互作用为了构建社交网络,我想提取两个字符相互交谈的所有场合。如果两个字符在同一场景中讲话(我决定忽略人们在发射机上交谈,因此在场景中交谈),就会出现这种情况。提取属于同一对话部分的字符现在简化了,因为我可以只看一下我在上一步中放在一起的字符列表。1:letcharacters=2:File.ReadAlLLinesf_50URCE_DIRECT0R¥_+"/data/charaEteirs.csv1')3:|>Array・append(Seq3appendaliasDict.KeyssliasDitt.VialLje^|>Array4:|>setHereIcreatedasetofallcharacternamesandtheiraliasestouseforlookupandfiltering.ThenIusedittosearchthroughthecharactersappearingineachscene:在这里,我创建了一组所有字符名称及其别名,用于查找和过滤。然后我用它来搜索每个场景中出现的字符:letscenes=splitBySceneniainScript[]|>List.revletletscenes=splitBySceneniainScript[]|>List.revletnamesInScenes=scenes|>List.mapgetCharacterNawies|>List.map(fuinnsmes->rsames|>ay.filter(funn->characters.ContainsnJ)ThenIusedthefilteredlistofcharacterstodefinethesocialnetwork:然后,我使用过滤后的字符列表来定义社交网络://CreatEweightednetworkLetnodesnaneslnSceFies|>Seq.c^ll«ct|>Seq.c$«|fiEBy14//thrhUTtiAfef|aSeq.filter(fun(nafi&Pcount)->count>■=cowitThrestwid)letnodeLcxslkup-nodes|>Seq.inapfstI*setMtlinks=|*List.collect(funnajiBE->[far1inD^.iianes.Length-1da-forjin1+1□.nmes.Length--Idletn1=nsnffj.(i]Irtn2=MM*r[jQifnKM^Loakup-Ggntsinsfhl)«Aup-CwtainsCn2)then$$ordernodesalphabeticallyyieldmLnnln2Bnaxnln2])|>5eq.co<iotByidThisgavemealistofnodeswiththenumberoftimestheyspokeacrossthewholescript,whichIusedtospecifythesizeofnodesinthevisualizations.ThenIcreatedalinkforeachtimetwocharactersspokewithinthesamescene,andcountedthemtogetthestrengthofeachrelationship.Together,thenodesandlinksdefinedthefullsocialnetwork.这给了我一个节点列表,它们在整个脚本中发言的次数,我用来指定可视化中节点的大小然后,我创建了一个链接,每次两个字符在同一场景中发言,并计算它们获得每一个关系的力量。在一起,节点和链接定义了完整的社交网络。Finally,IexportedthedataintotheJSONformat.Youcanfindallthenetworks,boththeglobaloneandtheindividualepisodes'networks,onmyGithub.ThefullcodeforthisstepisinthegetInteractions.fsxscript.最后,我将数据导出到JSON格式。尔可以找到所有的网络,无论是整体和个体事件的网络,在我的GitHub。在这一步中的完整代码是在getinteractions.fsx脚本。CharactermentionsinthescriptIalsodecidedtolookatwhereeachofthecharactersappearsthroughoutthesixmoviecycle,resultinginthetimelineschart.ForthisIlookedatallthetimesthenameofthecharacterwasmentionedinthescripts,notlimitedtothenumberoftimesthecharacteractuallyspoke.Thecodeforthiswaslargerlysimilartoextractingtheinteractionsintheprevioussection,onlyhereIwaslookingforallthementionsandnotonlyforthedialogues.Togettheactualtimelines,Ialsokepttrackofthescenenumbers.Thefollowingcodesnippetreturnsalistofscenenumbersandcharactersthatarementionedinthem.脚本中提到的字符我还决定查看每个角色在六个电影周期中出现的时间线图表。为此,我看了所有的时间,在剧本中提到了人物的名字,而不仅仅限于人物所说的次数。这个代码是由类似于前一段的相互作用中,只有我在这里寻找所有提到不仅为对话。为了得到实际的时间线,我也记录了场景编号。下面的代码片段返回其中提到的场景编号和字符列表。1::Utscenes=2;splitByScenem^imScript|[]|>List.rev3;A•lettotalSc&nes-scenes.Length■r■5;scenes6:|>List.imapi(funisceneldxscene7://containtyposwithlower-casecharacters8;Q-letIscene=scene|>Array-map(funs->s.TalowerO)10;characters11;|>Array.map(funnan>e->12:1SEBD@13:|>Aritay.map(funcontentsifcontainisNanftecontentsnamethenSomenameelseNone)4:|>Array.chaaaeid)15;|>Array.concat16;|>自y,iwp(fynftame亠niapNsmeToUpper()))17;|>Seq,distinct18:|>Seq.m/p(funname・》sceneldx^name)9::|>List.afSeq)20:!|>List.collectid,21::t&talScenesTogetthefulltimeline,Iusedthescenenumberstomapeachepisodeintoa[episodeindex-1,episodeindex]interval,givingmearelativescaleofwhereintheepisodethecharacterappeared.Thescenetimesinintervals[0,1]arefromEpisodeI,in[1,2]correspondtoEpisodeIIetc.得到充分的时间,我用现场数字地图每集为一个[事件指数-1集指数]区间,给我一个相对规模在一集的角色出现。在区间[0,1]上的场景的时间从第一集,在[1,2],对应第二集等。1://extracttimelines>'[05]3:|>Li&t.map(funepiscdeldK->^etSceneAppearancesepisodeldx)M.|>Li&t.mapi(funcpisodeldx(sccneAppearangw*total)->5.s匚eneAppearances6:|>List.map(funnan电)->7;floatepisodeldx*floatsceneIfloattotal,n^ine)}Isavedthisdataintoanill-formatedpseudo-csvfile,whereeachrowcontainsacharacternameandtherelativetimesthecharacterappearedacrossthe6films,separatedbycommas.【原创】R语言数据分析可视化案例报告论文(附代码数据)有问题到淘宝找“大数据部落”就可以了ThefullcodeisinthegetMentions.fsxfile.我救了这个数据不形成伪CSV文件,其中每一行包含一个字符的名称和相应的时代特征出现在6部电影中,以逗号分隔。完整的代码是在getmentions.fsx文件。Addingnon-speakingcharactersWhenIcomparedtheinteractionsandthecharactersthatwerementionedinthescripts,Inoticedthatsomethingwasdifferent:therewasnoR2-D2andnoChewbacca.NotonlythepoorWookieedidn'treceiveanymedalattheendofEpisodeIV(likethehumanheroesdid),buthewasmissingfromallthedialoguesinthescreenplays!Actually,bothChewbaccaandR2-D2appearthroughoutthescriptsasnon-speakingcharacters.TheyarementionedinlineslikeArtoofindssomethingthatmakeshimwhistlewildly.orAsuddenfrowncrossesChewbacca'sfaceandhebeginsyellinggibberishatthetinyrobot.当我比较,在脚本中提到的作用和特点,我注意到有些不同:没有R2-D2和没有Chewbacca。可怜的Wookiee不仅没有受到任何金牌的第四端(如人类的英雄一样),但他在剧本的所有对话的缺失!其实,无论是Chewbacca和R2-D2出现在脚本作为非母语的特点。他们提到的线条如下阿图发现一些让他疯狂地吹口哨。或突然皱眉穿过Chewbacca的脸,他开始大喊大叫,胡言乱语的小机器人。Itwouldn'tbeaproperStarWarssocialnetworkifweignoredthesetwoimportantcharacters.TocorrectfortheracialdiscriminationagainstWookieesandastromechdroids,Idecidedtoinsertthemintothesocialnetworkdefinedbydialogues.Ilookedagainatallthetimesthesecharactersgotmentionedinthescreenplay.Thementionsalsodefineasocialnetworkwheretwocharactersarelinkedtogetheriftheyarementionedinthesamescene.Becausethecharactersareincludedinthescenedescriptionsandtheyalsotalkabouteachothermorethantheyactuallyappearonscreen,thenetworkdefinedbyallmentionsismuchmessierthanthenetworkdefinedbydirectinteractions.Becauseofthis,Icouldn'tusetheChewbacca'sandR2-D2'sconnectionsdirectlyinthesocialnetwork.Icouldhoweveruseitasanapproximation.如果忽略了这两个重要人物,这将不是一个合适的星球大战社交网络。正确的对Wookieesandastromech机器人种族歧视,我决定将它们插入到由对话的社会网络。我又看了一遍这些角色在电影剧本中提到的时代。提到的还定义了一个社交网络,如果两个字符在同一场景中被提及,那么它们会链接在一起。因为汉字中包含的场景描述,他们也谈论对方其实比他们出现在屏幕上,所有提到的定义网络是比直接相互作用定义的网络乱得多因为这个,我不能用楚巴卡和R2-D2的连接直接在社交网络。我可以用它作为一个近似值。Iextractedthenodesizesandlinksforthetwomissingcharactersfromthenetworkdefinedbymentions.Totransformthemintoconnectionsfromthesocialnetwork,Idecidedtoscalealltheirvaluesbycomparingthemwithsimilarcharacters.Forthis,IchoseC-3POasaproxyforR2-D2,andHanasaproxyforChewie,assumingtheirinteractionswerelargelysimilar.ThenIappliedthefollowingformulatocomputethelinkstrengthsinthedialoguesocialnetwork(thisexampleusesChewbaccaandHan):【原创】R语言数据分析可视化案例报告论文(附代码数据)有问题到淘宝找“大数据部落”就可以了我从所定义的网络中提取了两个丢失字符的节点大小和链接。为了将它们转换成社交网络的连接,我决定通过与类似的字符比较它们的所有值。为此,我选择了C-3P0作为代理的R2-D2,汉为代理Chewie,假设它们之间的相互作用在很大程度上是相似的。然后我使用下面的公式计算在对话中社会网络的链接强度(本例使用楚巴卡和汉族):Iusedthishighlyscientificequationtorecomputeallthelinkstrenghtsandalsothenodesizes.Theweightfactorwasaround0.5bothforHanandC-3PO,whichmeansthecharacterswereonaveragementionedtwotimesmorethantheyactuallyspokeinthefilms.Afterthis,Idiscardedallthelinksthathadtheirweightsmallerthanone.Thecodeforthisstepisrelativelylongbutnotveryinteresting.我用这个很科学的公式重新计算所有的链接强度和节点的大小。权重系数是0.5左右的汉族和C-3PO,即性状平均比他们竟然说在电影中两次提到。在此之后,我放弃了所有的链接,他们的重量比一个小。这一步的代码比较长,但不是很有趣。VisualizationsAftermanuallyaddingbackChewbaccaandR2-D2,Ifinallyhadthefullsetofsocialnetworksbothfortheindividualmoviesandforthefullfranchise.IusedtheForcetovisualizethenetworks...well,Iactuallyusedtheforce-directednetworklayoutfromtheD3.jslibrary.Thisvisualizationmethodusesaphysicalsimulationofchargedparticlestogenerateanetworklayout.ThemostimportantpartoftheD3JavaScriptfileisthefollowingpart:可视化效果在手动添加回楚巴卡和R2-D2,我终于有了对个人电影和完整的特许经营社交网络的全套。我用原力使网络可视化…嗯,其实我用的有向网络布局从d3.js图书馆的力量。这种可视化方法使用带电粒子的物理模拟来生成网络布局。D3JavaScript文件中最重要的部分是以下部分:-jsofl("■stsnrars-episade-1-interactipus-a11Charactersrjsen11.fynctio<iCerrorrgraph)</*Morecodehere*/vanlink=svg-selectAl1(*.linkH)+data(graphsLinks)enter()Tappendl(Hline")kattr(,!class",style£*stroke-width*Pfunctioned){returnMathsqrtfd+value);卜);varnode=svg.selectAll(**.node")raphi-nodes)enter[J*appendCcircle").attr("class11.-node?fc).attrfr";S)stylet"fill"ifun-ctiori(d){returndLcolour;})rattr(,,r",11function(d){return2*liathi.sqrtfdrvalu
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 10781.13-2026白酒质量要求第13部分:液态法白酒
- 2025-2026年幼儿园大班语言表达专项练习题
- 2026年人教版高一数学必修一第十二章模拟试卷
- 2025-2026年重庆市苏教版初中物理力学综合测试卷
- 2025-2026年广东省苏教版高三数学概率统计同步练习题
- 2026年湖南省苏教版高中化学必修第一册元素周期律习题集
- 2025-2026年重庆市部编版四年级语文上册第3单元综合测试卷
- 2025-2026年天津市苏教版八年级生物第8课生物多样性练习题
- 2025-2026年考研外语黑山语阅读理解专项训练习题
- 2026年人教版初中英语下册第12章知识点巩固习题
- 儿童功能性腹痛诊疗指南
- 安徽省省十联考2027届高三上学期第一次教学质量测评物理试卷(含答案)
- 【小学】【秋季上】高年级【信息技术】开学第一课【课件】
- 2026年学习教育工作总结
- SG-CIM模型建设与实践
- 电气设备检修安全生产技术常识培训课件
- 装配式建筑预制混凝土构件质量管理标准
- 小学五年级上册音乐教案(人音版)
- 课堂碎嘴子的代价 课件2025-2026学年高一下学期纪律主题班会
- 产品采购检验制度
- 高等数学(上下册全套)全套教学课件
评论
0/150
提交评论