Skip to content

Commit

Permalink
merge json-ld changes into thoth.json update changes and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Feb 29, 2024
2 parents 87ab15d + 4f77082 commit 58b3d5a
Show file tree
Hide file tree
Showing 52 changed files with 9,603 additions and 356 deletions.
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"pretestui": "dotnet fable src/ARCtrl -o tests/UI/ARCtrl ",
"testui": "cd tests/UI & npx cypress run --component ",
"testpy": "",
"postinstall": "cd src/ISA & npm install",
"postinstall": "cd src/ISA && npm install",
"devui": "cd tests/UI & npx vite"
},
"author": "Heinrich Lukas Weil <[email protected]> (https://github.com/HLWeil)",
Expand All @@ -33,7 +33,8 @@
"exceljs": "^4.3.0",
"fable-library": "^1.1.1",
"fsspreadsheet": "^4.0.0-alpha2",
"isomorphic-fetch": "^3.0.0"
"isomorphic-fetch": "^3.0.0",
"jsonschema": "^1.4.1"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.4.1",
Expand Down
23 changes: 23 additions & 0 deletions src/ISA/ISA.Json/ARCtrl.ISA.Json.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@
<Compile Include="Validation/ValidationResult.fs" />
<Compile Include="Validation/Fable.fs" />
<Compile Include="Validation/JsonSchemaValidation.fs" />
<Compile Include="context/ro-crate/isa_assay_context.fs" />
<Compile Include="context/ro-crate/isa_comment_context.fs" />
<Compile Include="context/ro-crate/isa_component_context.fs" />
<Compile Include="context/ro-crate/isa_data_context.fs" />
<Compile Include="context/ro-crate/isa_factor_context.fs" />
<Compile Include="context/ro-crate/isa_factor_value_context.fs" />
<Compile Include="context/ro-crate/isa_investigation_context.fs" />
<Compile Include="context/ro-crate/isa_material_attribute_context.fs" />
<Compile Include="context/ro-crate/isa_material_attribute_value_context.fs" />
<Compile Include="context/ro-crate/isa_material_context.fs" />
<Compile Include="context/ro-crate/isa_ontology_annotation_context.fs" />
<Compile Include="context/ro-crate/isa_ontology_source_reference_context.fs" />
<Compile Include="context/ro-crate/isa_organization_context.fs" />
<Compile Include="context/ro-crate/isa_person_context.fs" />
<Compile Include="context/ro-crate/isa_process_context.fs" />
<Compile Include="context/ro-crate/isa_process_parameter_value_context.fs" />
<Compile Include="context/ro-crate/isa_protocol_context.fs" />
<Compile Include="context/ro-crate/isa_protocol_parameter_context.fs" />
<Compile Include="context/ro-crate/isa_publication_context.fs" />
<Compile Include="context/ro-crate/isa_sample_context.fs" />
<Compile Include="context/ro-crate/isa_source_context.fs" />
<Compile Include="context/ro-crate/isa_study_context.fs" />
<Compile Include="context/ro-crate/rocrate_context.fs" />
<Compile Include="ConverterOptions.fs" />
<Compile Include="Decode.fs" />
<Compile Include="GEncode.fs" />
Expand Down
10 changes: 7 additions & 3 deletions src/ISA/ISA.Json/ArcTypes/ArcAssay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,20 @@ module ArcAssay =


/// exports in json-ld format
let toStringLD (a:ArcAssay) =
Assay.encoder (ConverterOptions(SetID=true,IncludeType=true)) (a.ToAssay())
let toJsonldString (a:ArcAssay) =
Assay.encoder (ConverterOptions(SetID=true,IncludeType=true)) None (a.ToAssay())
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:ArcAssay) =
Assay.encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) None (a.ToAssay())
|> GEncode.toJsonString 2

let fromJsonString (s:string) =
GDecode.fromJsonString (Assay.decoder (ConverterOptions())) s
|> ArcAssay.fromAssay

let toJsonString (a:ArcAssay) =
Assay.encoder (ConverterOptions()) (a.ToAssay())
Assay.encoder (ConverterOptions()) None (a.ToAssay())
|> GEncode.toJsonString 2

let toArcJsonString (a:ArcAssay) : string =
Expand Down
6 changes: 5 additions & 1 deletion src/ISA/ISA.Json/ArcTypes/ArcInvestigation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ module ArcInvestigation =
)

/// exports in json-ld format
let toStringLD (a:ArcInvestigation) =
let toJsonldString (a:ArcInvestigation) =
Investigation.encoder (ConverterOptions(SetID=true,IncludeType=true)) (a.ToInvestigation())
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:ArcInvestigation) =
Investigation.encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) (a.ToInvestigation())
|> GEncode.toJsonString 2

let fromJsonString (s:string) =
GDecode.fromJsonString (Investigation.decoder (ConverterOptions())) s
|> ArcInvestigation.fromInvestigation
Expand Down
6 changes: 5 additions & 1 deletion src/ISA/ISA.Json/ArcTypes/ArcStudy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,14 @@ module ArcStudy =


/// exports in json-ld format
let toStringLD (a:ArcStudy) (assays: ResizeArray<ArcAssay>) =
let toJsonldString (a:ArcStudy) (assays: ResizeArray<ArcAssay>) =
Study.encoder (ConverterOptions(SetID=true,IncludeType=true)) (a.ToStudy(assays))
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:ArcStudy) (assays: ResizeArray<ArcAssay>) =
Study.encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) (a.ToStudy(assays))
|> GEncode.toJsonString 2

let fromJsonString (s:string) =
GDecode.fromJsonString (Study.decoder (ConverterOptions())) s
|> ArcStudy.fromStudy
Expand Down
48 changes: 36 additions & 12 deletions src/ISA/ISA.Json/Assay.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,49 @@ module Assay =
match a.ID with
| Some id -> URI.toString id
| None -> match a.FileName with
| Some n -> n
| Some n -> n.Replace(" ","_").Remove(0,1 + (max (n.LastIndexOf('/')) (n.LastIndexOf('\\'))))
| None -> "#EmptyAssay"

let encoder (options : ConverterOptions) (oa : Assay) =
let encoder (options : ConverterOptions) (studyName:string Option) (oa : Assay) =
let assayName =
try
match (oa).FileName with
| Some fn -> Some (Identifier.Assay.identifierFromFileName fn)
| None -> None
with
| Failure(msg) -> None
let a = ["Assay";"ArcAssay"]
[
if options.SetID then "@id", Encode.string (oa |> genID)
else GEncode.tryInclude "@id" Encode.string (oa.ID)
if options.IncludeType then "@type", Encode.string "Assay"
if options.SetID then
"@id", Encode.string (oa |> genID)
else
GEncode.tryInclude "@id" Encode.string (oa.ID)
if options.IncludeType then
"@type", (Encode.list [ GEncode.toJsonString "Assay"; GEncode.toJsonString "ArcAssay"])
GEncode.tryInclude "filename" Encode.string (oa.FileName)
GEncode.tryInclude "measurementType" (OntologyAnnotation.encoder options) (oa.MeasurementType)
GEncode.tryInclude "technologyType" (OntologyAnnotation.encoder options) (oa.TechnologyType)
GEncode.tryInclude "technologyPlatform" Encode.string (oa.TechnologyPlatform)
GEncode.tryIncludeList "dataFiles" (Data.encoder options) (oa.DataFiles)
GEncode.tryInclude "materials" (AssayMaterials.encoder options) (oa.Materials)
if options.IsRoCrate then
match oa.Materials with
| Some m ->
GEncode.tryIncludeList "samples" (Sample.encoder options) m.Samples
GEncode.tryIncludeList "materials" (Material.encoder options) m.OtherMaterials
| None -> ()
if not options.IsRoCrate then
GEncode.tryInclude "materials" (AssayMaterials.encoder options) oa.Materials
GEncode.tryIncludeList "characteristicCategories" (MaterialAttribute.encoder options) (oa.CharacteristicCategories)
GEncode.tryIncludeList "unitCategories" (OntologyAnnotation.encoder options) (oa.UnitCategories)
GEncode.tryIncludeList "processSequence" (Process.encoder options) (oa.ProcessSequence)
GEncode.tryIncludeList "processSequence" (Process.encoder assayName options) (oa.ProcessSequence)
GEncode.tryIncludeList "comments" (Comment.encoder options) (oa.Comments)
if options.IncludeContext then
"@context", ROCrateContext.Assay.context_jsonvalue
]
|> GEncode.choose
|> Encode.object

let allowedFields = ["@id";"filename";"measurementType";"technologyType";"technologyPlatform";"dataFiles";"materials";"characteristicCategories";"unitCategories";"processSequence";"comments";"@type"]
let allowedFields = ["@id";"filename";"measurementType";"technologyType";"technologyPlatform";"dataFiles";"materials";"characteristicCategories";"unitCategories";"processSequence";"comments";"@type"; "@context"]

let decoder (options : ConverterOptions) : Decoder<Assay> =
GDecode.object allowedFields (fun get ->
Expand All @@ -76,17 +96,21 @@ module Assay =
GDecode.fromJsonString (decoder (ConverterOptions())) s

let toJsonString (p:Assay) =
encoder (ConverterOptions()) p
encoder (ConverterOptions()) None p
|> GEncode.toJsonString 2

/// exports in json-ld format
let toStringLD (a:Assay) =
encoder (ConverterOptions(SetID=true,IncludeType=true)) a
let toJsonldString (a:Assay) =
encoder (ConverterOptions(SetID=true,IncludeType=true)) None a
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:Assay) =
encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) None a
|> GEncode.toJsonString 2

//let fromFile (path : string) =
// File.ReadAllText path
// |> fromString

//let toFile (path : string) (p:Assay) =
// File.WriteAllText(path,toString p)
// File.WriteAllText(path,toString p)
19 changes: 14 additions & 5 deletions src/ISA/ISA.Json/Comment.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ module Comment =

let encoder (options : ConverterOptions) (comment : Comment) =
[
if options.SetID then "@id", Encode.string (comment |> genID)
else GEncode.tryInclude "@id" Encode.string (comment.ID)
if options.IncludeType then "@type", Encode.string "Comment"
if options.SetID then "@id",
Encode.string (comment |> genID)
else
GEncode.tryInclude "@id" Encode.string (comment.ID)
if options.IncludeType then
"@type", Encode.string "Comment"
GEncode.tryInclude "name" Encode.string (comment.Name)
GEncode.tryInclude "value" Encode.string (comment.Value)
if options.IncludeContext then
"@context", ROCrateContext.Comment.context_jsonvalue
]
|> GEncode.choose
|> Encode.object
Expand All @@ -47,13 +52,17 @@ module Comment =
|> GEncode.toJsonString 2

/// exports in json-ld format
let toStringLD (c:Comment) =
let toJsonldString (c:Comment) =
encoder (ConverterOptions(SetID=true,IncludeType=true)) c
|> GEncode.toJsonString 2

let toJsonldStringWithContext (a:Comment) =
encoder (ConverterOptions(SetID=true,IncludeType=true,IncludeContext=true)) a
|> GEncode.toJsonString 2

//let fromFile (path : string) =
// File.ReadAllText path
// |> fromString

//let toFile (path : string) (c:Comment) =
// File.WriteAllText(path,toString c)
// File.WriteAllText(path,toString c)
16 changes: 10 additions & 6 deletions src/ISA/ISA.Json/ConverterOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ type ConverterOptions() =

let mutable setID = false
let mutable includeType = false
let mutable includeContext = false
let mutable isRoCrate = false

member this.SetID
with get() = setID
and set(setId) = setID <- setId
member this.IncludeType
with get() = includeType
and set(iT) = includeType <- iT
member this.SetID with get() = setID
and set(setId) = setID <- setId
member this.IncludeType with get() = includeType
and set(iT) = includeType <- iT
member this.IncludeContext with get() = includeContext
and set(iC) = includeContext <- iC
member this.IsRoCrate with get() = isRoCrate
and set(iR) = isRoCrate <- iR
Loading

0 comments on commit 58b3d5a

Please sign in to comment.