Skip to content

Commit

Permalink
Update key parser and worksheet parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed Jul 17, 2023
1 parent 2a49bfd commit 4623a46
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 23 deletions.
59 changes: 54 additions & 5 deletions playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#r "nuget: DocumentFormat.OpenXml"
#r "nuget: FSharpAux"
#r "nuget: FsSpreadsheet, 1.2.0-preview"
#r "nuget: FsSpreadsheet.ExcelIO, 1.2.0-preview"
#r "nuget: FsSpreadsheet, 1.3.0-preview"
#r "nuget: FsSpreadsheet.ExcelIO, 1.3.0-preview"
#r "nuget: FSharp.FGL"
#r "nuget: FSharp.FGL.ArrayAdjacencyGraph"

Expand Down Expand Up @@ -40,16 +40,65 @@ open ArcType



let inves = FsWorkbook.fromXlsxFile @"C:\Users\revil\OneDrive\CSB-Stuff\NFDI\testARC30\isa.investigation.xlsx"
//let inves = FsWorkbook.fromXlsxFile @"C:\Users\revil\OneDrive\CSB-Stuff\NFDI\testARC30\isa.investigation.xlsx"
let inves = FsWorkbook.fromXlsxFile @"C:\Users\olive\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.parseRowsAggregated invesWs
//let invesWsParsed = ArcGraphModel.IO.Worksheet.parseColumnsAggregated invesWs
let invesWsParsed = ArcGraphModel.IO.Worksheet.parseRowsFlat invesWs

//invesWsParsed |> Seq.cast<CvParam>
invesWsParsed |> Seq.cast<IParamBase> |> Seq.cast<CvParam>
//invesWsParsed |> List.map (fun x -> x :> CvParam)
invesWsParsed
|> List.take 10
|> List.map (
fun x ->
match x with
| :? CvParam as p ->
Param.getValue p
p.ToString()
| :? UserParam as p ->
Param.getValue p
p.ToString()
)

invesWsParsed
invesWsParsed |> List.iter (List.iter (printfn "%A"))
invesWsParsed.Head |> printfn "%A"
invesWsParsed.Head |> printfn "%O"
(invesWsParsed.Head :?> CvAttributeCollection)
invesWsParsed.Head.ToString()

[1 .. 10] |> printfn "%A"
[1 .. 10] |> printfn "%O"

open System.Text.RegularExpressions

let namePattern = @"(?<=\[).*(?=[\]])"
let key = "Comment[<Investigation Person ORCID>]"
Regex.tryParseValue namePattern key
|> Option.map (fun n ->
CvTerm("",n,"")
)
|> Option.get
|> fun term -> CvParam(term,ParamValue.Value "Hallo",[])

let lol = CvParam("lol", "lol", "lol", ParamValue.Value "lol")
let lol2 = CvParam("lol", "lol", "lol", ParamValue.Value "lol")

lol = lol2

let dict1 = Dictionary<string,string>()
dict1.Add("kek", "lil")
let dict2 = Dictionary<string,string>()
dict2.Add("kek", "lil")

dict1 = dict2


// new CvTypes - testin' and foolin' around
Expand Down
31 changes: 16 additions & 15 deletions src/ArcGraphModel.IO/ISA/KeyParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ module KeyParser =
let namePattern = @"(?<=\[).*(?=[\]])"
Regex.tryParseValue namePattern key
|> Option.map (fun n ->
"",n,""
CvTerm("",n,"")
)

let (|AnnotationID|_|) (key : string) : CvTerm Option =
let namePattern = @"(?<=\[).*(?=[\]])"
Regex.tryParseValue namePattern key
|> Option.map (fun n ->
"",n,""
CvTerm("",n,"")
)

let (|UnMatchable|) (key : string) : string =
Expand All @@ -167,21 +167,22 @@ module KeyParser =
| Token TokenBase.phone term ->
fun (pv) -> CvParam(term,pv,attributes)

| Attribute AttributeBase.person (attribute,key)
| Attribute AttributeBase.investigation (attribute,key)
| Attribute AttributeBase.study (attribute,key)
| Attribute AttributeBase.assay (attribute,key)
| Attribute AttributeBase.publication (attribute,key)
| Attribute AttributeBase.factorType (attribute,key)
| Attribute AttributeBase.designType (attribute,key)
| Attribute AttributeBase.parameter (attribute,key)
| Attribute AttributeBase.characteristic (attribute,key)
| Attribute AttributeBase.rawData (attribute,key)
| Attribute AttributeBase.processedData (attribute,key)
| Attribute AttributeBase.factor (attribute,key) ->
parseKey (attribute :: attributes) key
//| Attribute AttributeBase.person (attribute,key)
//| Attribute AttributeBase.investigation (attribute,key)
//| Attribute AttributeBase.study (attribute,key)
//| Attribute AttributeBase.assay (attribute,key)
//| Attribute AttributeBase.publication (attribute,key)
//| Attribute AttributeBase.factorType (attribute,key)
//| Attribute AttributeBase.designType (attribute,key)
//| Attribute AttributeBase.parameter (attribute,key)
//| Attribute AttributeBase.characteristic (attribute,key)
//| Attribute AttributeBase.rawData (attribute,key)
//| Attribute AttributeBase.processedData (attribute,key)
//| Attribute AttributeBase.factor (attribute,key) ->
// parseKey (attribute :: attributes) key

| StructuredName term ->
printfn "term is %O\tkey is %s" term key
fun (pv) -> CvParam(term,pv,attributes)

| UnMatchable name ->
Expand Down
6 changes: 3 additions & 3 deletions src/ArcGraphModel.IO/ISA/Worksheet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module Worksheet =

/// 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
parseCells (worksheet.Rows) tokenizationFunction worksheet

/// Parses rows of a given FsWorksheet and returns the resulting aggregated ICvBase list.
let parseRowsAggregated (worksheet : FsWorksheet) =
Expand All @@ -36,7 +36,7 @@ module 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
parseCells (Seq.toList worksheet.Columns) tokenizationFunction worksheet

/// Parses columns of a given FsWorksheet and returns the resulting aggregated ICvBase list.
let parseColumnsAggregated (worksheet : FsWorksheet) =
Expand All @@ -48,7 +48,7 @@ module 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
parseCells (worksheet.Tables.Head.Columns(worksheet.CellCollection) |> Seq.toList) tokenizationFunction worksheet

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

0 comments on commit 4623a46

Please sign in to comment.