Skip to content

Commit

Permalink
various fixes for reading new and deprecated ARC RO-Crates
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Mar 4, 2025
1 parent 6cf8105 commit b755341
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 30 deletions.
3 changes: 2 additions & 1 deletion src/ARCtrl/ARC.fs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,8 @@ type ARC(?isa : ArcInvestigation, ?cwl : unit, ?fs : FileSystem.FileSystem) =
|]

static member fromDeprecatedROCrateJsonString (s:string) =
try
try
let s = s.Replace("bio:additionalProperty","sdo:additionalProperty")
let isa = ARCtrl.Json.Decode.fromJsonString ARCtrl.Json.ARC.ROCrate.decoderDeprecated s
ARC(isa = isa)
with
Expand Down
3 changes: 1 addition & 2 deletions src/ARCtrl/Conversion.fs
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,7 @@ module TableTypeExtensions =
///
/// Then each group is converted to a table with this nameroot as sheetname
static member fromProcesses (ps : LDNode list, ?graph : LDGraph, ?context : LDContext) : ArcTables =
ps
|> ProcessConversion.groupProcesses
ProcessConversion.groupProcesses(ps, ?graph = graph, ?context = context)
|> List.map (fun (name,ps) ->
ps
|> List.collect (fun p -> ProcessConversion.processToRows(p,?graph = graph, ?context = context) |> List.ofSeq)
Expand Down
2 changes: 1 addition & 1 deletion src/ARCtrl/ROCrateIO.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ module ARC =
ldnode
|> Dataset.getAbouts
|> Seq.exactlyOne
|> ArcInvestigation.fromROCrateInvestigation
|> fun node -> ArcInvestigation.fromROCrateInvestigation(node, context = Context.initV1_1())
)
2 changes: 1 addition & 1 deletion src/Core/Helper/ORCID.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let orcidPrefix = "http://orcid.org/"

let (|ORCID|_|) input =
match input with
| Regex orcidPattern r -> Some r
| Regex orcidPattern r -> Some r.Value
| _ -> None

let tryGetOrcidURL (orcid : string) =
Expand Down
4 changes: 2 additions & 2 deletions src/ROCrate/Generic/Person.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Person =

static member tryGetAffiliation(p : LDNode, ?graph :LDGraph, ?context : LDContext) =
match p.TryGetPropertyAsSingleNode(Person.affiliation, ?graph = graph, ?context = context) with
| Some n when Organization.validate n -> Some n
| Some n when Organization.validate(n, ?context = context) -> Some n
| _ -> None

static member setAffiliation(p : LDNode, a : LDNode, ?context : LDContext) =
Expand Down Expand Up @@ -98,7 +98,7 @@ type Person =

static member tryGetAddressAsPostalAddress(p : LDNode, ?graph : LDGraph, ?context : LDContext) =
match p.TryGetPropertyAsSingleNode(Person.address, ?graph = graph, ?context = context) with
| Some n when PostalAddress.validate n -> Some n
| Some n when PostalAddress.validate(n, ?context = context) -> Some n
| _ -> None

static member tryGetAddressAsString(p : LDNode, ?context : LDContext) =
Expand Down
4 changes: 2 additions & 2 deletions src/ROCrate/Generic/PropertyValue.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ type PropertyValue =

static member validateParameterValue (pv : LDNode, ?context : LDContext) =
PropertyValue.validate(pv, ?context = context)
&& pv.AdditionalType.Contains("ParameterValue")
&& (pv.AdditionalType.Contains("ParameterValue") || pv.AdditionalType.Contains("ProcessParameterValue"))

static member validateCharacteristicValue (pv : LDNode, ?context : LDContext) =
PropertyValue.validate(pv, ?context = context)
&& pv.AdditionalType.Contains("CharacteristicValue")
&& (pv.AdditionalType.Contains("CharacteristicValue") || pv.AdditionalType.Contains("MaterialAttributeValue"))

static member validateFactorValue (pv : LDNode, ?context : LDContext) =
PropertyValue.validate(pv, ?context = context)
Expand Down
2 changes: 1 addition & 1 deletion src/ROCrate/Generic/ScholarlyArticle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type ScholarlyArticle =

static member tryGetCreativeWorkStatus(s : LDNode, ?graph : LDGraph, ?context : LDContext) =
match s.TryGetPropertyAsSingleNode(ScholarlyArticle.creativeWorkStatus, ?graph = graph, ?context = context) with
| Some cws when DefinedTerm.validate cws -> Some cws
| Some cws when DefinedTerm.validate(cws,?context = context) -> Some cws
| _ -> None

static member setCreativeWorkStatus(s : LDNode, cws : LDNode, ?context : LDContext) =
Expand Down
25 changes: 14 additions & 11 deletions src/ROCrate/LDContext.fs
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,20 @@ type LDContext(?mappings : Dictionary<string,string>, ?baseContexts : ResizeArra
static member fromMappingSeq(mappings : seq<string*string>) =
LDContext(Dictionary.ofSeq mappings)

// Append second context to the first one inplace
static member combine_InPlace (first : LDContext) (second : LDContext) : LDContext =
first.BaseContexts.Add second
first

// Create new context with the the two given contexts as baseContexts
static member combine (first : LDContext) (second : LDContext) : LDContext =
LDContext(baseContexts = ResizeArray([first;second]))

static member tryCombineOptional (first : LDContext option) (second : LDContext option) : LDContext option =
match first,second with
/// Append first context as base context to the second one inplace
static member combine_InPlace (baseContext : LDContext) (specificContext : LDContext) : LDContext =
specificContext.BaseContexts.Add baseContext
specificContext

/// Create new context with the the two given contexts as baseContexts
static member combine (baseContext : LDContext) (specificContext : LDContext) : LDContext =
LDContext(baseContexts = ResizeArray([specificContext;baseContext]))

/// Try to combine two optional contexts
///
/// Create new context with the the two given contexts as baseContexts
static member tryCombineOptional (baseContext : LDContext option) (specificContext : LDContext option) : LDContext option =
match baseContext,specificContext with
| Some f, Some s -> Some (LDContext.combine f s)
| Some f, None -> Some f
| None, Some s -> Some s
Expand Down
12 changes: 5 additions & 7 deletions tests/ARCtrl/ARCtrl.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,19 +1382,17 @@ let tests_RemoveStudy =

let tests_ROCrate =
testList "RO-Crate" [
ftestCase "CanRead_Deprecated" <| fun _ ->
testCase "CanRead_Deprecated" <| fun _ ->
let arc = ARC.fromDeprecatedROCrateJsonString(TestObjects.ROCrate.ArcPrototypeDeprecated.ed123499)
let isa = Expect.wantSome arc.ISA "ARC should contain an ISA part"
let nonDeprecatedARC = ARC.fromROCrateJsonString(TestObjects.ROCrate.ArcPrototype.ed123499)
let nonDeprecatedISA = Expect.wantSome nonDeprecatedARC.ISA "ARC should contain an ISA part"
Expect.equal isa.Identifier nonDeprecatedISA.Identifier "Investigation should have correct identifier"
Expect.equal isa.Title nonDeprecatedISA.Title "Investigation should have correct title"
Expect.equal isa.Description nonDeprecatedISA.Description "Investigation should have correct description"
Expect.sequenceEqual isa.Contacts nonDeprecatedISA.Contacts "Investigation should have correct contacts"
Expect.sequenceEqual isa.Studies nonDeprecatedISA.Studies "Investigation should have correct studies"
Expect.sequenceEqual isa.Assays nonDeprecatedISA.Assays "Investigation should have correct assays"

ftestCase "CanRead" <| fun _ ->
Expect.equal isa.Contacts.[1] nonDeprecatedISA.Contacts.[1] "Investigation should have correct contacts"
Expect.equal isa.Studies.[1] nonDeprecatedISA.Studies.[1] "Investigation should have correct studies"
testCase "CanRead" <| fun _ ->
let arc = ARC.fromROCrateJsonString(TestObjects.ROCrate.ArcPrototype.ed123499)
let isa = Expect.wantSome arc.ISA "ARC should contain an ISA part"
Expect.equal isa.Identifier "ArcPrototype" "Investigation should have correct identifier"
Expand All @@ -1421,7 +1419,7 @@ let tests_ROCrate =
Expect.equal firstRole.NameText "principal investigator" "First contact should have correct role"
/// Studies
Expect.equal isa.StudyCount 2 "ARC should contain 2 studies"
let secondStudy = isa.Studies.[1]
let secondStudy = isa.GetStudy("MaterialPreparation")
let secondStudyTitle = Expect.wantSome secondStudy.Title "Second study should have title"
Expect.equal secondStudyTitle "Prototype for experimental data" "Second study should have correct title"
let secondStudyDescription = Expect.wantSome secondStudy.Description "Second study should have description"
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/TestingUtils/TestingUtils.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<Compile Include="TestObjects.CWL\Outputs.fs" />
<Compile Include="TestObjects.CWL\Inputs.fs" />
<Compile Include="TestObjects.CWL\Requirements.fs" />
<Compile Include="TestObjects.ROCrate\ArcPrototype%40ed123499.fs" />
<Compile Include="TestObjects.ROCrate\ArcPrototype%40ed123499_deprecated.fs" />
<Compile Include="TestObjects.ROCrate\ArcPrototype_ed123499.fs" />
<Compile Include="TestObjects.ROCrate\ArcPrototype_ed123499_deprecated.fs" />
<Compile Include="TestObjects.Json\Study.fs" />
<Compile Include="TestObjects.Json\ROCrate.fs" />
<Content Include="TestObjects.Json\MinimalJson.json" />
Expand Down

0 comments on commit b755341

Please sign in to comment.