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

📄 ontmodelspec.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 3 页
字号:


    /**
     * <p>Answer the language profile for this ontology specification</p>
     * @return An ontology langauge profile object
     */
    public Profile getProfile() {
        return m_profile;
    }

    /**
     *  <p>Create an OntModel according to this model specification.
     *  The base model comes from the attached base ModelMaker.</p>
     *  @return an OntModel satisfying this specification
     */
    public Model doCreateModel() {
        Model m = m_baseModelName == null ? maker.createFreshModel() : maker.createModel( m_baseModelName );
        return new OntModelImpl( this, m );
    }

    /**
     * <p>Create an OntModel according to this model specification.
     * The base model comes from the underlying ModelMaker and is named by the
     *  given name.</p>
     * @see com.hp.hpl.jena.rdf.model.ModelSpec#createModelOver(java.lang.String)
     */
    public Model implementCreateModelOver( String name ) {
        return new OntModelImpl( this, maker.createModel( name, false ) );
    }

    /**
     * </p>Answer the ModelMaker to be used to construct models that are used for
     * the imports of an OntModel. The ModelMaker is specified by the properties of
     * the resource which is the object of the root's <code>jms:importMaker</code> property.
     * If no importMaker is specified, a MemModelMaker is returned as a default.</p>
     * @param description the description model for this OntModel
     * @param root the root of the description for the OntModel
     * @return a ModelMaker fitting the given description
     */
    public static ModelMaker getImportMaker( Model description, Resource root ) {
        return getMaker( description, root, JenaModelSpec.importMaker );
    }

    /**
     * </p>Answer the ModelMaker to be used to construct models that are used for
     * the base model of an OntModel. The ModelMaker is specified by the properties of
     * the resource which is the object of the root's <code>jms:maker</code> property.
     * If no importMaker is specified, a MemModelMaker is returned as a default.</p>
     * @param description the description model for this OntModel
     * @param root the root of the description for the OntModel
     * @return a ModelMaker fitting the given description
     */
    public static ModelMaker getBaseMaker( Model description, Resource root ) {
        return getMaker( description, root, JenaModelSpec.maker );
    }

    /**
        Answer the value of the jms:modelName property of <code>root</code>,
        or <code>null</code> id there isn't one.
    */
    protected static String getBaseModelName( Model description, Resource root ) {
        Statement s = description.getProperty( root, JenaModelSpec.modelName );
        return s == null ? null : s.getString();
        }

    /**
         Answer a ModelMaker described by the <code>makerProperty</code> of
         <code>root</code> in <code>description</code>; if there is no such statement,
         answer a memory-model maker.
    */
    protected static ModelMaker getMaker( Model description, Resource root, Property makerProperty ) 	{
        Statement mStatement = description.getProperty( root, makerProperty );
        return mStatement == null
            ? ModelFactory.createMemModelMaker()
            : createMaker( mStatement.getResource(), description );
    }

    /**
        Answer the URI string of the ontology language in this description.

        @param description the Model from which to extract the description
        @return the language string
        @exception something if the value isn't a URI resource
    */
    public static String getLanguage( Model description, Resource root ) {
        Statement langStatement = description.getRequiredProperty( root, JenaModelSpec.ontLanguage );
        return langStatement.getResource().getURI();
    }

    /**
        Answer an OntDocumentManager satisfying the docManager part of this description.
        Currently restricted to one where the object of JenaModelSpec.docManager is registered with
        the value table held in ModelSpecImpl. If there's no such property, or if its bnode
        has no associated value, returns null.

         @param description the description of the OntModel
         @param root the root of the description
         @return the OntDocumentManager of root's JenaModelSpec.docManager
    */
    public static OntDocumentManager getDocumentManager( Model description, Resource root ) {
        Statement docStatement = description.getProperty( root, JenaModelSpec.docManager );
        if (docStatement == null) return null;
        Resource manager = docStatement.getResource();
        Statement policy = description.getProperty( manager, JenaModelSpec.policyPath );
        if (policy == null)
            return (OntDocumentManager) getValue( manager );
        else
            return new OntDocumentManager( policy.getString() );
    }

    /**
        Answer a ReasonerFactory as described by the reasonsWith part of this discription,
        or null if no reasoner specification has been supplied.

        @param description the description of this OntModel
        @param root the root of this OntModel's description
        @return  a ReasonerFactory with URI given by root's reasonsWith's reasoner.
    */
    public static ReasonerFactory getReasonerFactory( Model description, Resource root ) {
        Statement factStatement = description.getProperty( root, JenaModelSpec.reasonsWith );
        if (factStatement == null) return null;
        return InfModelSpec.getReasonerFactory( factStatement.getResource(), description );
    }

    /**
        Add the description of this OntModelSpec to the given model under the given
        resource. This same description can be used to create an equivalent OntModelSpec.
        Serialising the description will lose the DocumentManager description.

        TODO allow the DocumentManager to be [de]serialised
    */
    public Model addDescription( Model d, Resource self )  {
        super.addDescription( d, self );
        addImportsDescription( d, self, m_importsMaker );
        addLanguageDescription( d, self, m_languageURI );
        addManagerDescription( d, self, getDocumentManager() );
        addReasonerDescription( d, self, getReasonerFactory() );
        return d;
    }

    /**
        Answer the RDFS property used to attach this ModelSpec to its ModelMaker; used
        by the parent classes when constructing the RDF description for this Spec.

        @return JenaModelSpec.importMaker
    */
    public Property getMakerProperty() {
        return JenaModelSpec.importMaker;
    }

    /**
        Augment the description with that of our language
        @param d the description to augment
        @param me the resource to use to represent this OntModelSpec
        @param langURI the language URI
    */
    protected void addLanguageDescription( Model d, Resource me, String langURI ) {
        d.add( me, JenaModelSpec.ontLanguage, d.createResource( langURI ) );
    }

    protected void addImportsDescription( Model d, Resource me, ModelMaker m ) {
        Resource importSelf = d.createResource();
        d.add( me, JenaModelSpec.importMaker, importSelf );
        m.addDescription( d, importSelf );
    }

    /**
        Augment the description with that of our document manager [as a Java value]
        @param d the description to augment
        @param me the resource to use to represent this OntModelSpec
        @param man the document manager
    */
    protected  void addManagerDescription( Model d, Resource me,
        OntDocumentManager man ) {
        d.add( me, JenaModelSpec.docManager, createValue( man ) );
    }

    /**
        Augment the description with that of our reasoner factory
        @param d the description to augment
        @param me the resource to use to represent this OntModelSpec
        @param rf the reasoner factory to describe
    */
    protected void addReasonerDescription( Model d, Resource me, ReasonerFactory rf ) {
        Resource reasonerSelf = d.createResource();
        d.add( me, JenaModelSpec.reasonsWith, reasonerSelf );
        if (rf != null) {
            d.add( reasonerSelf, JenaModelSpec.reasoner, d.createResource( rf.getURI() ) );
        }
    }

    /**
         Answer a base model constructed according to this specificiation. This is used for the
         "base" (ie non-imported) model for an OntModel.
    */
    public Model createBaseModel()  {
        return ModelFactory.createDefaultModel();
    }

}


/*
    (c) Copyright 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 + -