-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement stringtable in arctable json compression
- Loading branch information
Showing
7 changed files
with
237 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
namespace rec ARCtrl.ISA.Json | ||
|
||
#if FABLE_COMPILER | ||
open Thoth.Json | ||
#else | ||
open Thoth.Json.Net | ||
#endif | ||
open ARCtrl.ISA | ||
|
||
open ARCtrl.ISA.Aux | ||
|
||
type CellTableMap = System.Collections.Generic.Dictionary<CompositeCell,int> | ||
|
||
type CellTableArray = array<CompositeCell> | ||
|
||
module CellTable = | ||
|
||
let [<Literal>] CellType = "celltype" | ||
let [<Literal>] CellValues = "values" | ||
|
||
let arrayFromMap (otm : CellTableMap) : CellTableArray= | ||
otm | ||
|> Seq.sortBy (fun kv -> kv.Value) | ||
|> Seq.map (fun kv -> kv.Key) | ||
|> Seq.toArray | ||
|
||
let encoder (stringTable : StringTableMap) (oaTable : OATableMap) (ot: CellTableArray) = | ||
ot | ||
|> Array.map (CompositeCell.compressedEncoder stringTable oaTable) | ||
|> Encode.array | ||
|
||
let decoder (stringTable : StringTableArray) (oaTable : OATableArray) : Decoder<CellTableArray> = | ||
Decode.array (CompositeCell.compressedDecoder stringTable oaTable) | ||
|
||
let encodeCell (otm : CellTableMap) (cc : CompositeCell) = | ||
match Dict.tryFind cc otm with | ||
| Some i -> Encode.int i | ||
| None -> | ||
let i = otm.Count | ||
otm.Add(cc,i) | ||
Encode.int i | ||
|
||
let decodeCell (ot : CellTableArray) : Decoder<CompositeCell> = | ||
fun s o -> | ||
match Decode.int s o with | ||
| Ok i -> Ok ot.[i] | ||
| Error err -> Error err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace rec ARCtrl.ISA.Json | ||
|
||
#if FABLE_COMPILER | ||
open Thoth.Json | ||
#else | ||
open Thoth.Json.Net | ||
#endif | ||
open ARCtrl.ISA | ||
|
||
open ARCtrl.ISA.Aux | ||
|
||
type OATableMap = System.Collections.Generic.Dictionary<OntologyAnnotation,int> | ||
|
||
type OATableArray = array<OntologyAnnotation> | ||
|
||
module OATable = | ||
|
||
let arrayFromMap (otm : OATableMap) : OATableArray= | ||
otm | ||
|> Seq.sortBy (fun kv -> kv.Value) | ||
|> Seq.map (fun kv -> kv.Key) | ||
|> Seq.toArray | ||
|
||
let encoder (stringTable : StringTableMap) (ot: OATableArray) = | ||
ot | ||
|> Array.map (OntologyAnnotation.compressedEncoder stringTable (ConverterOptions())) | ||
|> Encode.array | ||
|
||
let decoder stringTable : Decoder<OATableArray> = | ||
Decode.array (OntologyAnnotation.compressedDecoder stringTable (ConverterOptions())) | ||
|
||
let encodeOA (otm : OATableMap) (oa : OntologyAnnotation) = | ||
match Dict.tryFind oa otm with | ||
| Some i -> Encode.int i | ||
| None -> | ||
let i = otm.Count | ||
otm.Add(oa,i) | ||
Encode.int i | ||
|
||
let decodeOA (ot : OATableArray) : Decoder<OntologyAnnotation> = | ||
fun s o -> | ||
match Decode.int s o with | ||
| Ok i -> Ok ot.[i] | ||
| Error err -> Error err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace rec ARCtrl.ISA.Json | ||
|
||
#if FABLE_COMPILER | ||
open Thoth.Json | ||
#else | ||
open Thoth.Json.Net | ||
#endif | ||
open ARCtrl.ISA | ||
|
||
open ARCtrl.ISA.Aux | ||
|
||
type StringTableMap = System.Collections.Generic.Dictionary<string,int> | ||
|
||
type StringTableArray = array<string> | ||
|
||
module StringTable = | ||
|
||
let arrayFromMap (otm : StringTableMap) : StringTableArray= | ||
otm | ||
|> Seq.sortBy (fun kv -> kv.Value) | ||
|> Seq.map (fun kv -> kv.Key) | ||
|> Seq.toArray | ||
|
||
let encoder (ot: StringTableArray) = | ||
ot | ||
|> Array.map Encode.string | ||
|> Encode.array | ||
|
||
let decoder : Decoder<StringTableArray> = | ||
Decode.array Decode.string | ||
|
||
let encodeString (otm : StringTableMap) (s : obj) = | ||
let s = s :?> string | ||
match Dict.tryFind s otm with | ||
| Some i -> Encode.int i | ||
| None -> | ||
let i = otm.Count | ||
otm.Add(s,i) | ||
Encode.int i | ||
|
||
let decodeString (ot : StringTableArray) : Decoder<string> = | ||
fun s o -> | ||
match Decode.int s o with | ||
| Ok i -> Ok ot.[i] | ||
| Error err -> Error err |