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

📄 digreasoner.java

📁 jena2.5.4推理机系统的一种最基本实现 HP实验室出品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param parameter the property identifying the parameter to be changed
     * @param value the new value for the parameter, typically this is a wrapped
     * java object like Boolean or Integer.
     * @throws IllegalParameterException if the parameter is unknown
     */
    public void setParameter(Property parameter, Object value) {
        if (!doSetParameter(parameter, value)) {
            throw new IllegalParameterException( "DIGReasoner does not recognize configuration parameter " + parameter );
        }
        else {
            // Record the configuration change
            if (m_configuration == null) {
                Model configModel = ModelFactory.createDefaultModel();
                m_configuration = configModel.createResource();
            }

            Util.updateParameter( m_configuration, parameter, value );
        }
    }


    /**
     * <p>Configure the reasoner using the properties attached to the given config
     * resource.</p>
     * @param configuration A configuration resource.
     */
    public void configure( Resource configuration ) {
        if (configuration != null) {
            for (StmtIterator i = configuration.listProperties(); i.hasNext(); ) {
                Statement s = i.nextStatement();
                if (!doSetParameter( s.getPredicate(), s.getObject() )) {
                    // we used to throw an exception here, but such is no longer felicitous
                    // TODO consider namespace-based checking
                }
            }
        }
    }


    /**
     * <p>Answer the URL to use when connecting to the external reasoner.</p>
     * @return The connection URL for the external reasoner as a string
     */
    public String getReasonerURL() {
        return m_extReasonerURL;
    }


    /**
     * <p>Answer the model spec that corresponds to the ontology model type we'll use to
     * access the terms of the ontology according to language.</p>
     * @return The appropriate ont model spec
     */
    public OntModelSpec getOntLangModelSpec() {
        return m_ontLang;
    }


    /**
     * <p>Answer the schema (tbox) graph for this reasoner, or null if no schema is defined.</p>
     * @return The schema graph, or null
     */
    public Graph getSchema() {
        return m_tbox;
    }


    /**
     * <p>Answer the model that contains the given axioms for this reasoner, or null if
     * not defined.</p>
     * @return The axioms model
     */
    public Model getAxioms() {
        return m_axioms;
    }

    /**
     * Return the Jena Graph Capabilties that the inference graphs generated
     * by this reasoner are expected to conform to.
     */
    public Capabilities getGraphCapabilities() {
        if (capabilities == null) {
            capabilities = new BaseInfGraph.InfCapabilities();
        }
        return capabilities;
    }

    // Internal implementation methods
    //////////////////////////////////

    /**
     * <p>Set a configuration parameter for the reasoner. The supported parameters
     * are:</p>
     * <ul>
     * <li>{@link ReasonerVocabulary#EXT_REASONER_URL} the URL to use to connect to the external reasoners</li>
     * <li>{@link ReasonerVocabulary#EXT_REASONER_ONT_LANG} the URI of the ontology language (OWL, DAML, etc) to process</li>
     * <li>{@link ReasonerVocabulary#EXT_REASONER_AXIOMS} the URL of the ontology axioms model</li>
     * </ul>
     *
     * @param parameter the property identifying the parameter to be changed
     * @param value the new value for the parameter, typically this is a wrapped
     * java object like Boolean or Integer.
     * @return false if the parameter was not known
     */
    protected boolean doSetParameter(Property parameter, Object value) {
        if (parameter.equals(ReasonerVocabulary.EXT_REASONER_URL)) {
            m_extReasonerURL = (value instanceof Resource) ? ((Resource) value).getURI() : value.toString();
            return true;
        }
        else if (parameter.equals(ReasonerVocabulary.EXT_REASONER_ONT_LANG)) {
            String lang = (value instanceof Resource) ? ((Resource) value).getURI() : value.toString();
            m_ontLang = getModelSpec( lang );
            return true;
        }
        else if (parameter.equals(ReasonerVocabulary.EXT_REASONER_AXIOMS)) {
            String axURL = (value instanceof Resource) ? ((Resource) value).getURI() : value.toString();
            m_axioms = ModelFactory.createDefaultModel();

            // if a file URL, try to load it as a stream (which means we can extract from jars etc)
            if (axURL.startsWith( "file:")) {
                String fileName = axURL.substring( 5 );
                InputStream in = null;
                try {
                    in = FileUtils.openResourceFileAsStream( fileName );
                    m_axioms.read( in, axURL );
                }
                catch (FileNotFoundException e) {
                    LogFactory.getLog( getClass() ).error( "Could not open DIG axioms " + axURL );
                }
                finally {
                    if (in != null) {
                        try {in.close();} catch (IOException ignore) {}
                    }
                }
            }
            else {
                m_axioms.read( axURL );
            }

            return true;
        }
        else {
            return false;
        }
    }


    /**
     * <p>Answer the ont model spec for the given ontology language</p>
     * @param lang The ontology language as a URI
     * @return The correspondig ont model spec to use (should be no reasoner attached)
     */
    protected OntModelSpec getModelSpec( String lang ) {
        if (lang.equals( ProfileRegistry.OWL_LANG ) ||
            lang.equals( ProfileRegistry.OWL_DL_LANG ) ||
            lang.equals( ProfileRegistry.OWL_LITE_LANG )) {
           return OntModelSpec.OWL_MEM;
        }
        else if (lang.equals( ProfileRegistry.DAML_LANG )) {
            return OntModelSpec.DAML_MEM;
        }
        else if (lang.equals( ProfileRegistry.RDFS_LANG )) {
            return OntModelSpec.RDFS_MEM;
        }
        else {
            throw new IllegalParameterException( "DIG reasoner did not recognise ontology language " + lang );
        }
    }



    //==============================================================================
    // Inner class definitions
    //==============================================================================

}


/*
 *  (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
 *  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

⌨️ 快捷键说明

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