Skip to content

Commit

Permalink
Merge pull request #28 from nfdi4plants/rework-cv
Browse files Browse the repository at this point in the history
Type model and API rework
  • Loading branch information
kMutagene authored Aug 17, 2023
2 parents c6e2072 + 16926d5 commit 04f5158
Show file tree
Hide file tree
Showing 21 changed files with 689 additions and 273 deletions.
6 changes: 3 additions & 3 deletions src/ARCTokenization/Address.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ open ControlledVocabulary

module Address =

let column : CvTerm = "http://purl.obolibrary.org/obo/NCIT_C43379","Column","NCIT"
let column = CvTerm.create(accession = "http://purl.obolibrary.org/obo/NCIT_C43379", name = "Column", ref = "NCIT")

let row : CvTerm = "http://purl.obolibrary.org/obo/NCIT_C43378","Row","NCIT"
let row = CvTerm.create(accession = "http://purl.obolibrary.org/obo/NCIT_C43378", name = "Row", ref = "NCIT")

let worksheet : CvTerm = "http://purl.obolibrary.org/obo/NCIT_C73541","Worksheet","NCIT"
let worksheet = CvTerm.create(accession = "http://purl.obolibrary.org/obo/NCIT_C73541", name = "Worksheet", ref = "NCIT")

//"isa_investigation!A1"

Expand Down
8 changes: 4 additions & 4 deletions src/ARCTokenization/AnnotationTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module AnnotationTable =
let cvPars =
List.map4 (
fun (vl : FsCell) unt tan tsr ->
let valTerm = CvUnit(tan.Value, vl.Value, tsr.Value)
let valTerm = CvUnit.create(accession = tan.Value, name = vl.Value, ref = tsr.Value)
CvParam(d.Value, a.Value, c.Value, WithCvUnitAccession (unt.Value, valTerm))
) dataCellsVal dataCellsUnt dataCellsTan dataCellsTsr
yield! cvPars
Expand All @@ -166,7 +166,7 @@ module AnnotationTable =
(dataCellsVal, dataCellsTsr, dataCellsTan)
|||> List.map3 (
fun vl tsr tan ->
let valTerm = CvTerm(tan.Value, vl.Value, tsr.Value)
let valTerm = CvTerm.create(accession = tan.Value, name = vl.Value, ref = tsr.Value)
CvParam(c.Value, a.Value, b.Value, CvValue valTerm)
)
yield! cvPars
Expand All @@ -182,7 +182,7 @@ module AnnotationTable =
(dataCellsVal, dataCellsTsr)
||> List.map2 (
fun vl tsr ->
let valTerm = CvTerm("(n/a)", vl.Value, tsr.Value)
let valTerm = CvTerm.create (accession = "(n/a)", name = vl.Value, ref = tsr.Value)
CvParam("n/a", a.Value, b.Value, CvValue valTerm)
)
yield! cvPars
Expand All @@ -195,7 +195,7 @@ module AnnotationTable =
(dataCellsTsr, dataCellsTan)
||> List.map2 (
fun tsr tan ->
let valTerm = CvTerm(tan.Value, "n/a", tsr.Value)
let valTerm = CvTerm.create(accession = tan.Value, name = "n/a", ref = tsr.Value)
CvParam(b.Value, "(n/a)", a.Value, CvValue valTerm)
)
yield! cvPars
Expand Down
2 changes: 1 addition & 1 deletion src/ARCTokenization/MetadataSheet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module MetadataSheet =

let (|Term|_|) (terms : CvTerm list) (key : string) : CvTerm Option =
terms
|> List.tryFind (fun (term) -> CvTerm.getName term = key)
|> List.tryFind (fun (term) -> term.Name = key)

let (|UnMatchable|) (key : string) : string =
key
Expand Down
8 changes: 4 additions & 4 deletions src/ARCTokenization/Terms.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module InvestigationMetadata =

let cvTerms =
ontology.Terms
|> List.map (fun t -> CvTerm(t.Id,t.Name,"INVMSO"))
|> List.map (fun t -> CvTerm.create(accession = t.Id, name = t.Name, ref = "INVMSO"))

module StudyMetadata =

Expand All @@ -34,7 +34,7 @@ module StudyMetadata =

let cvTerms =
ontology.Terms
|> List.map (fun t -> CvTerm(t.Id,t.Name,"STDMSO"))
|> List.map (fun t -> CvTerm.create(accession = t.Id, name = t.Name, ref ="STDMSO"))

module AssayMetadata =

Expand All @@ -44,8 +44,8 @@ module AssayMetadata =

let cvTerms =
ontology.Terms
|> List.map (fun t -> CvTerm(t.Id,t.Name,"ASSMSO"))
|> List.map (fun t -> CvTerm.create(accession = t.Id, name = t.Name, ref ="ASSMSO"))

module StructuralTerms =

let metadataSectionKey = CvTerm("AGMO:00000001","Metadata Section Key","AGMO")
let metadataSectionKey = CvTerm.create(accession = "AGMO:00000001", name = "Metadata Section Key", ref = "AGMO")
6 changes: 3 additions & 3 deletions src/ControlledVocabulary/CvAttributeCollection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type CvAttributeCollection(attributes : IDictionary<string,IParam>) =

/// Retrieves an IParam attribute by its term, if it exists, else returns None
member this.TryGetAttribute (term : CvTerm) =
Dictionary.tryFind (CvTerm.getName term) this
Dictionary.tryFind term.Name this
|> Option.bind (fun param ->
if CvBase.equalsTerm term param then
Some param
Expand All @@ -51,15 +51,15 @@ type CvAttributeCollection(attributes : IDictionary<string,IParam>) =

/// Retrieves an IParam attribute by its term, if it exists, else fails
member this.GetAttribute (term : CvTerm) =
Dictionary.item (CvTerm.getName term) this
Dictionary.item term.Name this

/// Returns true, if an attribute with the given name exists in the collection
member this.ContainsAttribute (name : string) =
Dictionary.containsKey name this

/// Returns true, if an attribute with the given term exists in the collection
member this.ContainsAttribute (term : CvTerm) =
match Dictionary.tryFind (CvTerm.getName term) this with
match Dictionary.tryFind term.Name this with
| Some param when CvBase.equalsTerm term param -> true
| _ -> false

Expand Down
28 changes: 14 additions & 14 deletions src/ControlledVocabulary/CvContainer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ module internal Dictionary =
/// Represents a collection of structured properties, annotated with a controlled vocabulary term.
type CvContainer (
cvAccession : string,
cvName : string,
cvRefUri : string,
attributes : IDictionary<string,IParam>,
properties : IDictionary<string,seq<ICvBase>>
cvName : string,
cvRef : string,
attributes : IDictionary<string,IParam>,
properties : IDictionary<string,seq<ICvBase>>
) =

inherit CvAttributeCollection(attributes)

interface ICvBase with
member this.ID = cvAccession
member this.Name = cvName
member this.RefUri = cvRefUri
member this.Accession = cvAccession
member this.Name = cvName
member this.RefUri = cvRef
member this.HasAttributes
with get() = this.Attributes |> Seq.isEmpty |> not

Expand All @@ -37,8 +37,8 @@ type CvContainer (
CvContainer(cvAccession, cvName, cvRefUri, Seq.empty)


new ((id,name,ref) : CvTerm, attributes : IDictionary<string,IParam>) =
CvContainer(id,name,ref, attributes, Dictionary<string, ICvBase seq>())
new (term : CvTerm, attributes : IDictionary<string,IParam>) =
CvContainer(term.Accession, term.Name, term.RefUri, attributes, Dictionary<string, ICvBase seq>())
new (term : CvTerm,attributes : seq<IParam>) =
let dict = CvAttributeCollection(attributes)
CvContainer(term, dict)
Expand Down Expand Up @@ -79,7 +79,7 @@ type CvContainer (
/// Fails if the propertyName cannot be found.
member this.GetManyParams propertyName =
Dictionary.item propertyName this.Properties
|> Seq.choose Param.tryParam
|> Seq.choose CvBase.tryParam

/// Retrieves child with the given name of the CvContainer.
///
Expand Down Expand Up @@ -109,7 +109,7 @@ type CvContainer (
/// Fails if there is not exactly one child with the given name or if the propertyName cannot be found.
member this.GetSingleParam propertyName =
Dictionary.item propertyName this.Properties
|> Seq.choose Param.tryParam
|> Seq.choose CvBase.tryParam
|> Seq.exactlyOne


Expand Down Expand Up @@ -146,7 +146,7 @@ type CvContainer (
Dictionary.tryFind propertyName this.Properties
|> Option.bind (fun many ->
many
|> Seq.choose Param.tryParam
|> Seq.choose CvBase.tryParam
|> fun items -> if Seq.isEmpty items then None else Some items
)

Expand Down Expand Up @@ -176,7 +176,7 @@ type CvContainer (
/// Returns None if there is not exactly one child with the given name or if the propertyName cannot be found.
member this.TryGetSingleParam propertyName =
Dictionary.tryFind propertyName this.Properties
|> Option.bind (Seq.choose Param.tryParam >> Seq.tryExactlyOne)
|> Option.bind (Seq.choose CvBase.tryParam >> Seq.tryExactlyOne)



Expand Down Expand Up @@ -330,4 +330,4 @@ type CvContainer (
Dictionary.addOrUpdateInPlace value.Name (Seq.singleton value) cvContainer.Properties

override this.ToString() =
$"CvContainer: {(this :> ICvBase).Name}\n\tID: {(this :> ICvBase).ID}\n\tRefUri: {(this :> ICvBase).RefUri}\n\tProperties: {this.Properties.Keys |> Seq.toList}"
$"CvContainer: {(this :> ICvBase).Name}\n\tID: {(this :> ICvBase).Accession}\n\tRefUri: {(this :> ICvBase).RefUri}\n\tProperties: {this.Properties.Keys |> Seq.toList}"
12 changes: 6 additions & 6 deletions src/ControlledVocabulary/CvObject.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
open System.Collections.Generic

/// Represents a generic object, annotated with a controlled vocabulary term
type CvObject<'T>(cvAccession : string, cvName : string, cvRefUri : string, object : 'T, attributes : Dictionary<string,IParam>) =
type CvObject<'T>(cvAccession : string, cvName : string, cvRef : string, object : 'T, attributes : Dictionary<string,IParam>) =

inherit CvAttributeCollection(attributes)

interface ICvBase with
member this.ID = cvAccession
member this.Name = cvName
member this.RefUri = cvRefUri
member this.Accession = cvAccession
member this.Name = cvName
member this.RefUri = cvRef
member this.HasAttributes
with get() = this.Attributes |> Seq.isEmpty |> not

new ((id,name,ref) : CvTerm,object : 'T, attributes) = CvObject (id,name,ref,object,attributes)
new (term: CvTerm, object : 'T, attributes) = CvObject (term.Accession, term.Name, term.RefUri, object, attributes)

member this.Object = object

override this.ToString() =
$"Name: {(this :> ICvBase).Name}\n\tID: {(this :> ICvBase).ID}\n\tRefUri: {(this :> ICvBase).RefUri}"
$"Name: {(this :> ICvBase).Name}\n\tID: {(this :> ICvBase).Accession}\n\tRefUri: {(this :> ICvBase).RefUri}"
Loading

0 comments on commit 04f5158

Please sign in to comment.