AS.hs revision a921ae1da1302f673204e7b63cdce01439a9bd5e
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz{-# LANGUAGE DeriveDataTypeable #-}
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz{- |
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzModule : $Header$
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzCopyright : (c) Heng Jiang, Uni Bremen 2004-2007
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzLicense : GPLv2 or higher, see LICENSE.txt
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzMaintainer : Christian.Maeder@dfki.de
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzStability : provisional
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzPortability : non-portable(deriving Typeable)
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzThis module defines all the data types for the functional style Syntax
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzof OWL 2
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst SchulzIt is modeled after the W3C document:
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz<http://www.w3.org/TR/2009/REC-owl2-syntax-20091027/#Functional-Style_Syntax>
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz-}
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzmodule OWL2.AS where
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport Common.Keywords
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport Common.Id (GetRange)
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport OWL.Keywords
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport OWL.ColonKeywords
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport qualified Data.Map as Map
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzimport Data.Typeable
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz{- | full or abbreviated IRIs with a possible uri for the prefix
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz or a local part following a hash sign -}
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulzdata QName = QN
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz { namePrefix :: String
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu -- ^ the name prefix part of a qualified name \"namePrefix:localPart\"
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz , localPart :: String
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz -- ^ the local part of a qualified name \"namePrefix:localPart\"
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz , isFullIri :: Bool
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz , namespaceUri :: String
fcd50ed0f526645ca50bad2170e3b98b911b7678Ewaryst Schulz -- ^ the associated namespace uri (not printed)
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu } deriving (Typeable, Show)
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavushowQN :: QName -> String
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavushowQN q = (if isFullIri q then showQI else showQU) q
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- | show QName as abbreviated iri
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst SchulzshowQU :: QName -> String
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavushowQU (QN pre local _ _) =
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu if null pre then local else pre ++ ":" ++ local
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- | show QName in ankle brackets as full iris
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavushowQI :: QName -> String
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavushowQI = ('<' :) . (++ ">") . showQU
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavunullQName :: QName
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavunullQName = QN "" "" False ""
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavudummyQName :: QName
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavudummyQName = QN "http" "//www.dfki.de/sks/hets/ontology/unamed" True ""
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavumkQName :: String -> QName
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavumkQName s = nullQName { localPart = s }
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Eq QName where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu p == q = compare p q == EQ
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance Ord QName where
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu compare (QN p1 l1 b1 n1) (QN p2 l2 b2 n2) =
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu if null n1 then
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu if null n2 then compare (b1, p1, l1) (b2, p2, l2) else LT
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu else if null n2 then GT else compare (b1, l1, n1) (b2, l2, n2)
3051a3502f027f3d7bb750a1d7a6b1b43cdd2a86Robert Savu
3051a3502f027f3d7bb750a1d7a6b1b43cdd2a86Robert Savutype IRIreference = QName
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype IRI = QName
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- | prefix -> localname
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype PrefixMap = Map.Map String String
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype NodeID = String
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype LexicalForm = String
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype LanguageTag = String
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype PrefixName = String
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype ImportIRI = IRI
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype OntologyIRI = IRI
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype Class = IRI
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype Datatype = IRI
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype ObjectProperty = IRI
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype DataProperty = IRI
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype AnnotationProperty = IRI
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype NamedIndividual = IRI
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype AnonymousIndividual = NodeID
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savudata Individual = NamedInd IRI | AnonymousIndividual AnonymousIndividual
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu deriving (Typeable, Show, Eq, Ord)
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu------------------------
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu-- ONTOLOGIES SYNTAX
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu------------------------
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savudata OntologyFile = OntologyFile
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu { prefixName :: PrefixMap
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu , ontology :: Ontology
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu } deriving (Typeable, Show, Eq, Ord)
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuinstance GetRange OntologyFile
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savudata Ontology = Ontology
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu { uri :: OntologyIRI
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu , importsList :: [ImportIRI]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu , annotationsList :: [Annotation]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu , axiomsList :: [Axiom]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu } deriving (Typeable, Show, Eq, Ord)
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savutype OntologyMap = Map.Map String OntologyFile
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz------------------------
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu-- SYMBOL ITEMS FOR HETS
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz------------------------
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulzdata SymbItems = SymbItems (Maybe EntityType) [IRI]
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu deriving (Typeable, Show, Eq)
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulzdata SymbMapItems = SymbMapItems (Maybe EntityType) [(IRI, Maybe IRI)]
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz deriving (Typeable, Show, Eq)
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz
-- | raw symbols
data RawSymb = ASymbol Entity | AnUri IRI deriving (Typeable, Show, Eq, Ord)
-------------------------
-- LITERALS
-------------------------
data TypedOrUntyped = Typed Datatype | Untyped (Maybe LanguageTag)
deriving (Typeable, Show, Eq, Ord)
data Literal = Literal LexicalForm TypedOrUntyped
deriving (Typeable, Show, Eq, Ord)
cTypeS :: String
cTypeS = "^^"
-- | a lexical representation either with an "^^" URI (typed) or
-- an optional language tag starting with "\@" (untyped)
--------------------------
-- PROPERTY EXPRESSIONS
--------------------------
type InverseObjectProperty = ObjectPropertyExpression
data ObjectPropertyExpression = ObjectProp ObjectProperty | ObjectInverseOf InverseObjectProperty
deriving (Typeable, Show, Eq, Ord)
type DataPropertyExpression = DataProperty
-- | data type strings (some are not listed in the grammar)
datatypeKeys :: [String]
datatypeKeys =
[ booleanS
, dATAS
, decimalS
, floatS
, integerS
, negativeIntegerS
, nonNegativeIntegerS
, nonPositiveIntegerS
, positiveIntegerS
, stringS
, universalS
]
--------------------------
-- DATA RANGES
--------------------------
data DatatypeFacet =
LENGTH
| MINLENGTH
| MAXLENGTH
| PATTERN
| MININCLUSIVE
| MINEXCLUSIVE
| MAXINCLUSIVE
| MAXEXCLUSIVE
| TOTALDIGITS
| FRACTIONDIGITS
deriving (Typeable, 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 DataRange
= DataType Datatype
| DataIntersectionOrUnionOf JunctionType [DataRange] -- at least two elements in the list
| DataComplementOf DataRange
| DataOneOf [Literal] -- at least one element in the list
| DatatypeRestriction Datatype [(ConstrainingFacet, RestrictionValue)] -- at least one element in the list
deriving (Typeable, Show, Eq, Ord)
data JunctionType = UnionOf | IntersectionOf deriving (Show, Eq, Ord)
type ConstrainingFacet = IRI
type RestrictionValue = Literal
---------------------------
-- CLASS EXPERSSIONS
---------------------------
data QuantifierType = AllValuesFrom | SomeValuesFrom deriving (Show, Eq, Ord)
showQuantifierType :: QuantifierType -> String
showQuantifierType ty = case ty of
AllValuesFrom -> onlyS
SomeValuesFrom -> someS
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 (Typeable, Show, Eq, Ord)
data ClassExpression =
Expression Class
| ObjectJunction JunctionType [ClassExpression] -- min. 2 ClassExpressions
| ObjectComplementOf ClassExpression
| ObjectOneOf [Individual] -- min. 1 Individual
| ObjectValuesFrom QuantifierType ObjectPropertyExpression ClassExpression
| ObjectHasValue ObjectPropertyExpression Individual
| ObjectHasSelf ObjectPropertyExpression
| ObjectCardinality (Cardinality ObjectPropertyExpression ClassExpression)
| DataValuesFrom
QuantifierType DataPropertyExpression [DataPropertyExpression] DataRange
| DataHasValue DataPropertyExpression Literal
| DataCardinality (Cardinality DataPropertyExpression DataRange)
deriving (Typeable, Show, Eq, Ord)
-------------------
-- ANNOTATIONS
-------------------
data Annotation = Annotation [Annotation] AnnotationProperty AnnotationValue
deriving (Typeable, Show, Eq, Ord)
data AnnotationAxiom
= AnnotationAssertion [Annotation] AnnotationProperty AnnotationSubject AnnotationValue
| SubAnnotationPropertyOf [Annotation] AnnotationProperty AnnotationProperty
| AnnotationPropertyDomainOrRange AnnotationDomainOrRange [Annotation] AnnotationProperty IRI
deriving (Typeable, Show, Eq, Ord)
data AnnotationDomainOrRange = AnnDomain | AnnRange deriving (Show, Eq, Ord)
data AnnotationSubject
= AnnSubIRI IRI
| AnnSubject AnonymousIndividual
deriving (Typeable, Show, Eq, Ord)
data AnnotationValue
= AnnValue AnonymousIndividual
| AnnValIRI IRI
| AnnValLit Literal
deriving (Typeable, Show, Eq, Ord)
---------------------
-- AXIOMS
---------------------
--Entities
data EntityType =
Datatype
| Class
| ObjectProperty
| DataProperty
| AnnotationProperty
| NamedIndividual
deriving (Typeable, Enum, Bounded, Show, Read, Eq, Ord)
-- | Syntax of Entities
data Entity = Entity EntityType IRI deriving (Typeable, Show, Eq, Ord)
instance GetRange Entity
entityTypes :: [EntityType]
entityTypes = [minBound .. maxBound]
type SourceIndividual = Individual
type TargetIndividual = Individual
type TargetValue = Literal
data Axiom = -- Annotations can be ignored
PlainAxiom [Annotation] PlainAxiom
| EntityAnno AnnotationAxiom
deriving (Typeable, Show, Eq, Ord)
instance GetRange Axiom
data EquivOrDisjoint = Equivalent | Disjoint deriving (Show, Eq, Ord)
showEquivOrDisjoint :: EquivOrDisjoint -> String
showEquivOrDisjoint ed = case ed of
Equivalent -> equivalentToC
Disjoint -> disjointWithC
data ObjDomainOrRange = ObjDomain | ObjRange deriving (Show, Eq, Ord)
showObjDomainOrRange :: ObjDomainOrRange -> String
showObjDomainOrRange dr = case dr of
ObjDomain -> domainC
ObjRange -> rangeC
data DataDomainOrRange = DataDomain ClassExpression | DataRange DataRange
deriving (Typeable, Show, Eq, Ord)
data Character =
Functional
| InverseFunctional
| Reflexive
| Irreflexive
| Symmetric
| Asymmetric
| Antisymmetric
| Transitive
deriving (Typeable, Enum, Bounded, Show, Eq, Ord)
data SameOrDifferent = Same | Different deriving (Show, Eq, Ord)
showSameOrDifferent :: SameOrDifferent -> String
showSameOrDifferent sd = case sd of
Same -> sameAsC
Different -> differentFromC
data PositiveOrNegative = Positive | Negative deriving (Show, Eq, Ord)
data Assertion a b = Assertion a PositiveOrNegative SourceIndividual b
deriving (Typeable, Show, Eq, Ord)
data PlainAxiom =
SubClassOf SubClass SuperClass
| EquivOrDisjointClasses EquivOrDisjoint [ClassExpression] -- min. 2 desc.
| DisjointUnion Class [ClassExpression] -- min. 2 desc.
| SubObjectPropertyOf SubObjectPropertyExpression ObjectPropertyExpression
| EquivOrDisjointObjectProperties EquivOrDisjoint [ObjectPropertyExpression] -- min. 2 ObjectPropertyExpression
| ObjectPropertyDomainOrRange ObjDomainOrRange ObjectPropertyExpression ClassExpression
| InverseObjectProperties ObjectPropertyExpression ObjectPropertyExpression
| ObjectPropertyCharacter Character ObjectPropertyExpression
| SubDataPropertyOf DataPropertyExpression DataPropertyExpression
| EquivOrDisjointDataProperties EquivOrDisjoint [DataPropertyExpression] -- min. 2 DataPropertyExpressions
| DataPropertyDomainOrRange DataDomainOrRange DataPropertyExpression
| FunctionalDataProperty DataPropertyExpression
| SameOrDifferentIndividual SameOrDifferent [Individual] -- min. 2 ind.
| ClassAssertion ClassExpression Individual -- arguments are reversed from OWL-1
| ObjectPropertyAssertion (Assertion ObjectPropertyExpression TargetIndividual)
| DataPropertyAssertion (Assertion DataPropertyExpression TargetValue)
| Declaration Entity
| DatatypeDefinition Datatype DataRange
| HasKey ClassExpression [ObjectPropertyExpression] [DataPropertyExpression]
deriving (Typeable, Show, Eq, Ord)
type SubClass = ClassExpression
type SuperClass = ClassExpression
data SubObjectPropertyExpression
= OPExpression ObjectPropertyExpression
| SubObjectPropertyChain [ObjectPropertyExpression] -- min. 2 ObjectPropertyExpression
deriving (Typeable, Show, Eq, Ord)
---------------------
-- ONTOLOGY FILES
---------------------
emptyOntologyFile :: OntologyFile
emptyOntologyFile = OntologyFile Map.empty emptyOntology
emptyOntology :: Ontology
emptyOntology = Ontology nullQName [] [] []
isEmptyOntologyFile :: OntologyFile -> Bool
isEmptyOntologyFile (OntologyFile ns onto) =
Map.null ns && isEmptyOntology onto
isEmptyOntology :: Ontology -> Bool
isEmptyOntology (Ontology (QN _ l _ n) annoList impList axioms) =
null l && null n && null annoList && null impList && null axioms