{-# LANGUAGE MultiParamTypeClasses #-}---------------------------------------------------------------------------------- See end of this file for licence information.---------------------------------------------------------------------------------- |-- Module : Ruleset-- Copyright : (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke-- License : GPL V2---- Maintainer : Douglas Burke-- Stability : experimental-- Portability : MultiParamTypeClasses---- This module defines a ruleset data type, used to collect information-- about a ruleset that may contribute torwards inferences in RDF;-- e.g. RDF and RDFS are rulesets.---- A ruleset consists of a namespace, a collection of axioms and-- a collection of rules.----------------------------------------------------------------------------------moduleSwish.RDF.Ruleset(Ruleset(..),RulesetMap,makeRuleset,getRulesetNamespace,getRulesetAxioms,getRulesetRules,getRulesetAxiom,getRulesetRule,getContextAxiom,getMaybeContextAxiom,getContextRule,getMaybeContextRule)whereimportSwish.Utils.Namespace(Namespace,ScopedName)importSwish.RDF.Rule(Formula(..),Rule(..))importSwish.Utils.LookupMap(LookupEntryClass(..),LookupMap(..),mapFindMaybe){-
Used for the Show instance of Ruleset, which was
used for debugging but has been removed as not
really needed by the general user.
import Swish.Utils.ShowM (ShowM(..))
import Data.List (intercalate)
-}importData.Maybe(fromMaybe,listToMaybe,mapMaybe)-- | Ruleset, having namespace, axioms and rulesdataRulesetex=Ruleset{rsNamespace::Namespace,rsAxioms::[Formulaex],rsRules::[Ruleex]}{-
Used for debugging.
instance (ShowM ex) => Show (Ruleset ex) where
show (Ruleset ns axs rls) =
intercalate "\n"
[ "Ruleset: " ++ show ns
, "Axioms:" ]
++ (showsFormulae "\n" axs
(intercalate "\n" ("Rules:" : map show rls))) ""
-}instanceEq(Rulesetex)wherer1==r2=rsNamespacer1==rsNamespacer2instanceLookupEntryClass(Rulesetex)Namespace(Rulesetex)wherekeyValr@(Rulesetk__)=(k,r)newEntry(_,r)=rtypeRulesetMapex=LookupMap(Rulesetex)makeRuleset::Namespace->[Formulaex]->[Ruleex]->RulesetexmakeRulesetnspfmsrls=Ruleset{rsNamespace=nsp,rsAxioms=fms,rsRules=rls}getRulesetNamespace::Rulesetex->NamespacegetRulesetNamespace=rsNamespacegetRulesetAxioms::Rulesetex->[Formulaex]getRulesetAxioms=rsAxiomsgetRulesetRules::Rulesetex->[Ruleex]getRulesetRules=rsRules-- | Find a named axiom in a ruleset.getRulesetAxiom::ScopedName->Rulesetex->Maybe(Formulaex)getRulesetAxiomnamrset=mapFindMaybenam(LookupMap(getRulesetAxiomsrset))-- listToMaybe $ filter ( (matchName nam) . formName ) $ getRulesetAxioms rset-- | Find a named rule in a ruleset. getRulesetRule::ScopedName->Rulesetex->Maybe(Ruleex)getRulesetRulenamrset=mapFindMaybenam(LookupMap(getRulesetRulesrset))-- listToMaybe $ filter ( (matchName nam) . ruleName ) $ getRulesetRules rset-- | Find a named axiom or rule in a proof context.getContextAxiom::ScopedName->Formulaex->[Rulesetex]->FormulaexgetContextAxiomnamdefrsets=fromMaybedef(getMaybeContextAxiomnamrsets){-
foldr (flip fromMaybe) def $ map (getRulesetAxiom nam) rsets
-}getMaybeContextAxiom::ScopedName->[Rulesetex]->Maybe(Formulaex)getMaybeContextAxiomnamrsets=listToMaybe$mapMaybe(getRulesetAxiomnam)rsetsgetContextRule::ScopedName->Ruleex->[Rulesetex]->RuleexgetContextRulenamdefrsets=fromMaybedef(getMaybeContextRulenamrsets){-
foldr (flip fromMaybe) def $ map (getRulesetRule nam) rsets
-}getMaybeContextRule::ScopedName->[Rulesetex]->Maybe(Ruleex)getMaybeContextRulenamrsets=listToMaybe$mapMaybe(getRulesetRulenam)rsets------------------------------------------------------------------------------------ Copyright (c) 2003, Graham Klyne, 2009 Vasili I Galchin, 2011 Douglas Burke-- All rights reserved.---- This file is part of Swish.---- Swish is free software; you can redistribute it and/or modify-- it under the terms of the GNU General Public License as published by-- the Free Software Foundation; either version 2 of the License, or-- (at your option) any later version.---- Swish is distributed in the hope that it will be useful,-- but WITHOUT ANY WARRANTY; without even the implied warranty of-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-- GNU General Public License for more details.---- You should have received a copy of the GNU General Public License-- along with Swish; if not, write to:-- The Free Software Foundation, Inc.,-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA----------------------------------------------------------------------------------