module OWL2.MedusaToJson (medusaToJson, medusaToJsonString) where
import OWL2.Medusa
import Common.Json
import Common.IRI
import qualified Data.Set as Set
medusaToJsonString :: Medusa -> String
medusaToJsonString :: Medusa -> String
medusaToJsonString = Json -> String
ppJson (Json -> String) -> (Medusa -> Json) -> Medusa -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Medusa -> Json
medusaToJson
medusaToJson :: Medusa -> Json
medusaToJson :: Medusa -> Json
medusaToJson m :: Medusa
m = [JPair] -> Json
JObject [("Definitions",Json
defs),("Relations",Json
rels)]
where inds :: [(IRI, IRI)]
inds = Set (IRI, IRI) -> [(IRI, IRI)]
forall a. Set a -> [a]
Set.toList (Set (IRI, IRI) -> [(IRI, IRI)]) -> Set (IRI, IRI) -> [(IRI, IRI)]
forall a b. (a -> b) -> a -> b
$ Medusa -> Set (IRI, IRI)
indivs Medusa
m
mrels :: [(IRI, IRI, IRI, IRI)]
mrels = Set (IRI, IRI, IRI, IRI) -> [(IRI, IRI, IRI, IRI)]
forall a. Set a -> [a]
Set.toList (Set (IRI, IRI, IRI, IRI) -> [(IRI, IRI, IRI, IRI)])
-> Set (IRI, IRI, IRI, IRI) -> [(IRI, IRI, IRI, IRI)]
forall a b. (a -> b) -> a -> b
$ Medusa -> Set (IRI, IRI, IRI, IRI)
relations Medusa
m
defs :: Json
defs = [Json] -> Json
JArray ([Json] -> Json) -> [Json] -> Json
forall a b. (a -> b) -> a -> b
$ ((IRI, IRI) -> Json) -> [(IRI, IRI)] -> [Json]
forall a b. (a -> b) -> [a] -> [b]
map (IRI, IRI) -> Json
indToJson [(IRI, IRI)]
inds
rels :: Json
rels = [Json] -> Json
JArray ([Json] -> Json) -> [Json] -> Json
forall a b. (a -> b) -> a -> b
$ ((IRI, IRI, IRI, IRI) -> Json) -> [(IRI, IRI, IRI, IRI)] -> [Json]
forall a b. (a -> b) -> [a] -> [b]
map (IRI, IRI, IRI, IRI) -> Json
relToJson [(IRI, IRI, IRI, IRI)]
mrels
indToJson :: (IRI, IRI) -> Json
indToJson :: (IRI, IRI) -> Json
indToJson (i :: IRI
i,t :: IRI
t) =
[JPair] -> Json
JObject [("Identifier",String -> Json
JString (String -> Json) -> String -> Json
forall a b. (a -> b) -> a -> b
$ Id -> String
forall a. Show a => a -> String
show (Id -> String) -> Id -> String
forall a b. (a -> b) -> a -> b
$ IRI -> Id
iriPath IRI
i),
("Type",String -> Json
JString (String -> Json) -> String -> Json
forall a b. (a -> b) -> a -> b
$ Id -> String
forall a. Show a => a -> String
show (Id -> String) -> Id -> String
forall a b. (a -> b) -> a -> b
$ IRI -> Id
iriPath IRI
t)]
relToJson :: (IRI, IRI, IRI, IRI) -> Json
relToJson :: (IRI, IRI, IRI, IRI) -> Json
relToJson (i1 :: IRI
i1, p1 :: IRI
p1, i2 :: IRI
i2, p2 :: IRI
p2) =
[JPair] -> Json
JObject [("Individual1", String -> Json
JString (String -> Json) -> String -> Json
forall a b. (a -> b) -> a -> b
$ Id -> String
forall a. Show a => a -> String
show (Id -> String) -> Id -> String
forall a b. (a -> b) -> a -> b
$ IRI -> Id
iriPath IRI
i1),
("Point1", String -> Json
JString (String -> Json) -> String -> Json
forall a b. (a -> b) -> a -> b
$ Id -> String
forall a. Show a => a -> String
show (Id -> String) -> Id -> String
forall a b. (a -> b) -> a -> b
$ IRI -> Id
iriPath IRI
p1),
("Individual2", String -> Json
JString (String -> Json) -> String -> Json
forall a b. (a -> b) -> a -> b
$ Id -> String
forall a. Show a => a -> String
show (Id -> String) -> Id -> String
forall a b. (a -> b) -> a -> b
$ IRI -> Id
iriPath IRI
i2),
("Point2", String -> Json
JString (String -> Json) -> String -> Json
forall a b. (a -> b) -> a -> b
$ Id -> String
forall a. Show a => a -> String
show (Id -> String) -> Id -> String
forall a b. (a -> b) -> a -> b
$ IRI -> Id
iriPath IRI
p2)]