Skip to content

Commit

Permalink
restructure library
Browse files Browse the repository at this point in the history
extend CvParam
replace CvDoc by CvContainer
  • Loading branch information
HLWeil committed Apr 19, 2023
1 parent 30b489a commit c567c64
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 82 deletions.
8 changes: 4 additions & 4 deletions networkDepiction.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open FsSpreadsheet
open FsSpreadsheet.ExcelIO
open FsSpreadsheet.DSL
open ArcGraphModel
open ArcGraphModel.Param
open ArcGraphModel

open System

Expand Down Expand Up @@ -152,6 +152,6 @@ x
// val network: ArcGraph
// val it: int = 18169
// val it: int = 404467
network.GetVertices()
network.GetLabel("5cec766a-860b-47de-a197-ab41d69c423d")
network.GetInEdges("5cec766a-860b-47de-a197-ab41d69c423d")
//network.GetVertices()
//network.GetLabel("5cec766a-860b-47de-a197-ab41d69c423d")
//network.GetInEdges("5cec766a-860b-47de-a197-ab41d69c423d")
13 changes: 13 additions & 0 deletions src/ArcGraphModel/ArcGraphModel.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="CvTokens\CvTerm.fs" />
<Compile Include="CvTokens\ParamValue.fs" />
<Compile Include="CvTokens\ICvBase.fs" />
<Compile Include="CvTokens\IParamBase.fs" />
<Compile Include="CvTokens\CvParam.fs" />
<Compile Include="CvTokens\UserParam.fs" />
<Compile Include="CvTokens\CvObject.fs" />
<Compile Include="CvTokens\CvContainer.fs" />
<Compile Include="FGLAux.fs" />
<Compile Include="ArcType.fs" />
<Compile Include="TableTransform.fs" />
</ItemGroup>
Expand All @@ -16,4 +25,8 @@
<PackageReference Include="FsSpreadsheet" Version="1.2.0-preview" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.7" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions src/ArcGraphModel/CvTokens/CvContainer.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace ArcGraphModel

open System.Collections.Generic
open FSharpAux

/// Represents a collection of structured properties, annotated with a controlled vocabulary term
type CvContainer (cvAccession:string,cvName:string,cvRefUri:string,properties : IDictionary<string,ICvBase seq>) =

inherit Dictionary<string,ICvBase seq>(properties)

interface ICvBase with
member this.ID = cvAccession
member this.Name = cvName
member this.RefUri = cvRefUri

new ((id,name,ref) : CvTerm,properties : IDictionary<string,ICvBase seq>) =
CvContainer(id,name,ref,properties)

new (term : CvTerm,items : seq<ICvBase>) =
let properties : IDictionary<string,ICvBase seq> =
items
|> Seq.groupBy (fun v -> v.Name)
|> Dictionary.ofSeq
CvContainer(term,properties)

new (term : CvTerm) = CvContainer (term,Seq.empty)
15 changes: 15 additions & 0 deletions src/ArcGraphModel/CvTokens/CvObject.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace ArcGraphModel

/// Represents a generic object, annotated with a controlled vocabulary term
type CvObject<'T>(cvAccession : string, cvName : string, cvRefUri : string, object : 'T) =
interface ICvBase with
member this.ID = cvAccession
member this.Name = cvName
member this.RefUri = cvRefUri

new ((id,name,ref) : CvTerm,object : 'T) = CvObject (id,name,ref,object)

member this.Object = object

override this.ToString() =
$"Name: {(this :> ICvBase).Name}\n\tID: {(this :> ICvBase).ID}\n\tRefUri: {(this :> ICvBase).RefUri}"
45 changes: 45 additions & 0 deletions src/ArcGraphModel/CvTokens/CvParam.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace ArcGraphModel

open System
open System.Collections.Generic
open FSharpAux

/// Represents a structured value, annotated with a controlled vocabulary term
///
/// Qualifiers can be used to further describe the CvParam
type CvParam(cvAccession : string, cvName : string, cvRefUri : string, paramValue : ParamValue, qualifiers : IDictionary<string,CvParam>) =

inherit Dictionary<string,CvParam>(qualifiers)

interface ICvBase with
member this.ID = cvAccession
member this.Name = cvName
member this.RefUri = cvRefUri
interface IParamBase with
member this.Value = paramValue

new (id,name,ref,pv,qualifiers : seq<CvParam>) =
let dict =
qualifiers
|> Seq.map (fun cvp -> (cvp :> ICvBase).Name, cvp)
|> Dictionary.ofSeq
CvParam (id,name,ref,pv,dict)
new (id,name,ref,pv) =
CvParam (id,name,ref,pv,Seq.empty)

new ((id,name,ref) : CvTerm,pv,qualifiers : seq<CvParam>) =
CvParam (id,name,ref,pv,qualifiers)
new (cvTerm,pv : ParamValue) =
CvParam (cvTerm,pv,Seq.empty)

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

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

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

override this.ToString() =
$"Name: {(this :> ICvBase).Name}\n\tID: {(this :> ICvBase).ID}\n\tRefUri: {(this :> ICvBase).RefUri}\n\tValue: {(this :> IParamBase).Value}"
12 changes: 12 additions & 0 deletions src/ArcGraphModel/CvTokens/CvTerm.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace ArcGraphModel

/// Represents a term from a controlled vocabulary (Cv)
/// in the form of: id|accession * name|value * refUri
// ?Maybe [<Struct>]
//[<Struct>]
type CvTerm = string * string * string

/// Represents a unit term from the unit ontology
/// in the form of: id|accession * name * refUri
// ?Maybe [<Struct>]
type CvUnit = string * string * string
25 changes: 25 additions & 0 deletions src/ArcGraphModel/CvTokens/ICvBase.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace ArcGraphModel


/// Interface ensures the propterties necessary for CvTerm
type ICvBase =
abstract member ID : string
abstract member Name : string
abstract member RefUri : string
// here or as node/edge abstraction
// abstract member DataType : ModelDataType
// abstract member Adress : Adress / Location / Position

//override this.ToString() =
// $"Name: {this.Name}\nID: {this.ID}\nRefUri: {this.RefUri}"

module CvBase =

let getCvAccession (param : #ICvBase) =
param.ID

let getCvName (param : #ICvBase) =
param.Name

let getCvRef (param : #ICvBase) =
param.RefUri
60 changes: 60 additions & 0 deletions src/ArcGraphModel/CvTokens/IParamBase.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace ArcGraphModel

open System

/// Interface ensures the value as ParamValue<'T>
type IParamBase =
abstract member Value : ParamValue


module ParamBase =

let getValue (param : #IParamBase) =
match param.Value with
| Value v -> v
| CvValue (_,v,_) -> v
| WithCvUnitAccession (v,_) -> v

let tryGetValueAccession (param : #IParamBase) =
match param.Value with
| CvValue (a,_,_) -> Some a
| Value _ -> None // mere Value has no accession number
| WithCvUnitAccession _ -> None // use tryGetCvUnitAccession instead
//| WithCvUnitAccession (_,(a,_,_)) -> Some a

let tryGetValueRef (param : #IParamBase) =
match param.Value with
| CvValue (_,_,r) -> Some r
| Value _ -> None // mere Value has no ref
| WithCvUnitAccession _ -> None // use tryGetCvUnitRef instead

let tryGetCvUnit (param : #IParamBase) : CvUnit option =
match param.Value with
| Value _ -> None
| CvValue _ -> None
| WithCvUnitAccession (_,u) -> Some u

let tryGetCvUnitValue (param : #IParamBase) : #IConvertible option =
match param.Value with
| Value _ -> None
| CvValue _ -> None
| WithCvUnitAccession (v,_) -> Some v

let tryGetCvUnitName (param : #IParamBase) =
match param.Value with
| Value _ -> None
| CvValue _ -> None
| WithCvUnitAccession (_,(_,n,_)) -> Some n

let tryGetCvUnitAccession (param : #IParamBase) =
match param.Value with
| Value _ -> None
| CvValue _ -> None
| WithCvUnitAccession (_,(a,_,_)) -> Some a

let tryGetCvUnitRef (param : #IParamBase) =
match param.Value with
| Value _ -> None
| CvValue _ -> None
| WithCvUnitAccession (_,(_,_,r)) -> Some r

25 changes: 25 additions & 0 deletions src/ArcGraphModel/CvTokens/ParamValue.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace ArcGraphModel

open System

/// Represent the different cases of a parameter, which is either a simple value,
/// a CvTerm or a simple value with CvUnit
// ?Maybe [<Struct>]
type ParamValue =
| Value of v: IConvertible
// id|accession * name|value * ref
| CvValue of cv: CvTerm
// value * CvUnit
| WithCvUnitAccession of cvu : IConvertible * CvUnit

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

static member tryGetUnit (param:ParamValue) : CvUnit option =
match param with
| Value _ -> None
| CvValue _ -> None
| WithCvUnitAccession (_,u) -> Some u
13 changes: 13 additions & 0 deletions src/ArcGraphModel/CvTokens/UserParam.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace ArcGraphModel

/// Represents a structured value, annotated by a user defined name
type UserParam(name : string, paramValue : ParamValue) =
interface ICvBase with
member this.ID = name
member this.Name = name
member this.RefUri = "UserTerm"
interface IParamBase with
member this.Value = paramValue

override this.ToString() =
$"Name: {(this :> ICvBase).Name}\n\tID: {(this :> ICvBase).ID}\n\tRefUri: {(this :> ICvBase).RefUri}\n\tValue: {(this :> IParamBase).Value}"
9 changes: 4 additions & 5 deletions src/ArcGraphModel/TableTransform.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

open FSharpAux
open FsSpreadsheet
open Param
open FSharp.FGL
open FSharp.FGL.ArrayAdjacencyGraph

Expand Down Expand Up @@ -200,10 +199,10 @@ module TableTransform =
/// <summary>
/// Takes a CvParam and returns the type of Node it contains.
/// </summary>
let getNodeType (cvPar : #IParamBase<'a>) =
let getNodeType (cvPar : #IParamBase) =
//let castedCvPar = cvPar :?> CvParam<string> // debatable approach
//let v = Param.getCvName castedCvPar
let v = Param.getCvName cvPar
let v = CvBase.getCvName cvPar
match v with
| "Source Name" -> Source
| "Sample Name"
Expand Down Expand Up @@ -241,8 +240,8 @@ module TableTransform =
: ((LVertex<'a,'b> list) * (LVertex<'a,'b> list) * (LEdge<'a,'b> list list)) =
match inputSources, inputSinks, inputEdges with
| hSrc :: tSrc, hSnk :: tSnk, hEdg :: tEdg ->
let sourceValue = Param.getValue hSrc
let sinkValue = Param.getValue hSnk
let sourceValue = ParamBase.getValue hSrc
let sinkValue = ParamBase.getValue hSnk
let filledSourceVertices = (sourceValue, hSrc) :: sourceVertices
let filledSinkVertices = (sinkValue, hSnk) :: sinkVertices
let filledConnEdges = (hEdg |> List.map (fun e -> sourceValue, sinkValue, e)) :: connectedEdges
Expand Down
2 changes: 1 addition & 1 deletion terms.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ open FSharp.FGL.ArrayAdjacencyGraph
#I @"src\ArcGraphModel\bin\Release\net6.0"
#r "ArcGraphModel.dll"

open ArcGraphModel.Param
open ArcGraphModel

module Terms =
let protocol : CvTerm = "ARC_00000150", "Protocol", ""
Expand Down
4 changes: 4 additions & 0 deletions tests/ArcGraphModel.Tests/ArcGraphModel.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@
<ProjectReference Include="..\..\src\ArcGraphModel\ArcGraphModel.fsproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="6.0.7" />
</ItemGroup>

</Project>
11 changes: 6 additions & 5 deletions tests/ArcGraphModel.Tests/ParamTests.fs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
namespace ArcGraphModel.Tests

open Xunit
open ArcGraphModel.Param

open ArcGraphModel
open ParamBase
open CvBase

module Param =

let testParamValueValue = ParamValue.Value "ParamValue.Value"
let testCvParam1 = CvParam("CvParam_TAN_1", "CvParam_Name_1", "CvParam_TSR_1", testParamValueValue)
let testCvTerm = CvTerm("CvTerm_TAN", "CvTerm_Name", "CvTerm_TSR")
let testParamValueCvValue = ParamValue.CvValue testCvTerm
let testCvParam2 : CvParam<string> = CvParam("CvParam_TAN_2", "CvParam_Name_2", "CvParam_TSR_3", testParamValueCvValue)
let testCvParam2 : CvParam = CvParam("CvParam_TAN_2", "CvParam_Name_2", "CvParam_TSR_3", testParamValueCvValue)
let testCvUnit = CvUnit("CvUnit_TAN", "CvUnit_Name", "CvUnit_TSR")
let testParamValueCvUnit = ParamValue.WithCvUnitAccession ("CvUnit_Value", testCvUnit)
let testCvParam3 = CvParam("CvParam_TAN_3", "CvParam_Name_3", "CvParam_TSR_3", testParamValueCvUnit)
Expand Down Expand Up @@ -44,7 +45,7 @@ module Param =

[<Fact>]
let ``returns correct Value`` () =
let retrievedValue = getValue testCvParam1
let retrievedValue = getValue testCvParam1 :?> string
Assert.Equal("ParamValue.Value", retrievedValue)


Expand Down Expand Up @@ -108,7 +109,7 @@ module Param =

[<Fact>]
let ``returns correct CvUnit Value`` () =
Assert.Equal("CvUnit_Value", retrievedCvUnitValue.Value)
Assert.Equal("CvUnit_Value", retrievedCvUnitValue.Value :?> string)


module tryGetCvUnitName =
Expand Down
Loading

0 comments on commit c567c64

Please sign in to comment.