Skip to content

Commit

Permalink
Merge pull request #17 from nfdi4plants/feature-newIOParser-#16
Browse files Browse the repository at this point in the history
#16 New IO parser(s)
  • Loading branch information
omaus authored Jul 17, 2023
2 parents 14e049f + 32ecc07 commit 6ccf979
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
15 changes: 14 additions & 1 deletion playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ open System.Collections.Generic
//#r "c:/repos/csbiology/fsspreadsheet/src/FsSpreadsheet/bin/Debug/netstandard2.0/FsSpreadsheet.dll"
//#r "c:/repos/csbiology/fsspreadsheet/src/FsSpreadsheet.CsvIO/bin/Debug/netstandard2.0/FsSpreadsheet.CsvIO.dll"
//#r "c:/repos/csbiology/fsspreadsheet/src/FsSpreadsheet.ExcelIO/bin/Debug/netstandard2.0/FsSpreadsheet.ExcelIO.dll"
#r @"C:\Repos\nfdi4plants\ArcGraphModel\src\ArcGraphModel\bin\Debug\net6.0\ArcGraphModel.dll"
//#r @"C:\Repos\nfdi4plants\ArcGraphModel\src\ArcGraphModel\bin\Debug\net6.0\ArcGraphModel.dll"
#r @"C:\Repos\nfdi4plants\ArcGraphModel\src\ArcGraphModel\bin\Debug\netstandard2.0\ArcGraphModel.dll"
#r @"C:\Repos\nfdi4plants\ArcGraphModel\src\ArcGraphModel.IO\bin\Debug\netstandard2.0\ArcGraphModel.IO.dll"
//#r @"C:/Users/olive/.nuget/packages/fsharpaux/1.1.0/lib/net5.0/FSharpAux.dll"

open FsSpreadsheet
Expand All @@ -38,6 +40,17 @@ open ArcType



let inves = FsWorkbook.fromXlsxFile @"C:\Users\revil\OneDrive\CSB-Stuff\NFDI\testARC30\isa.investigation.xlsx"

let invesWs = FsWorkbook.getWorksheets inves |> Seq.head
invesWs.RescanRows()
invesWs.CellCollection
invesWs.Rows

let invesWsParsed = ArcGraphModel.IO.Worksheet.parseRowsAggregated invesWs
let invesWsParsed = ArcGraphModel.IO.Worksheet.parseRowsFlat invesWs



// new CvTypes - testin' and foolin' around

Expand Down
70 changes: 38 additions & 32 deletions src/ArcGraphModel.IO/ISA/Worksheet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,53 @@ open FsSpreadsheet

module Worksheet =

let parseRows (worksheet : FsWorksheet) =
/// Parses a given list of FsCells of a given FsWorksheet via a given tokenization function and returns the resulting IAttributeCollection list.
let parseCells cellsList tokenizationFunction (worksheet : FsWorksheet) =
let sheetName = Address.createWorksheetParam worksheet.Name
worksheet.Rows
cellsList
|> List.choose (fun r ->
match r |> Tokenization.parseLine |> Seq.toList with
match tokenizationFunction r |> Seq.toList with
| [] -> None
| l -> Some l
)
|> List.concat
|> List.map (fun token ->
|> List.map (fun token ->
CvAttributeCollection.tryAddAttribute sheetName token |> ignore
token
)

let parseTableColumns (worksheet : FsWorksheet) =
let sheetName = Address.createWorksheetParam worksheet.Name
worksheet.Tables.Head.Columns(worksheet.CellCollection)
|> Seq.toList
|> List.choose (fun r ->
match r |> Tokenization.parseLine |> Seq.toList with
| [] -> None
| l -> Some l
)
|> List.concat
|> List.map (fun token ->
CvAttributeCollection.tryAddAttribute sheetName token |> ignore
token
)
/// Parses rows of a given FsWorksheet via a given tokenization function and returns the resulting IAttributeCollection list.
let parseRows tokenizationFunction (worksheet : FsWorksheet) =
parseCells (worksheet.Rows |> List.map (fun x -> x.Cells)) tokenizationFunction worksheet

let parseColumns (worksheet : FsWorksheet) =
let sheetName = Address.createWorksheetParam worksheet.Name
worksheet.Columns
|> Seq.toList
|> List.choose (fun r ->
match r |> Tokenization.parseLine |> Seq.toList with
| [] -> None
| l -> Some l
)
|> List.concat
|> List.map (fun token ->
CvAttributeCollection.tryAddAttribute sheetName token |> ignore
token
)
/// Parses rows of a given FsWorksheet and returns the resulting aggregated ICvBase list.
let parseRowsAggregated (worksheet : FsWorksheet) =
parseRows Tokenization.parseLine worksheet

/// Parses rows of a given FsWorksheet and returns the resulting flat IParam list.
let parseRowsFlat (worksheet : FsWorksheet) =
parseRows Tokenization.convertTokens worksheet

/// Parses columns of a given FsWorksheet via a given tokenization function and returns the resulting IAttributeCollection list.
let parseColumns tokenizationFunction (worksheet : FsWorksheet) =
parseCells (Seq.toList worksheet.Columns |> List.map (fun x -> x.Cells)) tokenizationFunction worksheet

/// Parses columns of a given FsWorksheet and returns the resulting aggregated ICvBase list.
let parseColumnsAggregated (worksheet : FsWorksheet) =
parseColumns Tokenization.parseLine worksheet

/// Parses columns of a given FsWorksheet and returns the resulting flat IParam list.
let parseColumnsFlat (worksheet : FsWorksheet) =
parseColumns Tokenization.convertTokens worksheet

/// Parses the columns of the first FsTable in a given FsWorksheet via a given tokenization function and returns the resulting IAttributeCollection list.
let parseTableColumns tokenizationFunction (worksheet : FsWorksheet) =
parseCells (worksheet.Tables.Head.Columns(worksheet.CellCollection) |> Seq.toList |> List.map (fun x -> x.Cells)) tokenizationFunction worksheet

/// Parses the columns of the first FsTable in a given FsWorksheet and returns the resulting aggregated ICvBase list.
let parseTableColumnsAggregated (worksheet : FsWorksheet) =
parseTableColumns Tokenization.parseLine worksheet

/// Parses the columns of the first FsTable in a a given FsWorksheet and returns the resulting flat IParam list.
let parseTableColumnsFlat (worksheet : FsWorksheet) =
parseTableColumns Tokenization.convertTokens worksheet

0 comments on commit 6ccf979

Please sign in to comment.