Skip to content

Commit

Permalink
add helper functions and example isa type
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Apr 19, 2023
1 parent c567c64 commit edf0b1c
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 9 deletions.
19 changes: 18 additions & 1 deletion src/ArcGraphModel/CvTokens/CvContainer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,21 @@ type CvContainer (cvAccession:string,cvName:string,cvRefUri:string,properties :
|> Dictionary.ofSeq
CvContainer(term,properties)

new (term : CvTerm) = CvContainer (term,Seq.empty)
new (term : CvTerm) = CvContainer (term,Seq.empty)

static member getManyAs<'T when 'T :> ICvBase> propertyName (cvContainer : CvContainer) =
Dictionary.item propertyName cvContainer
|> Seq.map (fun cv -> cv :?> 'T)

static member getSingleAs<'T when 'T :> ICvBase> propertyName (cvContainer : CvContainer) =
Dictionary.item propertyName cvContainer
|> Seq.exactlyOne
|> (fun cv -> cv :?> 'T)

static member setMany propertyName (values : seq<#ICvBase>) (cvContainer : CvContainer) =
Dictionary.addOrUpdateInPlace propertyName values cvContainer
|> ignore

static member setSingle propertyName (value : #ICvBase) (cvContainer : CvContainer) =
Dictionary.addOrUpdateInPlace propertyName (Seq.singleton value) cvContainer
|> ignore
21 changes: 18 additions & 3 deletions src/ArcGraphModel/CvTokens/CvParam.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,29 @@ type CvParam(cvAccession : string, cvName : string, cvRefUri : string, paramValu
new (cvTerm,pv : ParamValue) =
CvParam (cvTerm,pv,Seq.empty)

static member fromValue(category : CvTerm,v : 'T) =
static member fromValue (category : CvTerm) (v : 'T) =
CvParam(category, ParamValue.Value (v :> IConvertible))

static member fromCategory(category : CvTerm,term : CvTerm) =
static member fromCategory (category : CvTerm) (term : CvTerm) =
CvParam(category, ParamValue.CvValue term)

static member fromValueWithUnit(category : CvTerm,v : 'T, unit : CvUnit) =
static member fromValueWithUnit (category : CvTerm) (v : 'T) (unit : CvUnit) =
CvParam(category, ParamValue.WithCvUnitAccession (v :> IConvertible,unit))

static member getValue (cvp : CvParam) =
(cvp :> IParamBase).Value

static member getValueAsString (cvp : CvParam) =
(cvp :> IParamBase).Value
|> ParamValue.getValueAsString

static member getValueAsInt (cvp : CvParam) =
(cvp :> IParamBase).Value
|> ParamValue.getValueAsInt

static member getValueAsTerm (cvp : CvParam) =
(cvp :> IParamBase).Value
|> ParamValue.getValueAsTerm

override this.ToString() =
$"Name: {(this :> ICvBase).Name}\n\tID: {(this :> ICvBase).ID}\n\tRefUri: {(this :> ICvBase).RefUri}\n\tValue: {(this :> IParamBase).Value}"
9 changes: 9 additions & 0 deletions src/ArcGraphModel/CvTokens/CvTerm.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
//[<Struct>]
type CvTerm = string * string * string

module CvTerm =

let getName (cvTerm : CvTerm) =
match cvTerm with
| id, name, refUri -> name

let fromName (name : string) : CvTerm=
"", name, ""

/// Represents a unit term from the unit ontology
/// in the form of: id|accession * name * refUri
// ?Maybe [<Struct>]
Expand Down
21 changes: 20 additions & 1 deletion src/ArcGraphModel/CvTokens/ParamValue.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,31 @@ type ParamValue =
// value * CvUnit
| WithCvUnitAccession of cvu : IConvertible * CvUnit

static member getValue (param:ParamValue) =
//static member getValueAsStringWithUnit (param:ParamValue) =
// match param with
// | Value v -> string v
// | CvValue (_,v,_) -> v
// | WithCvUnitAccession (v,_) -> string v

static member getValueAsString (param:ParamValue) =
match param with
| Value v -> string v
| CvValue (_,v,_) -> v
| WithCvUnitAccession (v,_) -> string v

static member getValueAsInt (param:ParamValue) =
match param with
| Value v -> v :?> int
| CvValue (_,v,_) -> v |> int
| WithCvUnitAccession (v,_) -> v :?> int

static member getValueAsTerm (param:ParamValue) =
match param with
| Value v -> CvTerm.fromName (v |> string)
| CvValue term -> term
| WithCvUnitAccession (v,_) -> CvTerm.fromName (v |> string)


static member tryGetUnit (param:ParamValue) : CvUnit option =
match param with
| Value _ -> None
Expand Down
24 changes: 20 additions & 4 deletions treeDepiction.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,33 @@ open System.Collections
open System.Collections.Generic




type Protocol (version : CvParam, description : CvParam) =

inherit CvContainer(Terms.protocol,seq [version :> ICvBase;description])

member this.GetVersion() =
Dictionary.item "Version" this (*:?> CvParam*)
member this.SetVersion() =
Dictionary.item "Version" this
member this.Version
with get() =
CvContainer.getSingleAs<CvParam> Protocol.VersionProperty this
|> CvParam.getValueAsString
and set(version : string) =
CvParam.fromValue Terms.version version
|> fun cvp -> CvContainer.setSingle Protocol.VersionProperty cvp this


static member VersionProperty = "Version"

//member this.GetVersion() =
// Dictionary.item "Version" this (*:?> CvParam*)
//member this.SetVersion() =
// Dictionary.item "Version" this



member this.GetDescription() = Dictionary.item "Description" this :?> CvParam


type Process (name : CvParam, protocol : Protocol) =

inherit CvContainer(Terms.processs,seq ["Name",name;"Protocol",protocol])
Expand Down

0 comments on commit edf0b1c

Please sign in to comment.