0N/ACopyright : (c) Heng Jiang, Uni Bremen 2004-2005
0N/AMaintainer : jiang@tzi.de
0N/A Stability : provisional
0N/APortability : portable
Here is the place where the class Logic is instantiated for CASL.
Also the instances for Syntax an Category.
type ResXmlTree = XmlTree -> Result XmlTrees
type ResXmlTrees = XmlTrees -> Result XmlTrees
propAndValidateNamespaces :: ResXmlTree
propAndValidateNamespaces t
= validate $ propagateNamespaces t
where validate ct = let errs = foldr (++) [] $
Prelude.map validateNamespaces ct
then Result {diags = [], maybeResult = Just ct}
checkErrs [] = Result { diags = [], maybeResult = Just []}
checkErrs xt@[(NTree node _)] =
diagnosis = Diag{ diagKind = kind,
in Result{ diags = [diagnosis],
maybeResult = if kind == Warning then
checkErrs (hd:errs) = let Result d1 _ = checkErrs [hd]
Result d2 _ = checkErrs errs
in Result {diags = d1++d2, maybeResult = Nothing}
class (Show a) => XmlTransformer a where
fromXmlTree :: XmlTree -> Result a
fromXmlTrees :: XmlTrees -> Result [a]
fromXmlTrees = mapM fromXmlTree
instance XmlTransformer Ontology where
let ((Result diagNs maybeNs), subtrees) = analyseNamespace tree
(properties, subtrees2) = analyseHeader subtrees
in -- wenn keine Annotation in OntologyHeader hat, ...
then let directives = [] -- analyseTail subtrees -- axiom oder fact
Just namespaces -> Result{ diags = diagNs,
maybeResult = Just (Ontology Nothing properties directives namespaces) }
Nothing -> Result{ diags = diagNs,
maybeResult = Just (Ontology Nothing properties directives []) }
else let directives = [] -- analyseTail subtrees2 -- analyseOntology subtree2
Just namespaces -> Result{ diags = diagNs,
maybeResult = Just (Ontology Nothing properties directives namespaces) }
Nothing -> Result{ diags = diagNs,
maybeResult = Just (Ontology Nothing properties directives []) }
analyseNamespace :: XmlTree -> (Result [Namespace], XmlTrees) -- (namespaces, rest)
analyseNamespace (NTree node trees) =
if (tName qname) == "rdf:RDF" then
let Result diagNs mResNs = mapM anns nspaces
then ((Result {diags = diagNs, maybeResult = Nothing}), trees)
Just resNs ->((Result {diags = [],
maybeResult = Just ((NTree (XAttr qname) []):resNs)}),
Nothing -> ((Result {diags = [],
maybeResult = Just [(NTree (XAttr qname) [])]}),
else analyseNamespace $ head trees
_ -> analyseNamespace $ head trees -- nicht sicher, ob alle Namespaces am Anfang
anns :: XmlTree -> Result Namespace
maybeResult = Just (NTree (addURI attrib (head text)) []) }
_ -> warning (NTree (XText "") []) "format of namespaces illegal." nullPos
addURI :: XNode -> NTree XNode -> XNode
addURI (XAttr (QN pre local _)) (NTree (XText text) _) =
XAttr QN{ namePrefix = pre,
addURI n _ = n -- remove warning
-- ist Header immer der erste Knoten in XmlTrees?
analyseHeader :: XmlTrees -> ([Axiom], XmlTrees)
analyseHeader [] = ([], [])
analyseHeader (firstT:trees) =
NTree (XTag tagName rdfabout) st ->
if tName tagName == "owl:Ontology"
then case head rdfabout of
NTree (XAttr ontoProp) _ ->
_ -> ([],[]) -- remove warning
else case analyseHeader trees of
(res,trees') -> (res, firstT:trees') --(trees ++ [firstT])
where anaheader :: XmlTrees -> [Axiom]
NTree (XTag tagName attr) sub ->
let aname = tName tagName
in if (aname == "owl:versionInfo" ||
aname == "rdfs:comment" ||
aname == "rdfs:seeAlso" ||
aname == "rdfs:isDefinedBy")
then (AnnotationProperty tagName (buildAnno tagName sub)):(anaheader restT)
else (OntologyProperty tagName (buildAnno tagName attr)):(anaheader restT) -- sub wird hier weggelassen...
then [DLAnnotation tn (PlainL ("", ""))]
else buildAnnotations tn text
buildAnnotations tn [] = []
buildAnnotations tn (text:rest) =
if (any isAlphaNum str) then
(DLAnnotation tn (PlainL (str, ""))):(buildAnnotations tn rest)
else buildAnnotations tn rest
NTree (XAttr tn') text' -> (map (\x -> case x of NTree (XText t) _ -> URIAnnotation tn' (mkName t)) text')++(buildAnnotations tn rest)
_ -> (OntAnnotation (mkName "") (mkName "")):(buildAnnotations tn rest)
analyseTail :: XmlTrees -> Result [Directive]
analyseTail trees = mapM analyseTail' trees
analyseTail' :: XmlTree -> Result Directive
NTree (XTag tagName tagTrees) subTrees ->
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just axiom -> Just (Ax axiom)
Nothing -> Nothing::(Maybe Directive)}
case owlRestriction tree of
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just axiom -> Just (Ax axiom)
Nothing -> Nothing::(Maybe Directive)}
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just axiom -> Just (Ax axiom)
Nothing -> Nothing::(Maybe Directive)}
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just axiom -> Just (Ax axiom)
Nothing -> Nothing::(Maybe Directive)}
"owl:FunctionalProperty" ->
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just axiom -> Just (Ax axiom)
Nothing -> Nothing::(Maybe Directive)}
"owl:InverseFunctionalProperty" ->
case owlInvFuncProp tree of
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just axiom -> Just (Ax axiom)
Nothing -> Nothing::(Maybe Directive)}
"owl:TransitiveProperty" ->
case owlTransProp tree of
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just axiom -> Just (Ax axiom)
Nothing -> Nothing::(Maybe Directive)}
"owl:SymmetricProperty" ->
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just axiom -> Just (Ax axiom)
Nothing -> Nothing::(Maybe Directive)}
case rdfDescription tree of
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just axiom -> Just (Ax axiom)
Nothing -> Nothing::(Maybe Directive)}
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just fact -> Just (Fc fact)
Nothing -> Nothing::(Maybe Directive)}
"owl:DatatypeProperty" ->
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just axiom -> Just (Ax axiom)
Nothing -> Nothing::(Maybe Directive)}
"owl:AnnotatonProperty" ->
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just axiom -> Just (Ax axiom)
Nothing -> Nothing::(Maybe Directive)}
case owlIndividual tree of
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just fact -> Just (Fc fact)
Nothing -> Nothing::(Maybe Directive)}
_ -> if not ("owl:" == take 4 (tName tagName) && "rdf:" == take 4 (tName tagName))
case owlIndividual tree of
Result diagRes maybeRes ->
maybeResult = case maybeRes of
Just fact -> Just (Fc fact)
Nothing -> Nothing::(Maybe Directive)}
else fatal_error "Node is unknow." nullPos
_ -> fatal_error "Error" nullPos
dummyAx:: XmlTree -> Result Axiom
dummyAx tree = Result { diags = [], maybeResult = Nothing::(Maybe Axiom)}
dummyFc:: XmlTree -> Result Fact
dummyFc tree = Result { diags = [], maybeResult = Nothing::(Maybe Fact)}
owlClass:: XmlTree -> Result Axiom
owlRestriction:: XmlTree -> Result Axiom
rdfProp:: XmlTree -> Result Axiom -- Result Directive, keine Ahnung, nicht in abs. Struktur
owlObjProp:: XmlTree -> Result Axiom
owlFuncProp:: XmlTree -> Result Axiom
owlInvFuncProp:: XmlTree -> Result Axiom
owlTransProp:: XmlTree -> Result Axiom
owlSymmProp:: XmlTree -> Result Axiom
rdfDescription:: XmlTree -> Result Axiom
owlAllDiff:: XmlTree -> Result Fact
owlDtProp:: XmlTree -> Result Axiom
owlAnnoProp:: XmlTree -> Result Axiom
owlIndividual:: XmlTree -> Result Fact
owl_parserT :: String -> String -> Result XmlTrees
owl_parserT fname fcont =
let parsedT@(Result ds mtree) = checkErrs (tryP fname fcont)
Just mt -> let propAndValidT@(Result ds' mtree') = propAndValidateNamespaces $ head mt
Just pvt -> Result {diags = ds ++ ds',
maybeResult = Just (canonicalizeAllNodes $ head pvt)}
tryP :: String -> String -> XmlTrees
parseXmlFromString (do x <- document; return [x]) loc str
tryO fname = do x <- readFile fname
let Result diagnos mtrees = owl_parserT "TEST" x
Just trees -> putStrLn $ show trees
Nothing -> print $ show diagnos
resTrees :: Result XmlTrees -> XmlTrees
resTrees (Result ds mtree) = case mtree of
Nothing -> error "ds" -- remve warning
{- warum funktioniert nicht? -}
test1 :: FilePath -> IO ()
let Result d o = fromXmlTree $ head $ resTrees $ owl_parserT "Test" x
Just (onto::Ontology) -> print $ show onto