forked from evelinag/StarWars-social-network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getNames.fsx
41 lines (30 loc) · 1.17 KB
/
getNames.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#load "packages/FsLab/FsLab.fsx"
#load "parseScripts.fs"
open FSharp.Data
open System
open System.IO
open StarWars.ParseScripts
// ===========================================================================
// Extract character names from the scripts
let allNames =
scriptUrls
|> List.map (fun (episode, url) ->
let script = getScript url
let scriptParts = script.Elements()
let mainScript =
scriptParts
|> Seq.map (fun element -> element.ToString())
|> Seq.toArray
// Now every element of the list is a single scene
let scenes = splitByScene mainScript []
// Extract names appearing in each scene
scenes |> List.map getCharacterNames |> Array.concat )
|> Array.concat
|> Seq.countBy id
|> Seq.filter (snd >> (<) 1) // filter out characters that speak in only one scene
for (name, count) in allNames do printfn "%s - %d" name count
// Now follows a manual step - filter out names that are not actual names of characters
// such as "PILOT" or "GUARD"
// Print the selected character names
let characters = File.ReadAllLines(__SOURCE_DIRECTORY__ + "/data/characters.csv")
characters |> Array.sort |> Array.iter (printfn "%s")