Add compactor and marshal func
This commit is contained in:
parent
45fa095a15
commit
dedb3faf8c
1 changed files with 19 additions and 0 deletions
19
parser.go
19
parser.go
|
@ -1,6 +1,7 @@
|
||||||
package goap
|
package goap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
|
@ -155,3 +156,21 @@ func FindAttribute[T BaseApChain](object BaseApChain) (T, bool) {
|
||||||
}
|
}
|
||||||
return obj, true
|
return obj, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Compact(chain BaseApChain, ldContext map[string]any) (map[string]any, error) {
|
||||||
|
chainMap := chain.MarshalToMap()
|
||||||
|
proc := ld.NewJsonLdProcessor()
|
||||||
|
options := ld.NewJsonLdOptions("")
|
||||||
|
return proc.Compact(chainMap, ldContext, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Marshal(chain BaseApChain, ldContext map[string]any) ([]byte, error) {
|
||||||
|
chainMap := chain.MarshalToMap()
|
||||||
|
proc := ld.NewJsonLdProcessor()
|
||||||
|
options := ld.NewJsonLdOptions("")
|
||||||
|
compacted, err := proc.Compact(chainMap, ldContext, options)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return json.Marshal(compacted)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue