{- |
Module      :  ./OWL2/XML.hs
Copyright   :  (c) Felix Gabriel Mance
License     :  GPLv2 or higher, see LICENSE.txt

Maintainer  :  f.mance@jacobs-university.de
Stability   :  provisional
Portability :  portable

OWL/XML Syntax Parsing
-}

module OWL2.XML
 ( xmlBasicSpec
 , splitIRI
 , isSmth
 ) where

import Common.Lexer (value)
import Common.IRI
import Common.Id (stringToId, tokStr, getTokens)
import qualified Common.GlobalAnnotations as GA (PrefixMap)


import OWL2.AS
import OWL2.Keywords
import OWL2.XMLKeywords

import Text.XML.Light

import Data.Maybe
import Data.List
import qualified Data.Map as Map

type XMLBase = Maybe String

-- | error messages for the parser
err :: String -> t
err :: String -> t
err s :: String
s = String -> t
forall a. HasCallStack => String -> a
error (String -> t) -> String -> t
forall a b. (a -> b) -> a -> b
$ "XML parser: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s

{- two functions from Text.XML.Light.Proc version 1.3.7 for compatibility
  with previous versions -}
vLookupAttrBy :: (Text.XML.Light.QName -> Bool) -> [Attr] -> Maybe String
vLookupAttrBy :: (QName -> Bool) -> [Attr] -> Maybe String
vLookupAttrBy p :: QName -> Bool
p as :: [Attr]
as = Attr -> String
attrVal (Attr -> String) -> Maybe Attr -> Maybe String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` (Attr -> Bool) -> [Attr] -> Maybe Attr
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (QName -> Bool
p (QName -> Bool) -> (Attr -> QName) -> Attr -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Attr -> QName
attrKey) [Attr]
as

vFindAttrBy :: (Text.XML.Light.QName -> Bool) -> Element -> Maybe String
vFindAttrBy :: (QName -> Bool) -> Element -> Maybe String
vFindAttrBy p :: QName -> Bool
p e :: Element
e = (QName -> Bool) -> [Attr] -> Maybe String
vLookupAttrBy QName -> Bool
p (Element -> [Attr]
elAttribs Element
e)

isSmth :: String -> Text.XML.Light.QName -> Bool
isSmth :: String -> QName -> Bool
isSmth s :: String
s = (String
s String -> String -> Bool
forall a. Eq a => a -> a -> Bool
==) (String -> Bool) -> (QName -> String) -> QName -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QName -> String
qName

isSmthList :: [String] -> Text.XML.Light.QName -> Bool
isSmthList :: [String] -> QName -> Bool
isSmthList l :: [String]
l qn :: QName
qn = QName -> String
qName QName
qn String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
l

isNotSmth :: Text.XML.Light.QName -> Bool
isNotSmth :: QName -> Bool
isNotSmth q :: QName
q = let qn :: String
qn = QName -> String
qName QName
q in String
qn String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [
    String
prefixK, String
importK, String
annotationK]

-- | parses all children with the given name
filterCh :: String -> Element -> [Element]
filterCh :: String -> Element -> [Element]
filterCh s :: String
s = (QName -> Bool) -> Element -> [Element]
filterChildrenName (String -> QName -> Bool
isSmth String
s)

-- | parses all children with names in the list
filterChL :: [String] -> Element -> [Element]
filterChL :: [String] -> Element -> [Element]
filterChL l :: [String]
l = (QName -> Bool) -> Element -> [Element]
filterChildrenName ([String] -> QName -> Bool
isSmthList [String]
l)

-- | parses one child with the given name
filterC :: String -> Element -> Element
filterC :: String -> Element -> Element
filterC s :: String
s e :: Element
e = Element -> Maybe Element -> Element
forall a. a -> Maybe a -> a
fromMaybe (String -> Element
forall t. String -> t
err "child not found")
    (Maybe Element -> Element) -> Maybe Element -> Element
forall a b. (a -> b) -> a -> b
$ (QName -> Bool) -> Element -> Maybe Element
filterChildName (String -> QName -> Bool
isSmth String
s) Element
e

-- | parses one child with the name in the list
filterCL :: [String] -> Element -> Element
filterCL :: [String] -> Element -> Element
filterCL l :: [String]
l e :: Element
e = Element -> Maybe Element -> Element
forall a. a -> Maybe a -> a
fromMaybe (String -> Element
forall t. String -> t
err "child not found")
    (Maybe Element -> Element) -> Maybe Element -> Element
forall a b. (a -> b) -> a -> b
$ (QName -> Bool) -> Element -> Maybe Element
filterChildName ([String] -> QName -> Bool
isSmthList [String]
l) Element
e

getIRIWithType :: GA.PrefixMap -> XMLBase -> String -> String -> IRI
getIRIWithType :: PrefixMap -> Maybe String -> String -> String -> IRI
getIRIWithType pm :: PrefixMap
pm b :: Maybe String
b typ :: String
typ iriStr :: String
iriStr =
    let parsed :: Maybe IRI
parsed = Maybe String -> String -> Maybe IRI
getIRIWithResolvedBase Maybe String
b String
iriStr 
        e :: a
e = String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ "could not get " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
typ String -> String -> String
forall a. [a] -> [a] -> [a]
++ " from " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
iriStr
        full :: IRI
full = IRI -> Maybe IRI -> IRI
forall a. a -> Maybe a -> a
fromMaybe IRI
forall a. a
e Maybe IRI
parsed
        curie :: IRI
curie = case String -> Maybe IRI
parseCurie String
iriStr of
            Just i :: IRI
i -> IRI
i
            Nothing -> String -> IRI
forall a. HasCallStack => String -> a
error (String -> IRI) -> String -> IRI
forall a b. (a -> b) -> a -> b
$ "could not get CURIE from " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
iriStr
    
    in PrefixMap -> IRI -> IRI
expandIRI PrefixMap
pm (IRI -> IRI) -> IRI -> IRI
forall a b. (a -> b) -> a -> b
$ case String
typ of
        "abbreviatedIRI" ->  IRI
curie
        "AbbreviatedIRI" -> IRI
curie
        "nodeID" -> case String -> Maybe IRI
parseCurie String
iriStr of
            Just i :: IRI
i -> IRI
i {isBlankNode :: Bool
isBlankNode = Bool
True}
            Nothing -> String -> IRI
forall a. HasCallStack => String -> a
error (String -> IRI) -> String -> IRI
forall a b. (a -> b) -> a -> b
$ "could not get nodeID from " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
iriStr
        "IRI" -> IRI
full
        "facet" -> IRI
full
        "Import" -> IRI
full
        _ -> String -> IRI
forall a. HasCallStack => String -> a
error (String -> IRI) -> String -> IRI
forall a b. (a -> b) -> a -> b
$ "wrong qName:" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
typ

-- | parses an IRI
getIRI :: GA.PrefixMap -> XMLBase -> Element -> IRI
getIRI :: PrefixMap -> Maybe String -> Element -> IRI
getIRI pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =
    let [a :: Attr
a] = Element -> [Attr]
elAttribs Element
e
        anIri :: String
anIri = Attr -> String
attrVal Attr
a
    in PrefixMap -> Maybe String -> String -> String -> IRI
getIRIWithType PrefixMap
pm Maybe String
b (QName -> String
qName (QName -> String) -> QName -> String
forall a b. (a -> b) -> a -> b
$ Attr -> QName
attrKey Attr
a) String
anIri


getIRIWithResolvedBase :: XMLBase -> String -> Maybe IRI
getIRIWithResolvedBase :: Maybe String -> String -> Maybe IRI
getIRIWithResolvedBase b :: Maybe String
b str :: String
str
    -- According to https://www.w3.org/TR/2012/REC-owl2-xml-serialization-20121211/#The_Serialization_Syntax
    -- all @IRI@s must be resolved against xml:base. Only doing this
    -- if the iri is relative

    
    | "://" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isInfixOf` String
str Bool -> Bool -> Bool
|| "urn:" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` String
str = String -> Maybe IRI
parseIRI String
str -- iri is absolute (contains a scheme)
    | Bool
otherwise = Maybe String
b Maybe String -> (String -> Maybe IRI) -> Maybe IRI
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (String -> Maybe IRI
parseIRI (String -> Maybe IRI) -> (String -> String) -> String -> Maybe IRI
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ( String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
str))



-- | splits an IRI at the colon
splitIRI :: IRI -> IRI
splitIRI :: IRI -> IRI
splitIRI iri :: IRI
iri = let 
  i :: Id
i = IRI -> Id
iriPath IRI
iri
  in if IRI -> Bool
isBlankNode IRI
iri then IRI -> IRI
mkNodeID IRI
iri else 
   case Id -> [Token]
getTokens Id
i of
    [] -> IRI
iri
    (tok :: Token
tok:ts :: [Token]
ts) ->
      let lp :: String
lp = Token -> String
tokStr Token
tok
          sp :: (String, String)
sp = (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= ':') String
lp
      in case (String, String)
sp of
         (np :: String
np, ':' : nlp :: String
nlp) -> IRI
iri { iriScheme :: String
iriScheme = String
np String -> String -> String
forall a. [a] -> [a] -> [a]
++ ":"
                                , iriPath :: Id
iriPath = Id
i { getTokens :: [Token]
getTokens = Token
tok { tokStr :: String
tokStr = String
nlp } Token -> [Token] -> [Token]
forall a. a -> [a] -> [a]
: [Token]
ts}
                                }
         _ -> IRI
iri
         
-- | prepends "_:" to the nodeID if is not there already
mkNodeID :: IRI -> IRI
mkNodeID :: IRI -> IRI
mkNodeID iri :: IRI
iri =
    let lp :: String
lp = Id -> String
forall a. Show a => a -> String
show (Id -> String) -> Id -> String
forall a b. (a -> b) -> a -> b
$ IRI -> Id
iriPath IRI
iri
    in case String
lp of
        '_' : ':' : r :: String
r -> IRI
iri {prefixName :: String
prefixName = "_", iriPath :: Id
iriPath = String -> Id
stringToId String
r}
        -- todo: maybe we should keep the Id structure of iriPath iri
        _ -> IRI
iri {prefixName :: String
prefixName = "_"}

-- | gets the content of an element with name IRI, AbbreviatedIRI or Import
contentIRI :: GA.PrefixMap -> XMLBase -> Element -> IRI
contentIRI :: PrefixMap -> Maybe String -> Element -> IRI
contentIRI pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = PrefixMap -> Maybe String -> String -> String -> IRI
getIRIWithType PrefixMap
pm Maybe String
b (Element -> String
getName Element
e) (Element -> String
strContent Element
e)

-- | gets the name of an axiom in XML Syntax
getName :: Element -> String
getName :: Element -> String
getName e :: Element
e =
  let u :: QName
u = Element -> QName
elName Element
e
      n :: String
n = QName -> String
qName QName
u
      q :: Maybe String
q = QName -> Maybe String
qURI QName
u
      p :: Maybe String
p = QName -> Maybe String
qPrefix QName
u
  in case Maybe String
q of
    Just "http://www.w3.org/2002/07/owl#" -> String
n
    _ -> if Maybe String -> Bool
forall a. Maybe a -> Bool
isNothing Maybe String
p then String
n else ""

-- | gets the cardinality
getInt :: Element -> Int
getInt :: Element -> Int
getInt e :: Element
e = let [int :: Attr
int] = Element -> [Attr]
elAttribs Element
e in Int -> String -> Int
value 10 (String -> Int) -> String -> Int
forall a b. (a -> b) -> a -> b
$ Attr -> String
attrVal Attr
int

getEntityType :: String -> EntityType
getEntityType :: String -> EntityType
getEntityType ty :: String
ty = EntityType -> Maybe EntityType -> EntityType
forall a. a -> Maybe a -> a
fromMaybe (String -> EntityType
forall t. String -> t
err (String -> EntityType) -> String -> EntityType
forall a b. (a -> b) -> a -> b
$ "no entity type " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
ty)
  (Maybe EntityType -> EntityType)
-> ([(String, EntityType)] -> Maybe EntityType)
-> [(String, EntityType)]
-> EntityType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [(String, EntityType)] -> Maybe EntityType
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup String
ty ([(String, EntityType)] -> EntityType)
-> [(String, EntityType)] -> EntityType
forall a b. (a -> b) -> a -> b
$ (EntityType -> (String, EntityType))
-> [EntityType] -> [(String, EntityType)]
forall a b. (a -> b) -> [a] -> [b]
map (\ e :: EntityType
e -> (EntityType -> String
forall a. Show a => a -> String
show EntityType
e, EntityType
e)) [EntityType]
entityTypes

getEntity :: GA.PrefixMap -> XMLBase -> Element -> Entity
getEntity :: PrefixMap -> Maybe String -> Element -> Entity
getEntity pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = EntityType -> IRI -> Entity
mkEntity (String -> EntityType
getEntityType (String -> EntityType) -> String -> EntityType
forall a b. (a -> b) -> a -> b
$ (QName -> String
qName (QName -> String) -> (Element -> QName) -> Element -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Element -> QName
elName) Element
e) (IRI -> Entity) -> IRI -> Entity
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
e

getDeclaration :: GA.PrefixMap -> XMLBase -> Element -> Axiom
getDeclaration :: PrefixMap -> Maybe String -> Element -> Axiom
getDeclaration pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = case Element -> String
getName Element
e of
   "Declaration" ->
       AxiomAnnotations -> Entity -> Axiom
Declaration (PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e) (PrefixMap -> Maybe String -> Element -> Entity
getEntity PrefixMap
pm Maybe String
b (Element -> Entity) -> Element -> Entity
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
entityList Element
e)
   _ -> PrefixMap -> Maybe String -> Element -> Axiom
getClassAxiom PrefixMap
pm Maybe String
b Element
e

isPlainLiteral :: String -> Bool
isPlainLiteral :: String -> Bool
isPlainLiteral s :: String
s =
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral" String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
s

-- | put an "f" for float if not there already (eg. 123.45 --> 123.45f)
correctLit :: Literal -> Literal
correctLit :: Literal -> Literal
correctLit l :: Literal
l = case Literal
l of
    Literal lf :: String
lf (Typed dt :: IRI
dt) ->
        let nlf :: String
nlf = if String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isSuffixOf "float" (Id -> String
forall a. Show a => a -> String
show (Id -> String) -> Id -> String
forall a b. (a -> b) -> a -> b
$ IRI -> Id
iriPath IRI
dt) Bool -> Bool -> Bool
&& String -> Char
forall a. [a] -> a
last String
lf Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= 'f'
                then String
lf String -> String -> String
forall a. [a] -> [a] -> [a]
++ "f"
                else String
lf
        in String -> TypedOrUntyped -> Literal
Literal String
nlf (IRI -> TypedOrUntyped
Typed IRI
dt)
    _ -> Literal
l

getLiteral :: GA.PrefixMap -> Element -> Literal
getLiteral :: PrefixMap -> Element -> Literal
getLiteral pm :: PrefixMap
pm e :: Element
e = case Element -> String
getName Element
e of
    "Literal" ->
      let lf :: String
lf = Element -> String
strContent Element
e
          mdt :: Maybe String
mdt = QName -> Element -> Maybe String
findAttr (String -> QName
unqual "datatypeIRI") Element
e
          mattr :: Maybe String
mattr = (QName -> Bool) -> Element -> Maybe String
vFindAttrBy (String -> QName -> Bool
isSmth "lang") Element
e
      in case Maybe String
mdt of
          Nothing -> case Maybe String
mattr of
             Just lang :: String
lang -> String -> TypedOrUntyped -> Literal
Literal String
lf (TypedOrUntyped -> Literal) -> TypedOrUntyped -> Literal
forall a b. (a -> b) -> a -> b
$ Maybe String -> TypedOrUntyped
Untyped (Maybe String -> TypedOrUntyped) -> Maybe String -> TypedOrUntyped
forall a b. (a -> b) -> a -> b
$ String -> Maybe String
forall a. a -> Maybe a
Just String
lang
             Nothing -> String -> TypedOrUntyped -> Literal
Literal String
lf (TypedOrUntyped -> Literal) -> TypedOrUntyped -> Literal
forall a b. (a -> b) -> a -> b
$ Maybe String -> TypedOrUntyped
Untyped Maybe String
forall a. Maybe a
Nothing
          Just dt :: String
dt -> case Maybe String
mattr of
             Just lang :: String
lang -> String -> TypedOrUntyped -> Literal
Literal String
lf (TypedOrUntyped -> Literal) -> TypedOrUntyped -> Literal
forall a b. (a -> b) -> a -> b
$ Maybe String -> TypedOrUntyped
Untyped (Maybe String -> TypedOrUntyped) -> Maybe String -> TypedOrUntyped
forall a b. (a -> b) -> a -> b
$ String -> Maybe String
forall a. a -> Maybe a
Just String
lang
             Nothing -> if String -> Bool
isPlainLiteral String
dt then
                          String -> TypedOrUntyped -> Literal
Literal String
lf (TypedOrUntyped -> Literal) -> TypedOrUntyped -> Literal
forall a b. (a -> b) -> a -> b
$ Maybe String -> TypedOrUntyped
Untyped Maybe String
forall a. Maybe a
Nothing
                         else case String -> Maybe IRI
parseIRIReference String
dt of
                            Just f :: IRI
f -> Literal -> Literal
correctLit (Literal -> Literal) -> Literal -> Literal
forall a b. (a -> b) -> a -> b
$ String -> TypedOrUntyped -> Literal
Literal String
lf (TypedOrUntyped -> Literal) -> TypedOrUntyped -> Literal
forall a b. (a -> b) -> a -> b
$ IRI -> TypedOrUntyped
Typed (PrefixMap -> IRI -> IRI
expandIRI PrefixMap
pm IRI
f)
                            _ -> String -> Literal
forall a. HasCallStack => String -> a
error (String -> Literal) -> String -> Literal
forall a b. (a -> b) -> a -> b
$ "could not get datatypeIRI from " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
dt
    _ -> String -> Literal
forall t. String -> t
err "not literal"

getValue :: GA.PrefixMap -> XMLBase -> Element -> AnnotationValue
getValue :: PrefixMap -> Maybe String -> Element -> AnnotationValue
getValue pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = case Element -> String
getName Element
e of
    "Literal" -> Literal -> AnnotationValue
AnnValLit (Literal -> AnnotationValue) -> Literal -> AnnotationValue
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Element -> Literal
getLiteral PrefixMap
pm Element
e
    "AnonymousIndividual" -> IRI -> AnnotationValue
AnnValue (IRI -> AnnotationValue) -> IRI -> AnnotationValue
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
e
    _ -> IRI -> AnnotationValue
AnnValue (IRI -> AnnotationValue) -> IRI -> AnnotationValue
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> IRI
contentIRI PrefixMap
pm Maybe String
b Element
e

getSubject :: GA.PrefixMap -> XMLBase -> Element -> IRI
getSubject :: PrefixMap -> Maybe String -> Element -> IRI
getSubject pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = case Element -> String
getName Element
e of
    "AnonymousIndividual" -> PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
e
    _ -> PrefixMap -> Maybe String -> Element -> IRI
contentIRI PrefixMap
pm Maybe String
b Element
e

getAnnotation :: GA.PrefixMap -> XMLBase -> Element -> Annotation
getAnnotation :: PrefixMap -> Maybe String -> Element -> Annotation
getAnnotation pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =
     let hd :: [Element]
hd = String -> Element -> [Element]
filterCh "Annotation" Element
e
         [ap :: Element
ap] = String -> Element -> [Element]
filterCh "AnnotationProperty" Element
e
         av :: Element
av = [String] -> Element -> Element
filterCL [String]
annotationValueList Element
e
     in AxiomAnnotations -> IRI -> AnnotationValue -> Annotation
Annotation ((Element -> Annotation) -> [Element] -> AxiomAnnotations
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> Annotation
getAnnotation PrefixMap
pm Maybe String
b) [Element]
hd) (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
ap) (AnnotationValue -> Annotation) -> AnnotationValue -> Annotation
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> AnnotationValue
getValue PrefixMap
pm Maybe String
b Element
av

-- | returns a list of annotations
getAllAnnos :: GA.PrefixMap -> XMLBase -> Element -> [Annotation]
getAllAnnos :: PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = (Element -> Annotation) -> [Element] -> AxiomAnnotations
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> Annotation
getAnnotation PrefixMap
pm Maybe String
b) ([Element] -> AxiomAnnotations) -> [Element] -> AxiomAnnotations
forall a b. (a -> b) -> a -> b
$ String -> Element -> [Element]
filterCh "Annotation" Element
e

getObjProp :: GA.PrefixMap -> XMLBase -> Element -> ObjectPropertyExpression
getObjProp :: PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = case Element -> String
getName Element
e of
  "ObjectProperty" -> IRI -> ObjectPropertyExpression
ObjectProp (IRI -> ObjectPropertyExpression)
-> IRI -> ObjectPropertyExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
e
  "ObjectInverseOf" ->
    let [ch :: Element
ch] = Element -> [Element]
elChildren Element
e
        [cch :: Element
cch] = Element -> [Element]
elChildren Element
ch
    in case Element -> String
getName Element
ch of
      "ObjectInverseOf" -> PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b Element
cch
      "ObjectProperty" -> ObjectPropertyExpression -> ObjectPropertyExpression
ObjectInverseOf (ObjectPropertyExpression -> ObjectPropertyExpression)
-> ObjectPropertyExpression -> ObjectPropertyExpression
forall a b. (a -> b) -> a -> b
$ IRI -> ObjectPropertyExpression
ObjectProp (IRI -> ObjectPropertyExpression)
-> IRI -> ObjectPropertyExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
ch
      _ -> String -> ObjectPropertyExpression
forall t. String -> t
err "not objectProperty"
  _ -> String -> ObjectPropertyExpression
forall t. String -> t
err "not objectProperty"

-- | replaces eg. "minExclusive" with ">"
properFacet :: ConstrainingFacet -> ConstrainingFacet
properFacet :: IRI -> IRI
properFacet cf :: IRI
cf
    | IRI -> Bool
hasFullIRI IRI
cf =
        let p :: String
p = IRI -> String
showIRICompact IRI
cf String -> String -> String
forall a. Eq a => [a] -> [a] -> [a]
\\ "http://www.w3.org/2001/XMLSchema#"
        in case String
p of
            "minInclusive" -> DatatypeFacet -> IRI
facetToIRI DatatypeFacet
MININCLUSIVE
            "minExclusive" -> DatatypeFacet -> IRI
facetToIRI DatatypeFacet
MINEXCLUSIVE
            "maxInclusive" -> DatatypeFacet -> IRI
facetToIRI DatatypeFacet
MAXINCLUSIVE
            "maxExclusive" -> DatatypeFacet -> IRI
facetToIRI DatatypeFacet
MAXEXCLUSIVE
            _ -> IRI
cf
    | Bool
otherwise = IRI
cf

getFacetValuePair :: GA.PrefixMap -> XMLBase -> Element -> (ConstrainingFacet, RestrictionValue)
getFacetValuePair :: PrefixMap -> Maybe String -> Element -> (IRI, Literal)
getFacetValuePair pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = case Element -> String
getName Element
e of
    "FacetRestriction" ->
       let [ch :: Element
ch] = Element -> [Element]
elChildren Element
e
       in (IRI -> IRI
properFacet (IRI -> IRI) -> IRI -> IRI
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
e, PrefixMap -> Element -> Literal
getLiteral PrefixMap
pm Element
ch)
    _ -> String -> (IRI, Literal)
forall t. String -> t
err "not facet"

getDataRange :: GA.PrefixMap -> XMLBase -> Element -> DataRange
getDataRange :: PrefixMap -> Maybe String -> Element -> DataRange
getDataRange pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =
  let ch :: [Element]
ch@(ch1 :: Element
ch1 : _) = Element -> [Element]
elChildren Element
e
  in case Element -> String
getName Element
e of
    "Datatype" -> IRI -> [(IRI, Literal)] -> DataRange
DataType (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
e) []
    "DatatypeRestriction" ->
        let dt :: IRI
dt = PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b (Element -> IRI) -> Element -> IRI
forall a b. (a -> b) -> a -> b
$ String -> Element -> Element
filterC "Datatype" Element
e
            fvp :: [(IRI, Literal)]
fvp = (Element -> (IRI, Literal)) -> [Element] -> [(IRI, Literal)]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> (IRI, Literal)
getFacetValuePair PrefixMap
pm Maybe String
b) ([Element] -> [(IRI, Literal)]) -> [Element] -> [(IRI, Literal)]
forall a b. (a -> b) -> a -> b
$ String -> Element -> [Element]
filterCh "FacetRestriction" Element
e
        in IRI -> [(IRI, Literal)] -> DataRange
DataType IRI
dt [(IRI, Literal)]
fvp
    "DataComplementOf" -> DataRange -> DataRange
DataComplementOf (DataRange -> DataRange) -> DataRange -> DataRange
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> DataRange
getDataRange PrefixMap
pm Maybe String
b Element
ch1
    "DataOneOf" -> [Literal] -> DataRange
DataOneOf ([Literal] -> DataRange) -> [Literal] -> DataRange
forall a b. (a -> b) -> a -> b
$ (Element -> Literal) -> [Element] -> [Literal]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Element -> Literal
getLiteral PrefixMap
pm) ([Element] -> [Literal]) -> [Element] -> [Literal]
forall a b. (a -> b) -> a -> b
$ String -> Element -> [Element]
filterCh "Literal" Element
e
    "DataIntersectionOf" -> JunctionType -> [DataRange] -> DataRange
DataJunction JunctionType
IntersectionOf
            ([DataRange] -> DataRange) -> [DataRange] -> DataRange
forall a b. (a -> b) -> a -> b
$ (Element -> DataRange) -> [Element] -> [DataRange]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> DataRange
getDataRange PrefixMap
pm Maybe String
b) [Element]
ch
    "DataUnionOf" -> JunctionType -> [DataRange] -> DataRange
DataJunction JunctionType
UnionOf ([DataRange] -> DataRange) -> [DataRange] -> DataRange
forall a b. (a -> b) -> a -> b
$ (Element -> DataRange) -> [Element] -> [DataRange]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> DataRange
getDataRange PrefixMap
pm Maybe String
b) [Element]
ch
    _ -> String -> DataRange
forall t. String -> t
err "not data range"

getClassExpression :: GA.PrefixMap -> XMLBase -> Element -> ClassExpression
getClassExpression :: PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =
  let ch :: [Element]
ch = Element -> [Element]
elChildren Element
e
      ch1 :: Element
ch1 : _ = [Element]
ch
      rch1 :: Element
rch1 : _ = [Element] -> [Element]
forall a. [a] -> [a]
reverse [Element]
ch
  in case Element -> String
getName Element
e of
    "Class" -> IRI -> ClassExpression
Expression (IRI -> ClassExpression) -> IRI -> ClassExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
e
    "ObjectIntersectionOf" -> JunctionType -> [ClassExpression] -> ClassExpression
ObjectJunction JunctionType
IntersectionOf
            ([ClassExpression] -> ClassExpression)
-> [ClassExpression] -> ClassExpression
forall a b. (a -> b) -> a -> b
$ (Element -> ClassExpression) -> [Element] -> [ClassExpression]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b) [Element]
ch
    "ObjectUnionOf" -> JunctionType -> [ClassExpression] -> ClassExpression
ObjectJunction JunctionType
UnionOf ([ClassExpression] -> ClassExpression)
-> [ClassExpression] -> ClassExpression
forall a b. (a -> b) -> a -> b
$ (Element -> ClassExpression) -> [Element] -> [ClassExpression]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b) [Element]
ch
    "ObjectComplementOf" -> ClassExpression -> ClassExpression
ObjectComplementOf (ClassExpression -> ClassExpression)
-> ClassExpression -> ClassExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b Element
ch1
    "ObjectOneOf" -> [IRI] -> ClassExpression
ObjectOneOf ([IRI] -> ClassExpression) -> [IRI] -> ClassExpression
forall a b. (a -> b) -> a -> b
$ (Element -> IRI) -> [Element] -> [IRI]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b) [Element]
ch
    "ObjectSomeValuesFrom" -> QuantifierType
-> ObjectPropertyExpression -> ClassExpression -> ClassExpression
ObjectValuesFrom QuantifierType
SomeValuesFrom
            (PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b Element
ch1) (ClassExpression -> ClassExpression)
-> ClassExpression -> ClassExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b Element
rch1
    "ObjectAllValuesFrom" -> QuantifierType
-> ObjectPropertyExpression -> ClassExpression -> ClassExpression
ObjectValuesFrom QuantifierType
AllValuesFrom
            (PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b Element
ch1) (ClassExpression -> ClassExpression)
-> ClassExpression -> ClassExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b Element
rch1
    "ObjectHasValue" -> ObjectPropertyExpression -> IRI -> ClassExpression
ObjectHasValue (PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b Element
ch1) (IRI -> ClassExpression) -> IRI -> ClassExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
rch1
    "ObjectHasSelf" -> ObjectPropertyExpression -> ClassExpression
ObjectHasSelf (ObjectPropertyExpression -> ClassExpression)
-> ObjectPropertyExpression -> ClassExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b Element
ch1
    "DataSomeValuesFrom" -> QuantifierType -> [IRI] -> DataRange -> ClassExpression
DataValuesFrom QuantifierType
SomeValuesFrom ([PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
ch1])
            (DataRange -> ClassExpression) -> DataRange -> ClassExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> DataRange
getDataRange PrefixMap
pm Maybe String
b Element
rch1
    "DataAllValuesFrom" -> QuantifierType -> [IRI] -> DataRange -> ClassExpression
DataValuesFrom QuantifierType
AllValuesFrom ([PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
ch1])
            (DataRange -> ClassExpression) -> DataRange -> ClassExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> DataRange
getDataRange PrefixMap
pm Maybe String
b Element
rch1
    "DataHasValue" -> IRI -> Literal -> ClassExpression
DataHasValue (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
ch1) (Literal -> ClassExpression) -> Literal -> ClassExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Element -> Literal
getLiteral PrefixMap
pm Element
rch1
    _ -> PrefixMap
-> Maybe String
-> Element
-> [Element]
-> Element
-> ClassExpression
getObjCard PrefixMap
pm Maybe String
b Element
e [Element]
ch Element
rch1

getObjCard :: GA.PrefixMap -> XMLBase -> Element -> [Element] -> Element -> ClassExpression
getObjCard :: PrefixMap
-> Maybe String
-> Element
-> [Element]
-> Element
-> ClassExpression
getObjCard pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e ch :: [Element]
ch rch1 :: Element
rch1 =
    let ch1 :: Element
ch1 : _ = [Element]
ch
        i :: Int
i = Element -> Int
getInt Element
e
        op :: ObjectPropertyExpression
op = PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b Element
ch1
        ce :: Maybe ClassExpression
ce = if [Element] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Element]
ch Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 2
                then ClassExpression -> Maybe ClassExpression
forall a. a -> Maybe a
Just (ClassExpression -> Maybe ClassExpression)
-> ClassExpression -> Maybe ClassExpression
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b Element
rch1
                else Maybe ClassExpression
forall a. Maybe a
Nothing
    in case Element -> String
getName Element
e of
        "ObjectMinCardinality" -> Cardinality ObjectPropertyExpression ClassExpression
-> ClassExpression
ObjectCardinality (Cardinality ObjectPropertyExpression ClassExpression
 -> ClassExpression)
-> Cardinality ObjectPropertyExpression ClassExpression
-> ClassExpression
forall a b. (a -> b) -> a -> b
$ CardinalityType
-> Int
-> ObjectPropertyExpression
-> Maybe ClassExpression
-> Cardinality ObjectPropertyExpression ClassExpression
forall a b.
CardinalityType -> Int -> a -> Maybe b -> Cardinality a b
Cardinality
            CardinalityType
MinCardinality Int
i ObjectPropertyExpression
op Maybe ClassExpression
ce
        "ObjectMaxCardinality" -> Cardinality ObjectPropertyExpression ClassExpression
-> ClassExpression
ObjectCardinality (Cardinality ObjectPropertyExpression ClassExpression
 -> ClassExpression)
-> Cardinality ObjectPropertyExpression ClassExpression
-> ClassExpression
forall a b. (a -> b) -> a -> b
$ CardinalityType
-> Int
-> ObjectPropertyExpression
-> Maybe ClassExpression
-> Cardinality ObjectPropertyExpression ClassExpression
forall a b.
CardinalityType -> Int -> a -> Maybe b -> Cardinality a b
Cardinality
            CardinalityType
MaxCardinality Int
i ObjectPropertyExpression
op Maybe ClassExpression
ce
        "ObjectExactCardinality" -> Cardinality ObjectPropertyExpression ClassExpression
-> ClassExpression
ObjectCardinality (Cardinality ObjectPropertyExpression ClassExpression
 -> ClassExpression)
-> Cardinality ObjectPropertyExpression ClassExpression
-> ClassExpression
forall a b. (a -> b) -> a -> b
$ CardinalityType
-> Int
-> ObjectPropertyExpression
-> Maybe ClassExpression
-> Cardinality ObjectPropertyExpression ClassExpression
forall a b.
CardinalityType -> Int -> a -> Maybe b -> Cardinality a b
Cardinality
            CardinalityType
ExactCardinality Int
i ObjectPropertyExpression
op Maybe ClassExpression
ce
        _ -> PrefixMap
-> Maybe String
-> Element
-> [Element]
-> Element
-> ClassExpression
getDataCard PrefixMap
pm Maybe String
b Element
e [Element]
ch Element
rch1

getDataCard :: GA.PrefixMap -> XMLBase -> Element -> [Element] -> Element -> ClassExpression
getDataCard :: PrefixMap
-> Maybe String
-> Element
-> [Element]
-> Element
-> ClassExpression
getDataCard pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e ch :: [Element]
ch rch1 :: Element
rch1 =
    let ch1 :: Element
ch1 : _ = [Element]
ch
        i :: Int
i = Element -> Int
getInt Element
e
        dp :: IRI
dp = PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
ch1
        dr :: Maybe DataRange
dr = if [Element] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Element]
ch Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 2
                then DataRange -> Maybe DataRange
forall a. a -> Maybe a
Just (DataRange -> Maybe DataRange) -> DataRange -> Maybe DataRange
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> DataRange
getDataRange PrefixMap
pm Maybe String
b Element
rch1
                else Maybe DataRange
forall a. Maybe a
Nothing
    in case Element -> String
getName Element
e of
        "DataMinCardinality" -> Cardinality IRI DataRange -> ClassExpression
DataCardinality (Cardinality IRI DataRange -> ClassExpression)
-> Cardinality IRI DataRange -> ClassExpression
forall a b. (a -> b) -> a -> b
$ CardinalityType
-> Int -> IRI -> Maybe DataRange -> Cardinality IRI DataRange
forall a b.
CardinalityType -> Int -> a -> Maybe b -> Cardinality a b
Cardinality
              CardinalityType
MinCardinality Int
i IRI
dp Maybe DataRange
dr
        "DataMaxCardinality" -> Cardinality IRI DataRange -> ClassExpression
DataCardinality (Cardinality IRI DataRange -> ClassExpression)
-> Cardinality IRI DataRange -> ClassExpression
forall a b. (a -> b) -> a -> b
$ CardinalityType
-> Int -> IRI -> Maybe DataRange -> Cardinality IRI DataRange
forall a b.
CardinalityType -> Int -> a -> Maybe b -> Cardinality a b
Cardinality
              CardinalityType
MaxCardinality Int
i IRI
dp Maybe DataRange
dr
        "DataExactCardinality" -> Cardinality IRI DataRange -> ClassExpression
DataCardinality (Cardinality IRI DataRange -> ClassExpression)
-> Cardinality IRI DataRange -> ClassExpression
forall a b. (a -> b) -> a -> b
$ CardinalityType
-> Int -> IRI -> Maybe DataRange -> Cardinality IRI DataRange
forall a b.
CardinalityType -> Int -> a -> Maybe b -> Cardinality a b
Cardinality
              CardinalityType
ExactCardinality Int
i IRI
dp Maybe DataRange
dr
        _ -> String -> ClassExpression
forall t. String -> t
err "not class expression"

getClassAxiom :: GA.PrefixMap -> XMLBase -> Element -> Axiom
getClassAxiom :: PrefixMap -> Maybe String -> Element -> Axiom
getClassAxiom pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =
   let ch :: [Element]
ch = Element -> [Element]
elChildren Element
e
       as :: AxiomAnnotations
as = PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e
       l :: [Element]
l@(hd :: Element
hd : tl :: [Element]
tl) = [String] -> Element -> [Element]
filterChL [String]
classExpressionList Element
e
       [dhd :: Element
dhd, dtl :: Element
dtl] = [String] -> Element -> [Element]
filterChL [String]
dataRangeList Element
e
       cel :: [ClassExpression]
cel = (Element -> ClassExpression) -> [Element] -> [ClassExpression]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b) [Element]
l
   in case Element -> String
getName Element
e of
    "SubClassOf" ->
       let [sub :: ClassExpression
sub, super :: ClassExpression
super] = PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b (Element -> ClassExpression) -> [Element] -> [ClassExpression]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> [Element] -> [Element]
forall a. Int -> [a] -> [a]
drop ([Element] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Element]
ch Int -> Int -> Int
forall a. Num a => a -> a -> a
- 2) [Element]
ch
       in ClassAxiom -> Axiom
ClassAxiom (ClassAxiom -> Axiom) -> ClassAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations
-> ClassExpression -> ClassExpression -> ClassAxiom
SubClassOf AxiomAnnotations
as ClassExpression
sub ClassExpression
super
    "EquivalentClasses" -> ClassAxiom -> Axiom
ClassAxiom (ClassAxiom -> Axiom) -> ClassAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> [ClassExpression] -> ClassAxiom
EquivalentClasses AxiomAnnotations
as [ClassExpression]
cel
    "DisjointClasses" -> ClassAxiom -> Axiom
ClassAxiom (ClassAxiom -> Axiom) -> ClassAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> [ClassExpression] -> ClassAxiom
DisjointClasses AxiomAnnotations
as [ClassExpression]
cel
    "DisjointUnion" -> case PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b Element
hd of
        Expression c :: IRI
c -> ClassAxiom -> Axiom
ClassAxiom (ClassAxiom -> Axiom) -> ClassAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> IRI -> [ClassExpression] -> ClassAxiom
DisjointUnion AxiomAnnotations
as IRI
c (PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b (Element -> ClassExpression) -> [Element] -> [ClassExpression]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Element]
tl)
        _ -> String -> Axiom
forall t. String -> t
err "Invalid ClassExpression. DisjointUnion must have a class."
    "DatatypeDefinition" ->
        AxiomAnnotations -> IRI -> DataRange -> Axiom
DatatypeDefinition AxiomAnnotations
as (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
dhd) (PrefixMap -> Maybe String -> Element -> DataRange
getDataRange PrefixMap
pm Maybe String
b Element
dtl)
    _ -> PrefixMap -> Maybe String -> Element -> Axiom
getKey PrefixMap
pm Maybe String
b Element
e

getKey :: GA.PrefixMap -> XMLBase -> Element -> Axiom
getKey :: PrefixMap -> Maybe String -> Element -> Axiom
getKey pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = case Element -> String
getName Element
e of
  "HasKey" ->
    let as :: AxiomAnnotations
as = PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e
        [ce :: Element
ce] = [String] -> Element -> [Element]
filterChL [String]
classExpressionList Element
e
        op :: [ObjectPropertyExpression]
op = (Element -> ObjectPropertyExpression)
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b) ([Element] -> [ObjectPropertyExpression])
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> [Element]
filterChL [String]
objectPropList Element
e
        dp :: [IRI]
dp = (Element -> IRI) -> [Element] -> [IRI]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b) ([Element] -> [IRI]) -> [Element] -> [IRI]
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> [Element]
filterChL [String]
dataPropList Element
e
    in AxiomAnnotations
-> ClassExpression -> [ObjectPropertyExpression] -> [IRI] -> Axiom
HasKey AxiomAnnotations
as (PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b Element
ce) [ObjectPropertyExpression]
op [IRI]
dp
  _ -> PrefixMap -> Maybe String -> Element -> Axiom
getOPAxiom PrefixMap
pm Maybe String
b Element
e

getOPAxiom :: GA.PrefixMap -> XMLBase -> Element -> Axiom
getOPAxiom :: PrefixMap -> Maybe String -> Element -> Axiom
getOPAxiom pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =
   let as :: AxiomAnnotations
as = PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e
       op :: ObjectPropertyExpression
op = PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b (Element -> ObjectPropertyExpression)
-> Element -> ObjectPropertyExpression
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
objectPropList Element
e
   in case Element -> String
getName Element
e of
    "SubObjectPropertyOf" ->
       let opchain :: [ObjectPropertyExpression]
opchain = (Element -> [ObjectPropertyExpression])
-> [Element] -> [ObjectPropertyExpression]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((Element -> ObjectPropertyExpression)
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b) ([Element] -> [ObjectPropertyExpression])
-> (Element -> [Element]) -> Element -> [ObjectPropertyExpression]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Element -> [Element]
elChildren)
            ([Element] -> [ObjectPropertyExpression])
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> a -> b
$ String -> Element -> [Element]
filterCh "ObjectPropertyChain" Element
e
       in if [ObjectPropertyExpression] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ObjectPropertyExpression]
opchain
             then let [o1 :: ObjectPropertyExpression
o1, o2 :: ObjectPropertyExpression
o2] = (Element -> ObjectPropertyExpression)
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b) ([Element] -> [ObjectPropertyExpression])
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> [Element]
filterChL [String]
objectPropList Element
e
                  in ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
                    AxiomAnnotations
-> SubObjectPropertyExpression
-> ObjectPropertyExpression
-> ObjectPropertyAxiom
SubObjectPropertyOf AxiomAnnotations
as (ObjectPropertyExpression -> SubObjectPropertyExpression
SubObjPropExpr_obj ObjectPropertyExpression
o1) ObjectPropertyExpression
o2
             else ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
                AxiomAnnotations
-> SubObjectPropertyExpression
-> ObjectPropertyExpression
-> ObjectPropertyAxiom
SubObjectPropertyOf AxiomAnnotations
as ([ObjectPropertyExpression] -> SubObjectPropertyExpression
SubObjPropExpr_exprchain [ObjectPropertyExpression]
opchain) ObjectPropertyExpression
op
    "EquivalentObjectProperties" ->
       let opl :: [ObjectPropertyExpression]
opl = (Element -> ObjectPropertyExpression)
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b) ([Element] -> [ObjectPropertyExpression])
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> [Element]
filterChL [String]
objectPropList Element
e
       in ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations
-> [ObjectPropertyExpression] -> ObjectPropertyAxiom
EquivalentObjectProperties AxiomAnnotations
as [ObjectPropertyExpression]
opl
    "DisjointObjectProperties" ->
       let opl :: [ObjectPropertyExpression]
opl = (Element -> ObjectPropertyExpression)
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b) ([Element] -> [ObjectPropertyExpression])
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> [Element]
filterChL [String]
objectPropList Element
e
       in ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations
-> [ObjectPropertyExpression] -> ObjectPropertyAxiom
DisjointObjectProperties AxiomAnnotations
as [ObjectPropertyExpression]
opl
    "ObjectPropertyDomain" ->
       let ce :: ClassExpression
ce = PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b (Element -> ClassExpression) -> Element -> ClassExpression
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
classExpressionList Element
e
       in ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations
-> ObjectPropertyExpression
-> ClassExpression
-> ObjectPropertyAxiom
ObjectPropertyDomain AxiomAnnotations
as ObjectPropertyExpression
op ClassExpression
ce
    "ObjectPropertyRange" ->
       let ce :: ClassExpression
ce = PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b (Element -> ClassExpression) -> Element -> ClassExpression
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
classExpressionList Element
e
       in ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations
-> ObjectPropertyExpression
-> ClassExpression
-> ObjectPropertyAxiom
ObjectPropertyRange AxiomAnnotations
as ObjectPropertyExpression
op ClassExpression
ce
    "InverseObjectProperties" ->
       let [hd :: ObjectPropertyExpression
hd, lst :: ObjectPropertyExpression
lst] = (Element -> ObjectPropertyExpression)
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b) ([Element] -> [ObjectPropertyExpression])
-> [Element] -> [ObjectPropertyExpression]
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> [Element]
filterChL [String]
objectPropList Element
e
       in ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations
-> ObjectPropertyExpression
-> ObjectPropertyExpression
-> ObjectPropertyAxiom
InverseObjectProperties AxiomAnnotations
as ObjectPropertyExpression
hd ObjectPropertyExpression
lst
    "FunctionalObjectProperty" -> ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations -> ObjectPropertyExpression -> ObjectPropertyAxiom
FunctionalObjectProperty AxiomAnnotations
as ObjectPropertyExpression
op
    "InverseFunctionalObjectProperty" -> ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations -> ObjectPropertyExpression -> ObjectPropertyAxiom
InverseFunctionalObjectProperty AxiomAnnotations
as ObjectPropertyExpression
op
    "ReflexiveObjectProperty" -> ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations -> ObjectPropertyExpression -> ObjectPropertyAxiom
ReflexiveObjectProperty AxiomAnnotations
as ObjectPropertyExpression
op
    "IrreflexiveObjectProperty" -> ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations -> ObjectPropertyExpression -> ObjectPropertyAxiom
IrreflexiveObjectProperty AxiomAnnotations
as ObjectPropertyExpression
op
    "SymmetricObjectProperty" -> ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations -> ObjectPropertyExpression -> ObjectPropertyAxiom
SymmetricObjectProperty AxiomAnnotations
as ObjectPropertyExpression
op
    "AsymmetricObjectProperty" -> ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations -> ObjectPropertyExpression -> ObjectPropertyAxiom
AsymmetricObjectProperty AxiomAnnotations
as ObjectPropertyExpression
op
    "TransitiveObjectProperty" -> ObjectPropertyAxiom -> Axiom
ObjectPropertyAxiom (ObjectPropertyAxiom -> Axiom) -> ObjectPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ 
        AxiomAnnotations -> ObjectPropertyExpression -> ObjectPropertyAxiom
TransitiveObjectProperty AxiomAnnotations
as ObjectPropertyExpression
op
    _ -> PrefixMap -> Maybe String -> Element -> Axiom
getDPAxiom PrefixMap
pm Maybe String
b Element
e

getDPAxiom :: GA.PrefixMap -> XMLBase -> Element -> Axiom
getDPAxiom :: PrefixMap -> Maybe String -> Element -> Axiom
getDPAxiom pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =
   let as :: AxiomAnnotations
as = PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e
   in case Element -> String
getName Element
e of
    "SubDataPropertyOf" ->
        let [hd :: IRI
hd, lst :: IRI
lst] = (Element -> IRI) -> [Element] -> [IRI]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b) ([Element] -> [IRI]) -> [Element] -> [IRI]
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> [Element]
filterChL [String]
dataPropList Element
e
        in DataPropertyAxiom -> Axiom
DataPropertyAxiom (DataPropertyAxiom -> Axiom) -> DataPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> IRI -> IRI -> DataPropertyAxiom
SubDataPropertyOf AxiomAnnotations
as IRI
hd IRI
lst
    "EquivalentDataProperties" ->
        let dpl :: [IRI]
dpl = (Element -> IRI) -> [Element] -> [IRI]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b) ([Element] -> [IRI]) -> [Element] -> [IRI]
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> [Element]
filterChL [String]
dataPropList Element
e
        in DataPropertyAxiom -> Axiom
DataPropertyAxiom (DataPropertyAxiom -> Axiom) -> DataPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> [IRI] -> DataPropertyAxiom
EquivalentDataProperties AxiomAnnotations
as [IRI]
dpl
    "DisjointDataProperties" ->
        let dpl :: [IRI]
dpl = (Element -> IRI) -> [Element] -> [IRI]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b) ([Element] -> [IRI]) -> [Element] -> [IRI]
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> [Element]
filterChL [String]
dataPropList Element
e
        in DataPropertyAxiom -> Axiom
DataPropertyAxiom (DataPropertyAxiom -> Axiom) -> DataPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> [IRI] -> DataPropertyAxiom
DisjointDataProperties AxiomAnnotations
as [IRI]
dpl
    "DataPropertyDomain" ->
        let dp :: IRI
dp = PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b (Element -> IRI) -> Element -> IRI
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
dataPropList Element
e
            ce :: ClassExpression
ce = PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b (Element -> ClassExpression) -> Element -> ClassExpression
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
classExpressionList Element
e
        in DataPropertyAxiom -> Axiom
DataPropertyAxiom (DataPropertyAxiom -> Axiom) -> DataPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> IRI -> ClassExpression -> DataPropertyAxiom
DataPropertyDomain AxiomAnnotations
as IRI
dp ClassExpression
ce
    "DataPropertyRange" ->
        let dp :: IRI
dp = PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b (Element -> IRI) -> Element -> IRI
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
dataPropList Element
e
            dr :: DataRange
dr = PrefixMap -> Maybe String -> Element -> DataRange
getDataRange PrefixMap
pm Maybe String
b (Element -> DataRange) -> Element -> DataRange
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
dataRangeList Element
e
        in DataPropertyAxiom -> Axiom
DataPropertyAxiom (DataPropertyAxiom -> Axiom) -> DataPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> IRI -> DataRange -> DataPropertyAxiom
DataPropertyRange AxiomAnnotations
as IRI
dp DataRange
dr
    "FunctionalDataProperty" ->
        let dp :: IRI
dp = PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b (Element -> IRI) -> Element -> IRI
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
dataPropList Element
e
        in DataPropertyAxiom -> Axiom
DataPropertyAxiom (DataPropertyAxiom -> Axiom) -> DataPropertyAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> IRI -> DataPropertyAxiom
FunctionalDataProperty AxiomAnnotations
as IRI
dp
    _ -> PrefixMap -> Maybe String -> Element -> Axiom
getDataAssertion PrefixMap
pm Maybe String
b Element
e

getDataAssertion :: GA.PrefixMap -> XMLBase -> Element -> Axiom
getDataAssertion :: PrefixMap -> Maybe String -> Element -> Axiom
getDataAssertion pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =
   let as :: AxiomAnnotations
as = PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e
       dp :: IRI
dp = PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b (Element -> IRI) -> Element -> IRI
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
dataPropList Element
e
       ind :: IRI
ind = PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b (Element -> IRI) -> Element -> IRI
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
individualList Element
e
       lit :: Literal
lit = PrefixMap -> Element -> Literal
getLiteral PrefixMap
pm (Element -> Literal) -> Element -> Literal
forall a b. (a -> b) -> a -> b
$ String -> Element -> Element
filterC "Literal" Element
e
   in case Element -> String
getName Element
e of
    "DataPropertyAssertion" -> Assertion -> Axiom
Assertion (Assertion -> Axiom) -> Assertion -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> IRI -> IRI -> Literal -> Assertion
DataPropertyAssertion AxiomAnnotations
as IRI
dp IRI
ind Literal
lit
    "NegativeDataPropertyAssertion" -> 
        Assertion -> Axiom
Assertion (Assertion -> Axiom) -> Assertion -> Axiom
forall a b. (a -> b) -> a -> b
$  AxiomAnnotations -> IRI -> IRI -> Literal -> Assertion
NegativeDataPropertyAssertion AxiomAnnotations
as IRI
dp IRI
ind Literal
lit
    _ -> PrefixMap -> Maybe String -> Element -> Axiom
getObjectAssertion PrefixMap
pm Maybe String
b Element
e


getObjectAssertion :: GA.PrefixMap -> XMLBase -> Element -> Axiom
getObjectAssertion :: PrefixMap -> Maybe String -> Element -> Axiom
getObjectAssertion pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =
   let as :: AxiomAnnotations
as = PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e
       op :: ObjectPropertyExpression
op = PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b (Element -> ObjectPropertyExpression)
-> Element -> ObjectPropertyExpression
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
objectPropList Element
e
       [hd :: IRI
hd, lst :: IRI
lst] = (Element -> IRI) -> [Element] -> [IRI]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b) ([Element] -> [IRI]) -> [Element] -> [IRI]
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> [Element]
filterChL [String]
individualList Element
e
   in case Element -> String
getName Element
e of
    "ObjectPropertyAssertion" -> Assertion -> Axiom
Assertion (Assertion -> Axiom) -> Assertion -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations
-> ObjectPropertyExpression -> IRI -> IRI -> Assertion
ObjectPropertyAssertion AxiomAnnotations
as ObjectPropertyExpression
op IRI
hd IRI
lst
    "NegativeObjectPropertyAssertion" ->
        Assertion -> Axiom
Assertion (Assertion -> Axiom) -> Assertion -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations
-> ObjectPropertyExpression -> IRI -> IRI -> Assertion
NegativeObjectPropertyAssertion AxiomAnnotations
as ObjectPropertyExpression
op IRI
hd IRI
lst
    _ -> PrefixMap -> Maybe String -> Element -> Axiom
getIndividualAssertion PrefixMap
pm Maybe String
b Element
e

getIndividualAssertion :: GA.PrefixMap -> XMLBase -> Element -> Axiom
getIndividualAssertion :: PrefixMap -> Maybe String -> Element -> Axiom
getIndividualAssertion pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =
   let as :: AxiomAnnotations
as = PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e
       ind :: [IRI]
ind = (Element -> IRI) -> [Element] -> [IRI]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b) ([Element] -> [IRI]) -> [Element] -> [IRI]
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> [Element]
filterChL [String]
individualList Element
e
   in case Element -> String
getName Element
e of
    "SameIndividual" -> Assertion -> Axiom
Assertion (Assertion -> Axiom) -> Assertion -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> [IRI] -> Assertion
SameIndividual AxiomAnnotations
as [IRI]
ind
    "DifferentIndividuals" -> Assertion -> Axiom
Assertion (Assertion -> Axiom) -> Assertion -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> [IRI] -> Assertion
DifferentIndividuals AxiomAnnotations
as [IRI]
ind
    _ -> PrefixMap -> Maybe String -> Element -> Axiom
getClassAssertion PrefixMap
pm Maybe String
b Element
e

getClassAssertion :: GA.PrefixMap -> XMLBase -> Element -> Axiom
getClassAssertion :: PrefixMap -> Maybe String -> Element -> Axiom
getClassAssertion pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = case Element -> String
getName Element
e of
    "ClassAssertion" ->
        let as :: AxiomAnnotations
as = PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e
            ce :: ClassExpression
ce = PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b (Element -> ClassExpression) -> Element -> ClassExpression
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
classExpressionList Element
e
            ind :: IRI
ind = PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b (Element -> IRI) -> Element -> IRI
forall a b. (a -> b) -> a -> b
$ [String] -> Element -> Element
filterCL [String]
individualList Element
e
        in Assertion -> Axiom
Assertion (Assertion -> Axiom) -> Assertion -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> ClassExpression -> IRI -> Assertion
ClassAssertion AxiomAnnotations
as ClassExpression
ce IRI
ind
    _ -> PrefixMap -> Maybe String -> Element -> Axiom
getAnnoAxiom PrefixMap
pm Maybe String
b Element
e

getAnnoAxiom :: GA.PrefixMap -> XMLBase -> Element -> Axiom
getAnnoAxiom :: PrefixMap -> Maybe String -> Element -> Axiom
getAnnoAxiom pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =
   let as :: AxiomAnnotations
as = PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e
       ap :: IRI
ap = PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b (Element -> IRI) -> Element -> IRI
forall a b. (a -> b) -> a -> b
$ String -> Element -> Element
filterC "AnnotationProperty" Element
e
       [ch :: Element
ch] = [String] -> Element -> [Element]
filterChL [String
iriK, String
abbreviatedIRI] Element
e
       anIri :: IRI
anIri = PrefixMap -> Maybe String -> Element -> IRI
contentIRI PrefixMap
pm Maybe String
b Element
ch
    in case Element -> String
getName Element
e of
    "AnnotationAssertion" ->
       let [s :: Element
s, v :: Element
v] = [String] -> Element -> [Element]
filterChL [String]
annotationValueList Element
e
           sub :: IRI
sub = PrefixMap -> Maybe String -> Element -> IRI
getSubject PrefixMap
pm Maybe String
b Element
s
        -- TODO: What about iris?
       in AnnotationAxiom -> Axiom
AnnotationAxiom (AnnotationAxiom -> Axiom) -> AnnotationAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations
-> IRI -> AnnotationSubject -> AnnotationValue -> AnnotationAxiom
AnnotationAssertion AxiomAnnotations
as IRI
ap (IRI -> AnnotationSubject
AnnSubIri IRI
sub) (PrefixMap -> Maybe String -> Element -> AnnotationValue
getValue PrefixMap
pm Maybe String
b Element
v)
       -- the misc will be converted to entities in static analysis
    --    in PlainAxiom (Misc [Annotation [] sub $ AnnValue sub])
    --        $ AnnFrameBit [Annotation as ap (getValue b v)]
    --                 $ AnnotationFrameBit Assertion
    "SubAnnotationPropertyOf" ->
        let [hd :: IRI
hd, lst :: IRI
lst] = (Element -> IRI) -> [Element] -> [IRI]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b) ([Element] -> [IRI]) -> [Element] -> [IRI]
forall a b. (a -> b) -> a -> b
$ String -> Element -> [Element]
filterCh "AnnotationProperty" Element
e
        in AnnotationAxiom -> Axiom
AnnotationAxiom (AnnotationAxiom -> Axiom) -> AnnotationAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> IRI -> IRI -> AnnotationAxiom
SubAnnotationPropertyOf AxiomAnnotations
as IRI
hd IRI
lst
    "AnnotationPropertyDomain" -> AnnotationAxiom -> Axiom
AnnotationAxiom (AnnotationAxiom -> Axiom) -> AnnotationAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> IRI -> IRI -> AnnotationAxiom
AnnotationPropertyDomain AxiomAnnotations
as IRI
ap IRI
anIri
    "AnnotationPropertyRange" -> AnnotationAxiom -> Axiom
AnnotationAxiom (AnnotationAxiom -> Axiom) -> AnnotationAxiom -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> IRI -> IRI -> AnnotationAxiom
AnnotationPropertyRange AxiomAnnotations
as IRI
ap IRI
anIri
    _ -> PrefixMap -> Maybe String -> Element -> Axiom
getRuleAxiom PrefixMap
pm Maybe String
b Element
e

getIArg :: GA.PrefixMap -> XMLBase -> Element -> IndividualArg
getIArg :: PrefixMap -> Maybe String -> Element -> IndividualArg
getIArg pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = case Element -> String
getName Element
e of
    "Variable" -> IRI -> IndividualArg
IVar (IRI -> IndividualArg) -> IRI -> IndividualArg
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
e
    "NamedIndividual" -> IRI -> IndividualArg
IArg (IRI -> IndividualArg) -> IRI -> IndividualArg
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
e
    _ ->  String -> IndividualArg
forall t. String -> t
err (String -> IndividualArg) -> String -> IndividualArg
forall a b. (a -> b) -> a -> b
$ "Unexpected element '" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Element -> String
getName Element
e String -> String -> String
forall a. [a] -> [a] -> [a]
++ "'."

getDArg :: GA.PrefixMap -> XMLBase -> Element -> DataArg
getDArg :: PrefixMap -> Maybe String -> Element -> DataArg
getDArg pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = case Element -> String
getName Element
e of
    "Variable" -> IRI -> DataArg
DVar (IRI -> DataArg) -> IRI -> DataArg
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
e
    "Literal" -> Literal -> DataArg
DArg (Literal -> DataArg) -> Literal -> DataArg
forall a b. (a -> b) -> a -> b
$ PrefixMap -> Element -> Literal
getLiteral PrefixMap
pm Element
e
    _ ->  String -> DataArg
forall t. String -> t
err (String -> DataArg) -> String -> DataArg
forall a b. (a -> b) -> a -> b
$ "Unexpected element '" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Element -> String
getName Element
e String -> String -> String
forall a. [a] -> [a] -> [a]
++ "'."

getAtom :: GA.PrefixMap -> XMLBase -> Element -> Atom
getAtom :: PrefixMap -> Maybe String -> Element -> Atom
getAtom pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e =  case Element -> String
getName Element
e of
    "ClassAtom" ->
        let [clExpr :: Element
clExpr, iarg :: Element
iarg] = Element -> [Element]
elChildren Element
e
        in ClassExpression -> IndividualArg -> Atom
ClassAtom (PrefixMap -> Maybe String -> Element -> ClassExpression
getClassExpression PrefixMap
pm Maybe String
b Element
clExpr) (PrefixMap -> Maybe String -> Element -> IndividualArg
getIArg PrefixMap
pm Maybe String
b Element
iarg)
    "DataRangeAtom" ->
        let [dr :: Element
dr, darg :: Element
darg] = Element -> [Element]
elChildren Element
e
        in DataRange -> DataArg -> Atom
DataRangeAtom (PrefixMap -> Maybe String -> Element -> DataRange
getDataRange PrefixMap
pm Maybe String
b Element
dr) (PrefixMap -> Maybe String -> Element -> DataArg
getDArg PrefixMap
pm Maybe String
b Element
darg)
    "ObjectPropertyAtom" ->
        let [obExpr :: Element
obExpr, iarg1 :: Element
iarg1, iarg2 :: Element
iarg2] = Element -> [Element]
elChildren Element
e
        in ObjectPropertyExpression -> IndividualArg -> IndividualArg -> Atom
ObjectPropertyAtom
            (PrefixMap -> Maybe String -> Element -> ObjectPropertyExpression
getObjProp PrefixMap
pm Maybe String
b Element
obExpr)
            (PrefixMap -> Maybe String -> Element -> IndividualArg
getIArg PrefixMap
pm Maybe String
b Element
iarg1)
            (PrefixMap -> Maybe String -> Element -> IndividualArg
getIArg PrefixMap
pm Maybe String
b Element
iarg2)
    "DataPropertyAtom" ->
        let [dpExp :: Element
dpExp, iarg :: Element
iarg, darg :: Element
darg] = Element -> [Element]
elChildren Element
e
        in IRI -> IndividualArg -> DataArg -> Atom
DataPropertyAtom
            (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
dpExp)
            (PrefixMap -> Maybe String -> Element -> IndividualArg
getIArg PrefixMap
pm Maybe String
b Element
iarg)
            (PrefixMap -> Maybe String -> Element -> DataArg
getDArg PrefixMap
pm Maybe String
b Element
darg)
    "BuiltInAtom" ->
        let dargs :: [DataArg]
dargs = PrefixMap -> Maybe String -> Element -> DataArg
getDArg PrefixMap
pm Maybe String
b (Element -> DataArg) -> [Element] -> [DataArg]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> [Element]
elChildren Element
e
        in IRI -> [DataArg] -> Atom
BuiltInAtom (PrefixMap -> Maybe String -> Element -> IRI
getIRI PrefixMap
pm Maybe String
b Element
e) [DataArg]
dargs
    "SameIndividualAtom" ->
        let [iarg1 :: IndividualArg
iarg1, iarg2 :: IndividualArg
iarg2] = PrefixMap -> Maybe String -> Element -> IndividualArg
getIArg PrefixMap
pm Maybe String
b (Element -> IndividualArg) -> [Element] -> [IndividualArg]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> [Element]
elChildren Element
e
        in IndividualArg -> IndividualArg -> Atom
SameIndividualAtom IndividualArg
iarg1 IndividualArg
iarg2
    "DifferentIndividualsAtom" ->
        let [iarg1 :: IndividualArg
iarg1, iarg2 :: IndividualArg
iarg2] = PrefixMap -> Maybe String -> Element -> IndividualArg
getIArg PrefixMap
pm Maybe String
b (Element -> IndividualArg) -> [Element] -> [IndividualArg]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Element -> [Element]
elChildren Element
e
        in IndividualArg -> IndividualArg -> Atom
DifferentIndividualsAtom IndividualArg
iarg1 IndividualArg
iarg2
    _ ->  String -> Atom
forall t. String -> t
err (String -> Atom) -> String -> Atom
forall a b. (a -> b) -> a -> b
$ "Unexpected element '" String -> String -> String
forall a. [a] -> [a] -> [a]
++ Element -> String
getName Element
e String -> String -> String
forall a. [a] -> [a] -> [a]
++ "'."
    


getRuleAxiom :: GA.PrefixMap -> XMLBase -> Element -> Axiom
getRuleAxiom :: PrefixMap -> Maybe String -> Element -> Axiom
getRuleAxiom pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = case Element -> String
getName Element
e of
    "DLSafeRule" ->
        let as :: AxiomAnnotations
as = PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e
            atoms :: String -> [Element]
atoms = Element -> [Element]
elChildren (Element -> [Element])
-> (String -> Element) -> String -> [Element]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Element -> Element
`filterC` Element
e)
            bd :: [Atom]
bd = PrefixMap -> Maybe String -> Element -> Atom
getAtom PrefixMap
pm Maybe String
b (Element -> Atom) -> [Element] -> [Atom]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> [Element]
atoms "Body"
            hd :: [Atom]
hd = PrefixMap -> Maybe String -> Element -> Atom
getAtom PrefixMap
pm Maybe String
b (Element -> Atom) -> [Element] -> [Atom]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> [Element]
atoms "Head"
        in Rule -> Axiom
Rule (Rule -> Axiom) -> Rule -> Axiom
forall a b. (a -> b) -> a -> b
$ AxiomAnnotations -> [Atom] -> [Atom] -> Rule
DLSafeRule AxiomAnnotations
as [Atom]
bd [Atom]
hd
    s :: String
s -> String -> Axiom
forall t. String -> t
err (String -> Axiom) -> String -> Axiom
forall a b. (a -> b) -> a -> b
$ "Unexpected element '" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ "'."


getOnlyAxioms :: GA.PrefixMap -> XMLBase -> Element -> [Axiom]
getOnlyAxioms :: PrefixMap -> Maybe String -> Element -> [Axiom]
getOnlyAxioms pm :: PrefixMap
pm b :: Maybe String
b e :: Element
e = (Element -> Axiom) -> [Element] -> [Axiom]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> Axiom
getDeclaration PrefixMap
pm Maybe String
b) ([Element] -> [Axiom]) -> [Element] -> [Axiom]
forall a b. (a -> b) -> a -> b
$ (QName -> Bool) -> Element -> [Element]
filterChildrenName QName -> Bool
isNotSmth Element
e

getImports :: GA.PrefixMap -> XMLBase -> Element -> DirectlyImportsDocuments
getImports :: PrefixMap -> Maybe String -> Element -> [IRI]
getImports m :: PrefixMap
m b :: Maybe String
b e :: Element
e = (Element -> IRI) -> [Element] -> [IRI]
forall a b. (a -> b) -> [a] -> [b]
map (PrefixMap -> Maybe String -> Element -> IRI
contentIRI PrefixMap
m Maybe String
b) ([Element] -> [IRI]) -> [Element] -> [IRI]
forall a b. (a -> b) -> a -> b
$ String -> Element -> [Element]
filterCh String
importK Element
e

get1Map :: Element -> (String, String)
get1Map :: Element -> (String, String)
get1Map e :: Element
e =
  let [pref :: String
pref, pmap :: String
pmap] = (Attr -> String) -> [Attr] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Attr -> String
attrVal ([Attr] -> [String]) -> [Attr] -> [String]
forall a b. (a -> b) -> a -> b
$ Element -> [Attr]
elAttribs Element
e
  in (String
pref, String
pmap)

getPrefixMap :: Element -> GA.PrefixMap
getPrefixMap :: Element -> PrefixMap
getPrefixMap e :: Element
e = PrefixMap -> PrefixMap
changePrefixMapTypeToGA (PrefixMap -> PrefixMap) -> PrefixMap -> PrefixMap
forall a b. (a -> b) -> a -> b
$ (String -> String) -> PrefixMap -> PrefixMap
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (\x :: String
x -> "<" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ ">") (PrefixMap -> PrefixMap) -> PrefixMap -> PrefixMap
forall a b. (a -> b) -> a -> b
$ [(String, String)] -> PrefixMap
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(String, String)] -> PrefixMap)
-> [(String, String)] -> PrefixMap
forall a b. (a -> b) -> a -> b
$ (Element -> (String, String)) -> [Element] -> [(String, String)]
forall a b. (a -> b) -> [a] -> [b]
map Element -> (String, String)
get1Map ([Element] -> [(String, String)])
-> [Element] -> [(String, String)]
forall a b. (a -> b) -> a -> b
$ String -> Element -> [Element]
filterCh "Prefix" Element
e

getOntologyIRI :: XMLBase -> Element -> Maybe IRI
getOntologyIRI :: Maybe String -> Element -> Maybe IRI
getOntologyIRI b :: Maybe String
b e :: Element
e =
  let oi :: Maybe String
oi = QName -> Element -> Maybe String
findAttr (String -> QName
unqual "ontologyIRI") Element
e
  in Maybe String
oi Maybe String -> (String -> Maybe IRI) -> Maybe IRI
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Maybe String -> String -> Maybe IRI
getIRIWithResolvedBase Maybe String
b

getVersionIRI :: XMLBase -> Element -> Maybe IRI
getVersionIRI :: Maybe String -> Element -> Maybe IRI
getVersionIRI b :: Maybe String
b e :: Element
e =
  let vi :: Maybe String
vi = QName -> Element -> Maybe String
findAttr (String -> QName
unqual "versionIRI") Element
e
  in Maybe String
vi Maybe String -> (String -> Maybe IRI) -> Maybe IRI
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Maybe String -> String -> Maybe IRI
getIRIWithResolvedBase Maybe String
b

getBase :: Element -> XMLBase
getBase :: Element -> Maybe String
getBase e :: Element
e = (QName -> Bool) -> Element -> Maybe String
vFindAttrBy (String -> QName -> Bool
isSmth "base") Element
e

-- | parses an ontology document
xmlBasicSpec :: Map.Map String String -> Element -> OntologyDocument
xmlBasicSpec :: PrefixMap -> Element -> OntologyDocument
xmlBasicSpec imap :: PrefixMap
imap e :: Element
e =
    let b :: Maybe String
b = Element -> Maybe String
getBase Element
e
        pm :: PrefixMap
pm = PrefixMap -> PrefixMap
changePrefixMapTypeToGA PrefixMap
imap PrefixMap -> PrefixMap -> PrefixMap
forall k a. Ord k => Map k a -> Map k a -> Map k a
`Map.union` Element -> PrefixMap
getPrefixMap Element
e
        ax :: [Axiom]
ax = PrefixMap -> Maybe String -> Element -> [Axiom]
getOnlyAxioms PrefixMap
pm Maybe String
b Element
e
    in
        OntologyMetadata -> PrefixMap -> Ontology -> OntologyDocument
OntologyDocument
            (OntologySyntaxType -> OntologyMetadata
OntologyMetadata OntologySyntaxType
XML)
            PrefixMap
pm
            (Ontology -> OntologyDocument) -> Ontology -> OntologyDocument
forall a b. (a -> b) -> a -> b
$ Maybe IRI
-> Maybe IRI -> [IRI] -> AxiomAnnotations -> [Axiom] -> Ontology
Ontology
                (Maybe String -> Element -> Maybe IRI
getOntologyIRI Maybe String
b Element
e)
                (Maybe String -> Element -> Maybe IRI
getVersionIRI Maybe String
b Element
e)
                (PrefixMap -> Maybe String -> Element -> [IRI]
getImports PrefixMap
pm Maybe String
b Element
e)
                (PrefixMap -> Maybe String -> Element -> AxiomAnnotations
getAllAnnos PrefixMap
pm Maybe String
b Element
e)
                [Axiom]
ax