ExpandCurie.hs revision c71adfa34068c59f783ac98a061441f5dc8daec9
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian MaederModule : $Header$
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian MaederDescription : Expansion of abbreviated IRI to full IRI
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian MaederCopyright : (c) Eugen Kuksa, Uni Bremen 2012
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian MaederLicense : GPLv2 or higher, see LICENSE.txt
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian MaederMaintainer : eugenk@informatik.uni-bremen.de
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian MaederStability : experimental
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian MaederPortability : portable
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian MaederProvides a function to expand each abbreviated IRI to a full IRI
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maederin a basic spec.
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder ( expandCurieBS
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maederimport qualified Common.AS_Annotation as Anno
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maederimport qualified Data.Map as Map
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder{- | Expands each abbreviated IRI to a full IRI in the basic spec according to
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maederthe supplemented map @gpm@. An IRI is stored in a name (quoted string). If
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maederthe prefix of an abbreviated IRI is not in the map, the IRI won't be expanded.
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian MaederexpandCurieBS :: Map.Map String IRI -> BASIC_SPEC -> BASIC_SPEC
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian MaederexpandCurieBS gpm (Basic_spec abis) = Basic_spec $ map
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder (\ abi@Anno.Annoted {Anno.item = bi} -> abi {Anno.item = expBI gpm bi})
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian MaederexpBI :: Map.Map String IRI -> BASIC_ITEMS -> BASIC_ITEMS
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian MaederexpBI gpm (Axiom_items atms) =
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder Axiom_items $ map (expAnTextMeta gpm) atms
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian MaederexpAnTextMeta :: Map.Map String IRI
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder -> Anno.Annoted TEXT_META -> Anno.Annoted TEXT_META
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian MaederexpAnTextMeta gpm an@Anno.Annoted {Anno.item = tm} =
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder an {Anno.item = expTextMeta gpm tm}
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian MaederexpTextMeta :: Map.Map String IRI -> TEXT_META -> TEXT_META
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian MaederexpTextMeta gpm tm =
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder tm { getText = expTxt (Map.unionWith (\ _ p2 -> p2) gpm $
06f58a67e6df999858bf4f97d5e0786956562d29Christian Maeder Map.fromList $ prefix_map tm) (getText tm) }
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian MaederexpTxt :: Map.Map String IRI -> TEXT -> TEXT
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian MaederexpTxt pm t = case t of
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder Text phrs rn -> Text (map (expPhr pm) phrs) rn
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder Named_text n txt rn -> Named_text (expName pm n) (expTxt pm txt) rn
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian MaederexpPhr :: Map.Map String IRI -> PHRASE -> PHRASE
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian MaederexpPhr pm p = case p of
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder Module m -> Module (expMod pm m)
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder Sentence s -> Sentence (expSen pm s)
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder Importation i -> Importation (expImp pm i)
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder Comment_text c t rn -> Comment_text c (expTxt pm t) rn
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian MaederexpMod :: Map.Map String IRI -> MODULE -> MODULE
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian MaederexpMod pm m = case m of
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Mod n t rn -> Mod (expName pm n) (expTxt pm t) rn
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Mod_ex n ns t rn ->
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder Mod_ex (expName pm n) (map (expName pm) ns) (expTxt pm t) rn
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian MaederexpImp :: Map.Map String IRI -> IMPORTATION -> IMPORTATION
bb2c1beb7ab66a49627a2a34df80864a3c65cc83Christian MaederexpImp pm (Imp_name n) = Imp_name $ expName pm n
bb2c1beb7ab66a49627a2a34df80864a3c65cc83Christian MaederexpSen :: Map.Map String IRI -> SENTENCE -> SENTENCE
bb2c1beb7ab66a49627a2a34df80864a3c65cc83Christian MaederexpSen pm s = case s of
bb2c1beb7ab66a49627a2a34df80864a3c65cc83Christian Maeder Quant_sent qs rn -> Quant_sent (case qs of
bb2c1beb7ab66a49627a2a34df80864a3c65cc83Christian Maeder Universal noss s2 -> Universal (map (expNos pm) noss) (expSen pm s2)
bb2c1beb7ab66a49627a2a34df80864a3c65cc83Christian Maeder Existential noss s2 -> Existential (map (expNos pm) noss) (expSen pm s2)
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Bool_sent bs rn -> Bool_sent (case bs of
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Conjunction ss -> Conjunction $ map (expSen pm) ss
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Disjunction ss -> Disjunction $ map (expSen pm) ss
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Negation s2 -> Negation $ expSen pm s2
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Implication s1 s2 -> Implication (expSen pm s1) (expSen pm s2)
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Biconditional s1 s2 -> Biconditional (expSen pm s1) (expSen pm s2)
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Atom_sent as rn -> Atom_sent (case as of
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Equation t1 t2 -> Equation (expTrm pm t1) (expTrm pm t2)
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Atom t tseqs -> Atom (expTrm pm t) $ map (expTseq pm) tseqs
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Comment_sent c cs rn -> Comment_sent c (expSen pm cs) rn
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Irregular_sent is rn -> Irregular_sent (expSen pm is) rn
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian MaederexpNos :: Map.Map String IRI -> NAME_OR_SEQMARK -> NAME_OR_SEQMARK
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian MaederexpNos pm nos = case nos of
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian Maeder Name n -> Name $ expName pm n
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian Maeder SeqMark s -> SeqMark $ expName pm s
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian MaederexpTrm :: Map.Map String IRI -> TERM -> TERM
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian MaederexpTrm pm trm = case trm of
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian Maeder Name_term n -> Name_term $ expName pm n
d4aed7a2eea6b546c0d9520d85038addb7beb12fChristian Maeder Funct_term t tseqs rn ->
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder Funct_term (expTrm pm t) (map (expTseq pm) tseqs) rn
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder Comment_term t c rn -> Comment_term (expTrm pm t) c rn
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian MaederexpTseq :: Map.Map String IRI -> TERM_SEQ -> TERM_SEQ
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian MaederexpTseq pm nos = case nos of
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder Term_seq t -> Term_seq $ expTrm pm t
a1a48072301767054f2a9ff7ccf8974b0d6a6a28Christian Maeder Seq_marks s -> Seq_marks $ expName pm s
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian MaederexpName :: Map.Map String IRI -> NAME -> NAME
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian MaederexpName pm n = case fmap (expandCurie pm) $ parseCurie (strippedQuotesStr n) of
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder Just (Just x) ->
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder Token (getQuote n ++ iriToStringUnsecure x ++ getQuote n) $ tokPos n
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian MaedergetQuote :: NAME -> String
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian MaedergetQuote s = case tokStr s of
5b3e0bbb6a776c60dc14113435a44e7b13d2fa01Christian Maeder '\"' : _ -> "\""
36a493b7eec0f9d719674296c26afe7fd9bfe327Christian Maeder '\'' : _ -> "\'"
38f35f2c4a3b6a778f4f68e7af047a174e93abbeChristian MaederstrippedQuotesStr :: NAME -> String
38f35f2c4a3b6a778f4f68e7af047a174e93abbeChristian MaederstrippedQuotesStr n =
13140d161d2d2d11d87283d01d57ee3a738a833dChristian Maeder let str = tokStr n
38f35f2c4a3b6a778f4f68e7af047a174e93abbeChristian Maeder middleStr = init $ tail str
38f35f2c4a3b6a778f4f68e7af047a174e93abbeChristian Maeder in case str of
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder '\"' : _ : _ -> middleStr
0c92a39a4adf3c1cbe173e3b16c65c159a1ce612Christian Maeder '\'' : _ : _ -> middleStr