AS.hs revision 5a3ae0a9224276de25e709ef8788c1b9716cd206
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : $Header$
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuCopyright : (c) C. Maeder
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuLicense : GPLv2 or higher, see LICENSE.txt
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuMaintainer : Christian.Maeder@dfki.de
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuStability : provisional
402ffc909b645ddb2d5c76343bf74a6cb33c6205Christian MaederPortability : portable
c7e03d0708369f944b6f235057b39142a21599f2Mihai CodescuOWL 2 Functional Syntax constructs
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/>
5418aa59492005c2ca40436ab84c4029cd2922a5Christian Maederimport qualified Data.Map as Map
c7e03d0708369f944b6f235057b39142a21599f2Mihai Codescudata IRIType = Full | Abbreviated | NodeID
5418aa59492005c2ca40436ab84c4029cd2922a5Christian Maeder deriving (Show, Eq, Ord)
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 Codescuinstance Eq QName where
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu p == q = compare p q == EQ
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 Codescuinstance GetRange QName where
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder getRange = iriPos
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescushowQN :: QName -> String
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescushowQN q = (if iriType q /= Abbreviated then showQI else showQU) q
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-- | show QName in ankle brackets as full iris
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescushowQI :: QName -> String
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescushowQI = ('<' :) . (++ ">") . showQU
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescunullQName :: QName
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescunullQName = QN "" "" Abbreviated "" nullRange
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescudummyQName :: QName
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu QN "http" "//www.dfki.de/sks/hets/ontology/unamed" Full "" nullRange
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedermkQName :: String -> QName
272a5a82588ab4115dac5eb81d43d74929e99ad7Till MossakowskimkQName s = nullQName { localPart = s }
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescusetQRange :: Range -> QName -> QName
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersetQRange r q = q { iriPos = r }
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescusetPrefix :: String -> QName -> QName
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescusetPrefix s q = q { namePrefix = s }
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 CodescusetFull :: QName -> QName
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedersetFull q = q {iriType = Full}
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescutype IRI = QName
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu-- | checks if an IRI is an anonymous individual
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederisAnonymous :: IRI -> Bool
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederisAnonymous iri = iriType iri == NodeID
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederisThing :: IRI -> Bool
142cf75c6377873ccc72450202fe7f0df94a6dffMihai CodescuisThing u = elem (localPart u) ["Thing", "Nothing"] &&
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder elem (namePrefix u) ["", "owl"]
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
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescu-- | prefix -> localname
142cf75c6377873ccc72450202fe7f0df94a6dffMihai Codescutype PrefixMap = Map.Map String String
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
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederdata EquivOrDisjoint = Equivalent | Disjoint
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder deriving (Show, Eq, Ord)
803425dfe6a5da41b9cea480788980fa104545adMihai CodescushowEquivOrDisjoint :: EquivOrDisjoint -> String
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroedershowEquivOrDisjoint ed = case ed of
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu Equivalent -> equivalentToC
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu Disjoint -> disjointWithC
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederdata DomainOrRange = ADomain | ARange
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder deriving (Show, Eq, Ord)
803425dfe6a5da41b9cea480788980fa104545adMihai CodescushowDomainOrRange :: DomainOrRange -> String
803425dfe6a5da41b9cea480788980fa104545adMihai CodescushowDomainOrRange dr = case dr of
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu ADomain -> domainC
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu ARange -> rangeC
803425dfe6a5da41b9cea480788980fa104545adMihai Codescudata SameOrDifferent = Same | Different
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder deriving (Show, Eq, Ord)
96d8cf9817eeb0d26cba09ca192fc5a33e27bc09mcodescushowSameOrDifferent :: SameOrDifferent -> String
803425dfe6a5da41b9cea480788980fa104545adMihai CodescushowSameOrDifferent sd = case sd of
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu Same -> sameAsC
96d8cf9817eeb0d26cba09ca192fc5a33e27bc09mcodescu Different -> differentFromC
b7f625188b6bf3d708b2a1b64a6cea7880708adbChristian Maederdata Relation =
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder EDRelation EquivOrDisjoint
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder | SubPropertyOf
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu | DRRelation DomainOrRange
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder | SDRelation SameOrDifferent
803425dfe6a5da41b9cea480788980fa104545adMihai Codescu deriving (Show, Eq, Ord)