F#CsvTypeProvider不读完整字符串

时间:2015-08-15 08:55:00

标签: .net f# type-providers

我正在尝试使用下面提到的代码使用F#CsvTypeProvider阅读movies.txt

type movies = CsvProvider<"../../movies.csv","/",InferRows=0,HasHeaders=false,IgnoreErrors=true,AssumeMissingValues=true,MissingValues="">

F#推断电影类型为:FSharp.Data.Runtime.CsvFile<System.Tuple<string,string,string>> 因此,只读取前三列值。我知道它不是一个统一的csv文件,即每一行都没有相同数量的列。我想知道这个文件是否适合CsvProvider。还有其他类型的提供程序可以解析上面提到的文件吗?

样本记录

Akira (1988)/Louie, Detroit/Lindsay, Michael (II)/Martin, Dan (II)/Stone, Doug (I)/Blum, Steven Jay/Woren, Dan/Forest, Michael (I)/Wurst, Brad/Akimoto, Yôsuke/Cole, George C./Katô, Masayuki (I)/Prescott, Simon/Reynolds, Mike (I)/Held, Watney/Prince, Derek Stephen/Lembaw, Mike/Ôtake, Hiroshi/Lang, Lex/Kusao, Takeshi/Arakawa, Tarô/Bosch, Johnny Yong (I)/Strong, Sam (I)/Buckley, Ivan/Taggert, Jim/Hirano, Masato/Seth, Joshua/Sholder, Adam/Inagaki, Satoru/Sasaki, Nozomu/Buchholz, Bob/Joyce, Christopher (I)/Sorich, Michael/Hustin, Matthew/Lemay, Lewis/Thornton, Kirk/Nakamura, Tatsuhiko/Staley, Steve (II)/Grant, Dougary/McConnohie, Michael/Pinkham, Guy/Kishino, Yukimasa/Ishida, Tarô/Umezu, Hideyuki/Osborne, Jonathan C./Iwata, Mitsuo/Tanaka, Kazumi/Stellrecht, Skip/Kamifuji, Kazuhiro/Spellos, Peter/Pope, Tony/Lee, Peter (I)/Winant, Bruce/Price, Jamieson/Ikemizu, Michihiro/Clarke, Cam/Oliver, Tony (I)/Rae, Ted/Futamata, Issei/Axelrod, Robert/Murray, Ethan/Gurd Jr., Stanley/Ôkura, Masaaki/Romersa, Joe/Walters, Burt/Kramer, Steve (I)/Kitamura, Kôichi/Mercer, Matthew/Bassett, William/Suzuki, Mizuho/Kelso, Lee/Nitta, Sanshirô/Knight, William (III)/Genda, Tesshô/Wimberger, Kurt P./Plantagenet, Richard/Shioya, Kôzô/Hatch, W.T./MacKenzie, Cody/Bergen, Bob/Frierson, Eddie/Itô, Fukue/Phelan, Julie (III)/Brown, Emily (I)/Lane, Marilyn/Ferhardt, Josil/Darro, Bambi/Fujii, Kayoko/Thornton, Chloe/Ôno, Yuka/Goodson, Barbara/Gee, Jessica/Taylor, Julie Anne/Ruff, Michelle/Koyama, Mami/Tissier, Barbara/Cody, Lara/Fuchizaki, Yuriko/Lee, Wendee/Toyoshima, Masami/Ja Lee, Patricia/Forstadt, Rebecca/Tarulli, Lisa/Fox, Sandy (I)/Marshall, Mona (I)/Sarducci, Tony
Aladdin (1992)/Burton, Corey/Cummings, Jim (I)/Young, Philip/Williams, Robin (I)/Welker, Frank/Adler, Charles (I)/Gottfried, Gilbert/Kane, Brad (I)/Proctor, Phil/Gooch, Bruce/Seale, Douglas/Weinger, Scott/Angel, Jack (I)/Wahl, Chris/Houser, Jerry/Freeman, Jonathan (I)/Clarke, Philip L./Pinney, Patrick/Adler, Bruce/McGowan, Mickie/Taylor, Russi/Derryberry, Debi/Lockwood, Vera/Larkin, Linda/Lynn, Sherry (I)/Darling, Jennifer/Zielinski, Kathy/Salonga, Lea

记录基本上是正斜杠(/)分隔的字符串,其中包含电影名称,后跟演员姓名。

1 个答案:

答案 0 :(得分:2)

您很可能对movies.csv的相对路径有疑问。也许它是不正确的,因此类型提供程序将给定路径解释为行类型推断的示例字符串。并且由于您的分隔符是反斜杠,它最终会从../../movies.csv派生行string*string*string来获取行类型。

您可以找出相对路径的错误并修复它,或者只使用csv文件的绝对路径,如下面的代码段所示:

    [<Literal>]
    let path = @"your absolute path to csv data file"
    type Movies = CsvProvider<path,"/",.....>