⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ruleml0_8driver.java

📁 Mandarax是一个规则引擎的纯Java实现。它支持多类型的事实和基于反映的规则
💻 JAVA
字号:
/*
 * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.mandarax.xkb.ruleml;

import java.util.Iterator;
import java.util.List;

import org.jdom.Element;
import org.mandarax.kernel.ClauseSet;
import org.mandarax.kernel.Fact;
import org.mandarax.kernel.KnowledgeBase;
import org.mandarax.kernel.Rule;
import org.mandarax.reference.AdvancedKnowledgeBase;
import org.mandarax.xkb.XKBException;

/**
 * Driver implementation for the RULE ML version 0.8.
 * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
 * @version 3.4 <7 March 05>
 * @since 1.9
 */
public class RuleML0_8Driver extends AbstractRuleMLDriver {

    /**
     * Constructor.
     */
    public RuleML0_8Driver() {
        super();
    }
    /**
     * Export a knowledge base, e.g. convert it into an xml element.
     * @return an element (of the jdom tree)
     * @param kb a knowledge base
     */
    protected Element export(KnowledgeBase kb) {
        Element   e             = new Element (RULEBASE);
        List      clauseSets    = kb.getClauseSets ();
        ClauseSet nextClauseSet = null;
		// export clause sets
        for (Iterator it = clauseSets.iterator(); it.hasNext (); ) {
            nextClauseSet = (ClauseSet) it.next ();
            if(nextClauseSet instanceof Fact) e.addContent (export ((Fact) nextClauseSet));
            else if (nextClauseSet instanceof Rule) e.addContent (export ((Rule) nextClauseSet));
            else LOG_XKB.warn ("Only facts and rules are suported by driver " + getName () + ", cannot export " + nextClauseSet);
        }    
        return e;
    }

    /**
     * Get a short text describing the driver.
     * @return a text
     */
    public String getDescription() {
        return "Driver for rulebases as specified by the RULE ML version 0.8 specification";
    }

    /**
     * Get the location (URL) of the associated DTD.
     * @return a text
     */
    public String getDTD() {
        return "http://www.dfki.uni-kl.de/ruleml/dtd/0.8/ruleml-datalog-monolith.dtd";
    }

    /**
     * Get the name of the driver.
     * @return a text
     */
    public String getName() {
        return "RuleML 0.8";
    }
    /**
     * Import a knowledge base.
     * @return a knowledge base
     * @param e an xml element
     * @throws an XKBException is thrown if import fails
     */
    protected KnowledgeBase importKnowledgeBase(Element e) throws XKBException {

        // since we have no chance to store the class name in this xml format,
        // we choose the default class
        KnowledgeBase kb = new AdvancedKnowledgeBase ();

        // build the clause sets
        List      all    = e.getChildren ();
        Element   next   = null;
        ClauseSet nextCS = null;

        for(Iterator it = all.iterator (); it.hasNext (); ) {
            next = (Element) it.next ();
            if(compare (next.getName (), IMP)) kb.add(importRule(next));
            else if(compare (next.getName (), FACT)) kb.add(importFact(next));
            else LOG_XKB.warn ("Cannot import element <"+ next.getName () + "> - driver " + getName() + " does not support this tag");
        }
        return kb;
    }
    /**
     * Indicates whether the driver (and the underlying xml format (=dtd))
     * supports auto facts.
     * @return a boolean
     */
    public boolean supportsAutoFacts() {
        return false;
    }
    /**
     * Indicates whether the driver (and the underlying xml format (=dtd))
     * supports clause sets.
     * @return a boolean
     */
    public boolean supportsClauseSets() {
        return false;
    }
    /**
     * Indicates whether the driver (and the underlying xml format (=dtd))
     * supports facts. (some formats might see facts as rules without body)
     * @return a boolean
     */
    public boolean supportsFacts() {
        return true;
    }
    /**
     * Indicates whether the driver (and the underlying xml format (=dtd))
     * supports functions.
     * @return a boolean
     */
    public boolean supportsFunctions() {
        return false;
    }
    /**
     * Indicates whether the driver (and the underlying xml format (=dtd))
     * supports the java semantics (e.g. JFunctions, JPredicate).
     * @return a boolean
     */
    public boolean supportsJavaSemantics() {
        return false;
    }
    /**
     * Indicates whether the driver (and the underlying xml format (=dtd))
     * supports multiple premises.
     * @return a boolean
     */
    public boolean supportsMultiplePremises() {
        return true;
    }
    /**
     * Indicates whether the driver (and the underlying xml format (=dtd))
     * supports multiple premises connected by OR.
     * @return a boolean
     */
    public boolean supportsOrPremises() {
        return false;
    }
    /**
     * Indicates whether the driver (and the underlying xml format (=dtd))
     * supports types.
     * @return a boolean
     */
    public boolean supportsTypes() {
        return false;
    }
    /**
     * Indicates whether the driver (and the underlying xml format (=dtd))
     * supports queries.
     * @return a boolean
     */
    public boolean supportsQueries() {
    	return false;
    }
    /**
	 * Indicates whether the driver (and the underlying xml format (=dtd))
	 * supports negation as failure.
	 * @return a boolean
	 */
	public boolean supportsNegationAsFailure(){
		return false;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -