AS.hs revision 863fa65ac095659c6da1cde7fe7b839f1e7f60f9
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder{- |
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederModule : $Header$
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerCopyright : (c) C. Maeder
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederLicense : GPLv2 or higher, see LICENSE.txt
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian Maeder
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederMaintainer : Christian.Maeder@dfki.de
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederStability : provisional
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederPortability : portable
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian Maeder
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederOWL 2 Functional Syntax constructs
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian Maeder
9d0567bda351efa4286f38e85fb3e41ecd3683eaChristian MaederReferences:
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder <http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#Functional-Style_Syntax>
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder <http://www.w3.org/TR/owl2-manchester-syntax/>
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder-}
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder
9f93b2a8b552789cd939d599504d39732672dc84Christian Maedermodule OWL2.AS where
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maederimport Common.Id
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maederimport Common.Keywords
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maederimport OWL2.ColonKeywords
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maederimport OWL2.Keywords
d3f192025f2836285d9705a959542350e057f281Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport Data.Char (intToDigit)
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian Maederimport Data.List
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maederimport Data.Maybe
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederimport qualified Data.Map as Map
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata IRIType = Full | Abbreviated | NodeID
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder deriving (Show, Eq, Ord)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder{- | full or abbreviated IRIs with a possible uri for the prefix
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder or a local part following a hash sign -}
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata QName = QN
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder { namePrefix :: String
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder , localPart :: String
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder -- ^ the local part of a qualified name \"namePrefix:localPart\"
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder , iriType :: IRIType
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder , expandedIRI :: String
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder -- ^ the associated namespace uri (not printed)
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder , iriPos :: Range
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder } deriving Show
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Eq QName where
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder p == q = compare p q == EQ
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maederinstance Ord QName where
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder compare n1 n2 -- compare fully expanded names only
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder
1a38107941725211e7c3f051f7a8f5e12199f03acmaederinstance GetRange QName where
20bd79f8844604c145510c616fecdaf47eba2fdbChristian Maeder getRange = iriPos
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder
1a38107941725211e7c3f051f7a8f5e12199f03acmaedershowQN :: QName -> String
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian MaedershowQN q = (if iriType q /= Abbreviated then showQI else showQU) q
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder-- | show QName as abbreviated iri
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaedershowQU :: QName -> String
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaedershowQU (QN pre local _ _ _) =
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder if null pre then local else pre ++ ":" ++ local
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder-- | show QName in ankle brackets as full iris
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaedershowQI :: QName -> String
ab0274ab68a174d3e92235b4c4ca865c03901583Christian MaedershowQI = ('<' :) . (++ ">") . showQU
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian MaedernullQName :: QName
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedernullQName = QN "" "" Abbreviated "" nullRange
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder
9f93b2a8b552789cd939d599504d39732672dc84Christian MaederdummyQName :: QName
9f93b2a8b552789cd939d599504d39732672dc84Christian MaederdummyQName =
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder QN "http" "//www.dfki.de/sks/hets/ontology/unamed" Full "" nullRange
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedermkQName :: String -> QName
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedermkQName s = nullQName { localPart = s }
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian Maeder
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian MaedersetQRange :: Range -> QName -> QName
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedersetQRange r q = q { iriPos = r }
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedersetPrefix :: String -> QName -> QName
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian MaedersetPrefix s q = q { namePrefix = s }
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder
9f93b2a8b552789cd939d599504d39732672dc84Christian MaedersetFull :: QName -> QName
23a0d43ca980983c7d7aebaa9f03bfe120be7de8Christian MaedersetFull q = q {iriType = Full}
ab0274ab68a174d3e92235b4c4ca865c03901583Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype IRI = QName
d3f192025f2836285d9705a959542350e057f281Christian Maeder
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder-- | checks if an IRI is an anonymous individual
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederisAnonymous :: IRI -> Bool
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederisAnonymous iri = iriType iri == NodeID
d3f192025f2836285d9705a959542350e057f281Christian Maeder
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder-- | checks if a string (bound to be localPart of an IRI) contains \":\/\/\"
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedercssIRI :: String -> IRIType
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedercssIRI iri = if isInfixOf "://" iri then Full else Abbreviated
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
38504dc968167ba2e82dd568edeae8d6af4dc145Christian Maeder-- | prefix -> localname
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedertype PrefixMap = Map.Map String String
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaederpredefPrefixes :: PrefixMap
66ea26416f702f5e00759ffc767f0f785cc86058Christian MaederpredefPrefixes = Map.fromList
d3f192025f2836285d9705a959542350e057f281Christian Maeder [ ("owl", "http://www.w3.org/2002/07/owl#")
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder , ("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder , ("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder , ("xsd", "http://www.w3.org/2001/XMLSchema#")
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder , ("", showQU dummyQName ++ "#") ]
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
d3f192025f2836285d9705a959542350e057f281Christian Maedertype LexicalForm = String
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maedertype LanguageTag = String
499b6cb3ab95a336a324545123e18f387ee4d2a3Christian Maedertype ImportIRI = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype OntologyIRI = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype Class = IRI
d3f192025f2836285d9705a959542350e057f281Christian Maedertype Datatype = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype ObjectProperty = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype DataProperty = IRI
d3f192025f2836285d9705a959542350e057f281Christian Maedertype AnnotationProperty = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype NamedIndividual = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maedertype Individual = IRI
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
d3f192025f2836285d9705a959542350e057f281Christian Maederdata EquivOrDisjoint = Equivalent | Disjoint
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder deriving (Show, Eq, Ord)
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedershowEquivOrDisjoint :: EquivOrDisjoint -> String
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedershowEquivOrDisjoint ed = case ed of
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder Equivalent -> equivalentToC
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder Disjoint -> disjointWithC
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata DomainOrRange = ADomain | ARange
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder deriving (Show, Eq, Ord)
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
d3f192025f2836285d9705a959542350e057f281Christian MaedershowDomainOrRange :: DomainOrRange -> String
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedershowDomainOrRange dr = case dr of
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder ADomain -> domainC
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder ARange -> rangeC
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata SameOrDifferent = Same | Different
d3f192025f2836285d9705a959542350e057f281Christian Maeder deriving (Show, Eq, Ord)
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder
df15a183ca8bf1c25db69775979905198d7cc8bbChristian MaedershowSameOrDifferent :: SameOrDifferent -> String
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian MaedershowSameOrDifferent sd = case sd of
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder Same -> sameAsC
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder Different -> differentFromC
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maederdata Relation =
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder EDRelation EquivOrDisjoint
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder | SubPropertyOf
d3f192025f2836285d9705a959542350e057f281Christian Maeder | InverseOf
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder | SubClass
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder | Types
2119c0874c93fc1cdfea381bcfea69e8fdb8b6e2Christian Maeder | DRRelation DomainOrRange
df15a183ca8bf1c25db69775979905198d7cc8bbChristian Maeder | SDRelation SameOrDifferent
deriving (Show, Eq, Ord)
showRelation :: Relation -> String
showRelation r = case r of
EDRelation ed -> showEquivOrDisjoint ed
SubPropertyOf -> subPropertyOfC
InverseOf -> inverseOfC
SubClass -> subClassOfC
Types -> typesC
DRRelation dr -> showDomainOrRange dr
SDRelation sd -> showSameOrDifferent sd
getED :: Relation -> EquivOrDisjoint
getED r = case r of
EDRelation ed -> ed
_ -> error "not domain or range"
getDR :: Relation -> DomainOrRange
getDR r = case r of
DRRelation dr -> dr
_ -> error "not domain or range"
getSD :: Relation -> SameOrDifferent
getSD s = case s of
SDRelation sd -> sd
_ -> error "not same or different"
data Character =
Functional
| InverseFunctional
| Reflexive
| Irreflexive
| Symmetric
| Asymmetric
| Antisymmetric
| Transitive
deriving (Enum, Bounded, Show, Eq, Ord)
data PositiveOrNegative = Positive | Negative
deriving (Show, Eq, Ord)
data QuantifierType = AllValuesFrom | SomeValuesFrom
deriving (Show, Eq, Ord)
showQuantifierType :: QuantifierType -> String
showQuantifierType ty = case ty of
AllValuesFrom -> onlyS
SomeValuesFrom -> someS
-- * Predefined IRIs
predefClass :: [String]
predefClass = [thing, nothing]
isThing :: IRI -> Bool
isThing = isOWLPredef predefClass
predefObjProp :: [String]
predefObjProp = [topObjProp, bottomObjProp]
isPredefObjProp :: IRI -> Bool
isPredefObjProp = isOWLPredef predefObjProp
predefDataProp :: [String]
predefDataProp = [topDataProp, bottomDataProp]
isPredefDataProp :: IRI -> Bool
isPredefDataProp = isOWLPredef predefDataProp
predefRDFSAnnoProps :: [String]
predefRDFSAnnoProps = [label, comment, seeAlso, isDefinedBy]
predefOWLAnnoProps :: [String]
predefOWLAnnoProps = [deprecated, versionInfo, priorVersion,
backwardCompatibleWith, incompatibleWith]
isPredefAnnoProp :: IRI -> Bool
isPredefAnnoProp iri = isOWLPredef predefOWLAnnoProps iri
|| checkPredef predefRDFSAnnoProps "rdfs" iri
xsdNumbers :: [String]
xsdNumbers = [integerS, negativeIntegerS, nonNegativeIntegerS,
nonPositiveIntegerS, positiveIntegerS, decimalS, doubleS, floatS,
longS, intS, shortS, byteS, unsignedLongS, unsignedIntS, unsignedShortS,
unsignedByteS]
owlNumbers :: [String]
owlNumbers = [realS, rationalS]
xsdStrings :: [String]
xsdStrings = [stringS, ncNameS, nameS, nmTokenS, tokenS, languageS,
normalizedStringS]
xsdKeys :: [String]
xsdKeys = [booleanS, dATAS, hexBinaryS, base64BinaryS,
dateTimeS, dateTimeStampS, anyURI] ++ xsdNumbers ++ xsdStrings
nonXSDKeys :: [String]
nonXSDKeys = owlNumbers ++ [xmlLiteral, rdfsLiteral]
datatypeKeys :: [String]
datatypeKeys = xsdKeys ++ nonXSDKeys
isDatatypeKey :: IRI -> Bool
isDatatypeKey iri = any (\ (l, p) -> checkPredef l p iri) [(xsdKeys, "xsd"),
(owlNumbers, "owl"), ([xmlLiteral], "rdf"), ([rdfsLiteral], "rdfs")]
checkPredef :: [String] -> String -> IRI -> Bool
checkPredef sl pref u =
localPart u `elem` sl && elem (namePrefix u) ["", pref]
|| showQU u `elem` map (Map.findWithDefault
(error $ "not predefined prefix: " ++ show pref)
pref (predefPrefixes `Map.difference`
Map.fromList [("", showQU dummyQName ++ "#")]) ++) sl
isOWLPredef :: [String] -> IRI -> Bool
isOWLPredef sl = checkPredef sl "owl"
-- | sets the correct prefix for the predefined datatypes
setDatatypePrefix :: IRI -> IRI
setDatatypePrefix iri = let lp = localPart iri in
if lp `elem` xsdKeys
then setPrefix "xsd" iri
else if lp `elem` owlNumbers
then setPrefix "owl" iri
else case lp of
"XMLLiteral" -> setPrefix "rdf" iri
"Literal" -> setPrefix "rdfs" iri
_ -> error $ showQU iri ++ " is not a predefined datatype"
-- | checks if the IRI is part of the built-in ones and puts the correct prefix
setReservedPrefix :: IRI -> IRI
setReservedPrefix iri
| isDatatypeKey iri && null (namePrefix iri) = setDatatypePrefix iri
| (isThing iri || isPredefAnnoProp iri || isPredefDataProp iri
|| isPredefObjProp iri) && null (namePrefix iri) = setPrefix "owl" iri
| otherwise = iri
{- | returns the name of the predefined IRI (e.g <xsd:string> returns "string"
or <http://www.w3.org/2002/07/owl#real> returns "real") -}
getPredefName :: IRI -> String
getPredefName iri =
if namePrefix iri `elem` ["", "xsd", "rdf", "rdfs", "owl"]
then localPart iri
else case catMaybes $ map (flip stripPrefix $ showQU iri)
$ Map.elems predefPrefixes of
[s] -> s
_ -> error $ showQU iri ++ " is not a predefined IRI"
data DatatypeCat = OWL2Number | OWL2String | OWL2Bool | Other
deriving (Show, Eq, Ord)
getDatatypeCat :: IRI -> DatatypeCat
getDatatypeCat iri = case isDatatypeKey iri of
True
| hasPrefXSD [booleanS] iri -> OWL2Bool
| hasPrefXSD xsdNumbers iri || checkPredef owlNumbers "owl" iri
-> OWL2Number
| hasPrefXSD xsdStrings iri -> OWL2String
| otherwise -> Other
False -> Other
hasPrefXSD :: [String] -> IRI -> Bool
hasPrefXSD sl = checkPredef sl "xsd"
data DatatypeFacet =
LENGTH
| MINLENGTH
| MAXLENGTH
| PATTERN
| LANGRANGE
| MININCLUSIVE
| MINEXCLUSIVE
| MAXINCLUSIVE
| MAXEXCLUSIVE
| TOTALDIGITS
| FRACTIONDIGITS
deriving (Show, Eq, Ord)
showFacet :: DatatypeFacet -> String
showFacet df = case df of
LENGTH -> lengthS
MINLENGTH -> minLengthS
MAXLENGTH -> maxLengthS
PATTERN -> patternS
LANGRANGE -> langRangeS
MININCLUSIVE -> lessEq
MINEXCLUSIVE -> lessS
MAXINCLUSIVE -> greaterEq
MAXEXCLUSIVE -> greaterS
TOTALDIGITS -> digitsS
FRACTIONDIGITS -> fractionS
-- * Cardinalities
data CardinalityType = MinCardinality | MaxCardinality | ExactCardinality
deriving (Show, Eq, Ord)
showCardinalityType :: CardinalityType -> String
showCardinalityType ty = case ty of
MinCardinality -> minS
MaxCardinality -> maxS
ExactCardinality -> exactlyS
data Cardinality a b = Cardinality CardinalityType Int a (Maybe b)
deriving (Show, Eq, Ord)
data JunctionType = UnionOf | IntersectionOf
deriving (Show, Eq, Ord)
type ConstrainingFacet = IRI
type RestrictionValue = Literal
-- * ENTITIES
data Entity = Entity EntityType IRI deriving (Show, Eq, Ord)
instance GetRange Entity where
getRange (Entity _ iri) = iriPos iri
data EntityType =
Datatype
| Class
| ObjectProperty
| DataProperty
| AnnotationProperty
| NamedIndividual
deriving (Enum, Bounded, Show, Read, Eq, Ord)
showEntityType :: EntityType -> String
showEntityType e = case e of
Datatype -> datatypeC
Class -> classC
ObjectProperty -> objectPropertyC
DataProperty -> dataPropertyC
AnnotationProperty -> annotationPropertyC
NamedIndividual -> individualC
entityTypes :: [EntityType]
entityTypes = [minBound .. maxBound]
cutIRI :: Entity -> IRI
cutIRI (Entity _ iri) = iri
-- * LITERALS
data TypedOrUntyped = Typed Datatype | Untyped (Maybe LanguageTag)
deriving (Show, Eq, Ord)
data Literal = Literal LexicalForm TypedOrUntyped | NumberLit FloatLit
deriving (Show, Eq, Ord)
-- | non-negative integers given by the sequence of digits
data NNInt = NNInt [Int] deriving (Eq, Ord)
instance Show NNInt where
show (NNInt l) = map intToDigit l
zeroNNInt :: NNInt
zeroNNInt = NNInt []
isZeroNNInt :: NNInt -> Bool
isZeroNNInt (NNInt l) = null l
data IntLit = IntLit
{ absInt :: NNInt
, isNegInt :: Bool }
deriving (Eq, Ord)
instance Show IntLit where
show (IntLit n b) = (if b then ('-' :) else id) $ show n
zeroInt :: IntLit
zeroInt = IntLit zeroNNInt False
isZeroInt :: IntLit -> Bool
isZeroInt (IntLit n _) = isZeroNNInt n
negNNInt :: Bool -> NNInt -> IntLit
negNNInt b n = IntLit n b
negInt :: IntLit -> IntLit
negInt (IntLit n b) = IntLit n $ not b
data DecLit = DecLit
{ truncDec :: IntLit
, fracDec :: NNInt }
deriving (Eq, Ord)
instance Show DecLit where
show (DecLit t f) = show t
++ if isZeroNNInt f then "" else
'.' : show f
isDecInt :: DecLit -> Bool
isDecInt = isZeroNNInt . fracDec
negDec :: Bool -> DecLit -> DecLit
negDec b (DecLit t f) = DecLit (if b then negInt t else t) f
data FloatLit = FloatLit
{ floatBase :: DecLit
, floatExp :: IntLit }
deriving (Eq, Ord)
instance Show FloatLit where
show (FloatLit b e) = show b
++ if isZeroInt e then "" else
'E' : show e ++ "F"
isFloatDec :: FloatLit -> Bool
isFloatDec = isZeroInt . floatExp
isFloatInt :: FloatLit -> Bool
isFloatInt f = isFloatDec f && isDecInt (floatBase f)
floatToInt :: FloatLit -> IntLit
floatToInt = truncDec . floatBase
intToDec :: IntLit -> DecLit
intToDec i = DecLit i zeroNNInt
decToFloat :: DecLit -> FloatLit
decToFloat d = FloatLit d zeroInt
intToFloat :: IntLit -> FloatLit
intToFloat = decToFloat . intToDec
abInt :: IntLit -> IntLit
abInt int = int {isNegInt = False}
abDec :: DecLit -> DecLit
abDec dec = dec {truncDec = abInt $ truncDec dec}
abFloat :: FloatLit -> FloatLit
abFloat f = f {floatBase = abDec $ floatBase f}
isNegDec :: DecLit -> Bool
isNegDec d = isNegInt $ truncDec d
numberName :: FloatLit -> String
numberName f
| isFloatInt f = integerS
| isFloatDec f = decimalS
| otherwise = floatS
cTypeS :: String
cTypeS = "^^"
-- * PROPERTY EXPRESSIONS
type InverseObjectProperty = ObjectPropertyExpression
data ObjectPropertyExpression = ObjectProp ObjectProperty
| ObjectInverseOf InverseObjectProperty
deriving (Show, Eq, Ord)
type DataPropertyExpression = DataProperty
-- * DATA RANGES
data DataRange =
DataType Datatype [(ConstrainingFacet, RestrictionValue)]
| DataJunction JunctionType [DataRange]
| DataComplementOf DataRange
| DataOneOf [Literal]
deriving (Show, Eq, Ord)
-- * CLASS EXPERSSIONS
data ClassExpression =
Expression Class
| ObjectJunction JunctionType [ClassExpression]
| ObjectComplementOf ClassExpression
| ObjectOneOf [Individual]
| ObjectValuesFrom QuantifierType ObjectPropertyExpression ClassExpression
| ObjectHasValue ObjectPropertyExpression Individual
| ObjectHasSelf ObjectPropertyExpression
| ObjectCardinality (Cardinality ObjectPropertyExpression ClassExpression)
| DataValuesFrom QuantifierType DataPropertyExpression DataRange
| DataHasValue DataPropertyExpression Literal
| DataCardinality (Cardinality DataPropertyExpression DataRange)
deriving (Show, Eq, Ord)
-- * ANNOTATIONS
data Annotation = Annotation [Annotation] AnnotationProperty AnnotationValue
deriving (Show, Eq, Ord)
data AnnotationValue =
AnnValue IRI
| AnnValLit Literal
deriving (Show, Eq, Ord)