AS.hs revision 5a3ae0a9224276de25e709ef8788c1b9716cd206
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu{- |
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : $Header$
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuCopyright : (c) C. Maeder
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuLicense : GPLv2 or higher, see LICENSE.txt
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuMaintainer : Christian.Maeder@dfki.de
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuStability : provisional
402ffc909b645ddb2d5c76343bf74a6cb33c6205Christian MaederPortability : portable
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuOWL 2 Functional Syntax constructs
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu
90d7cac36f60438bd35124e3389b5bce6d114b46Christian MaederReferences:
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu <http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#Functional-Style_Syntax>
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu <http://www.w3.org/TR/owl2-manchester-syntax/>
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu-}
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescumodule OWL2.AS where
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederimport Common.Id
803425dfe6a5da41b9cea480788980fa104545adMihai Codescuimport Common.Keywords
392634badbe11a21c7825ee0e1ee132220a2539eMihai Codescu
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederimport OWL2.ColonKeywords
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescuimport OWL2.Keywords
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescuimport Data.List
5418aa59492005c2ca40436ab84c4029cd2922a5Christian Maederimport qualified Data.Map as Map
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowski
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescudata IRIType = Full | Abbreviated | NodeID
5418aa59492005c2ca40436ab84c4029cd2922a5Christian Maeder deriving (Show, Eq, Ord)
5418aa59492005c2ca40436ab84c4029cd2922a5Christian Maeder
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu{- | full or abbreviated IRIs with a possible uri for the prefix
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescu or a local part following a hash sign -}
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescudata QName = QN
3bc502518f75cd5a21aa2f608a31f50c19134db0Christian Maeder { namePrefix :: String
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu , localPart :: String
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu -- ^ the local part of a qualified name \"namePrefix:localPart\"
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu , iriType :: IRIType
7b5ba6a2f3990cf508f90e55e1d59068e6aaa6a3Mihai Codescu , expandedIRI :: String
7b5ba6a2f3990cf508f90e55e1d59068e6aaa6a3Mihai Codescu -- ^ the associated namespace uri (not printed)
7b5ba6a2f3990cf508f90e55e1d59068e6aaa6a3Mihai Codescu , iriPos :: Range
7b5ba6a2f3990cf508f90e55e1d59068e6aaa6a3Mihai Codescu } deriving Show
7b5ba6a2f3990cf508f90e55e1d59068e6aaa6a3Mihai Codescu
7b5ba6a2f3990cf508f90e55e1d59068e6aaa6a3Mihai Codescuinstance Eq QName where
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu p == q = compare p q == EQ
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescuinstance Ord QName where
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu compare (QN p1 l1 b1 n1 _) (QN p2 l2 b2 n2 _) =
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder if null n1 || null n2 then compare (b1, p1, l1) (b2, p2, l2) else
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu compare n1 n2 -- compare fully expanded names only
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescuinstance GetRange QName where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder getRange = iriPos
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescushowQN :: QName -> String
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescushowQN q = (if iriType q /= Abbreviated then showQI else showQU) q
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu-- | show QName as abbreviated iri
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescushowQU :: QName -> String
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescushowQU (QN pre local _ _ _) =
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu if null pre then local else pre ++ ":" ++ local
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu-- | show QName in ankle brackets as full iris
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescushowQI :: QName -> String
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescushowQI = ('<' :) . (++ ">") . showQU
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescunullQName :: QName
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescunullQName = QN "" "" Abbreviated "" nullRange
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescudummyQName :: QName
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescudummyQName =
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu QN "http" "//www.dfki.de/sks/hets/ontology/unamed" Full "" nullRange
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedermkQName :: String -> QName
272a5a82588ab4115dac5eb81d43d74929e99ad7Till MossakowskimkQName s = nullQName { localPart = s }
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescusetQRange :: Range -> QName -> QName
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersetQRange r q = q { iriPos = r }
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescusetPrefix :: String -> QName -> QName
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescusetPrefix s q = q { namePrefix = s }
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescusetReservedPrefix :: QName -> QName
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescusetReservedPrefix iri
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu | isDatatypeKey iri = setPrefix "xsd" iri
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu | isThing iri = setPrefix "owl" iri
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu | otherwise = iri
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescusetFull :: QName -> QName
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersetFull q = q {iriType = Full}
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescutype IRI = QName
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu-- | checks if an IRI is an anonymous individual
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederisAnonymous :: IRI -> Bool
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederisAnonymous iri = iriType iri == NodeID
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederisThing :: IRI -> Bool
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescuisThing u = elem (localPart u) ["Thing", "Nothing"] &&
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder elem (namePrefix u) ["", "owl"]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu-- | checks if a string (bound to be localPart of an IRI) contains \":\/\/\"
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedercssIRI :: String -> IRIType
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedercssIRI iri = if isInfixOf "://" iri then Full else Abbreviated
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu-- | prefix -> localname
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescutype PrefixMap = Map.Map String String
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu
96d8cf9817eeb0d26cba09ca192fc5a33e27bc09mcodescutype LexicalForm = String
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescutype LanguageTag = String
803425dfe6a5da41b9cea480788980fa104545adMihai Codescutype ImportIRI = IRI
96d8cf9817eeb0d26cba09ca192fc5a33e27bc09mcodescutype OntologyIRI = IRI
803425dfe6a5da41b9cea480788980fa104545adMihai Codescutype Class = IRI
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowskitype Datatype = IRI
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowskitype ObjectProperty = IRI
80875f917d741946a39d0ec0b5721e46ba609823Till Mossakowskitype DataProperty = IRI
803425dfe6a5da41b9cea480788980fa104545adMihai Codescutype AnnotationProperty = IRI
803425dfe6a5da41b9cea480788980fa104545adMihai Codescutype NamedIndividual = IRI
803425dfe6a5da41b9cea480788980fa104545adMihai Codescutype Individual = IRI
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederdata EquivOrDisjoint = Equivalent | Disjoint
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder deriving (Show, Eq, Ord)
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu
803425dfe6a5da41b9cea480788980fa104545adMihai CodescushowEquivOrDisjoint :: EquivOrDisjoint -> String
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedershowEquivOrDisjoint ed = case ed of
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu Equivalent -> equivalentToC
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu Disjoint -> disjointWithC
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederdata DomainOrRange = ADomain | ARange
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder deriving (Show, Eq, Ord)
b7f625188b6bf3d708b2a1b64a6cea7880708adbChristian Maeder
803425dfe6a5da41b9cea480788980fa104545adMihai CodescushowDomainOrRange :: DomainOrRange -> String
803425dfe6a5da41b9cea480788980fa104545adMihai CodescushowDomainOrRange dr = case dr of
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu ADomain -> domainC
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu ARange -> rangeC
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu
803425dfe6a5da41b9cea480788980fa104545adMihai Codescudata SameOrDifferent = Same | Different
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder deriving (Show, Eq, Ord)
96d8cf9817eeb0d26cba09ca192fc5a33e27bc09mcodescu
96d8cf9817eeb0d26cba09ca192fc5a33e27bc09mcodescushowSameOrDifferent :: SameOrDifferent -> String
803425dfe6a5da41b9cea480788980fa104545adMihai CodescushowSameOrDifferent sd = case sd of
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu Same -> sameAsC
96d8cf9817eeb0d26cba09ca192fc5a33e27bc09mcodescu Different -> differentFromC
b7f625188b6bf3d708b2a1b64a6cea7880708adbChristian Maeder
b7f625188b6bf3d708b2a1b64a6cea7880708adbChristian Maederdata Relation =
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder EDRelation EquivOrDisjoint
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder | SubPropertyOf
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu | InverseOf
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu | SubClass
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu | Types
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu | DRRelation DomainOrRange
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder | SDRelation SameOrDifferent
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu 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
-- | data type strings (some are not listed in the grammar)
datatypeKeys :: [String]
datatypeKeys =
[ booleanS
, dATAS
, decimalS
, floatS
, integerS
, negativeIntegerS
, nonNegativeIntegerS
, nonPositiveIntegerS
, positiveIntegerS
, stringS
, universalS
]
isDatatypeKey :: IRI -> Bool
isDatatypeKey u =
elem (localPart u) datatypeKeys && elem (namePrefix u) ["", "xsd"]
data DatatypeType = OWL2Int | OWL2String | OWL2Bool | Other
deriving (Show, Eq, Ord)
datatypeType :: IRI -> DatatypeType
datatypeType iri =
let lp = localPart iri
in case isDatatypeKey iri of
True
| lp == booleanS -> OWL2Bool
| lp `elem` [integerS, negativeIntegerS, nonNegativeIntegerS,
nonPositiveIntegerS, positiveIntegerS] -> OWL2Int
| lp == stringS -> OWL2String
| otherwise -> Other
False -> Other
data DatatypeFacet =
LENGTH
| MINLENGTH
| MAXLENGTH
| PATTERN
| 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
MININCLUSIVE -> lessEq
MINEXCLUSIVE -> lessS
MAXINCLUSIVE -> greaterEq
MAXEXCLUSIVE -> greaterS
TOTALDIGITS -> digitsS
FRACTIONDIGITS -> fractionS
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]
-- * LITERALS
data TypedOrUntyped = Typed Datatype | Untyped (Maybe LanguageTag)
deriving (Show, Eq, Ord)
data Literal = Literal LexicalForm TypedOrUntyped
deriving (Show, Eq, Ord)
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)