nfdi4plants / ARCtrl

Library for management of Annotated Research Contexts (ARCs) using an in-memory representation and runtime-agnostic contract systems.
MIT License
16 stars 8 forks source link

[Feature Request] minimal tab seperation support #313

Open Freymaurer opened 9 months ago

Freymaurer commented 9 months ago

Is your feature request related to a problem? Please describe. While developing Swate the need for clipboard support arose. I decided to parse the cells to tab seperated strings, due to:

Describe the solution you'd like

⚠️ Function names are off, there must be ebtter options.

    let internal tryFromContent' (content: string []) =
        match content with
        | [|freetext|] -> CompositeCell.createFreeText freetext |> Ok
        | [|name; tsr; tan|] -> CompositeCell.createTermFromString(name, tsr, tan) |> Ok
        | [|value; name; tsr; tan|] -> CompositeCell.createUnitizedFromString(value, name, tsr, tan) |> Ok
        | anyElse -> sprintf "Unable to convert \"%A\" to CompositeCell." anyElse |> Error

    type CompositeCell with

        static member tryFromContent (content: string []) =
            match tryFromContent' content with
            | Ok r -> Some r
            | Error _ -> None

        static member fromContent (content: string []) =
            match tryFromContent' content with
            | Ok r -> r
            | Error msg -> raise (exn msg) 

        member this.ToTabStr() = this.GetContent() |> String.concat "\t"

        static member fromTabStr (str:string) = 
            let content = str.Split('\t', enum<System.StringSplitOptions>3)
            CompositeCell.fromContent content

        static member ToTabTxt (cells: CompositeCell []) =
            cells 
            |> Array.map (fun c -> c.ToTabStr())
            |> String.concat (System.Environment.NewLine)

        static member fromTabTxt (tabTxt: string) =
            let lines = tabTxt.Split(System.Environment.NewLine, enum<System.StringSplitOptions>3)
            let cells = lines |> Array.map (fun line -> CompositeCell.fromTabStr line)
            cells 
HLWeil commented 8 months ago

I don't quite understand the requested feature from the text 😅

Freymaurer commented 8 months ago

Create tab separated text from composite cells 😅 . Like one line per cell.

Freymaurer commented 8 months ago

:bug: found a bug for cells without tsr tan, in which tabs were trimmed away. so change to:

static member fromTabTxt (tabTxt: string) =
    let lines = tabTxt.Split(System.Environment.NewLine, System.StringSplitOptions.None)
    let cells = lines |> Array.map (fun line -> CompositeCell.fromTabStr line)
    cells