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

📄 ontmodelspecobsolete.java

📁 jena2.5.4推理机系统的一种最基本实现 HP实验室出品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * 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 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();
        }
    
    /**
        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() ) );
        }

    protected Model addDescription( Model d, Resource self, ModelMaker importsMaker, String language, OntDocumentManager documentManager, ReasonerFactory reasonerFactory )
        {
        addMakerDescription( d, self );
        addImportsDescription( d, self, importsMaker );
        addLanguageDescription( d, self, language );
        addManagerDescription( d, self, documentManager );
        addReasonerDescription( d, self, reasonerFactory );
        return d;
        }

    public Model getDescription()
        { return getDescription( ResourceFactory.createResource() ); }

    public Model getDescription( Resource root )
        { return addDescription( ModelFactory.createDefaultModel(), root ); }

    public Model addMakerDescription( Model desc, Resource root )
        {
        Resource makerRoot = desc.createResource();
        desc.add( root, JenaModelSpec.maker, makerRoot );
        maker.addDescription( desc, makerRoot );
        return desc;
        }

    /**
        The map which associates bnodes with Java values.
    */        
    private static Map values = new HashMap();
    
    /**
        Answer a new bnode Resource associated with the given value. The mapping from
        bnode to value is held in a single static table, and is not intended to hold many
        objects; there is no provision for garbage-collecting them [this might eventually be
        regarded as a bug].
        
        @param value a Java value to be remembered 
        @return a fresh bnode bound to <code>value</code>
    */
    public static Resource createValue( Object value )
        {
        Resource it = ResourceFactory.createResource();
        values.put( it, value );
        return it;    
        }
        
    /**
        Answer the value bound to the supplied bnode, or null if there isn't one or the
        argument isn't a bnode.
        
        @param it the RDF node to be looked up in the <code>createValue</code> table.
        @return the associated value, or null if there isn't one.
    */
    public static Object getValue( RDFNode it )
        { return values.get( it ); }
    
    public interface ModelMakerCreator
        {
        /**
            Answer a ModelMaker who's description is found hanging from a given root
            in a given model.
            @param desc the model containing the description
            @param root the root of the description
            @return a ModelMaker satisfying the description
         */
        ModelMaker create( Model desc, Resource root );
        }
    
    private static class MakerCreator
        {
        /**
            Answer the reification style possessed by <code>root</code> in 
            <code>desc</code> under the property <code>JenaModelSpec.reificationMode</code>.
            If no such property exists, default to <code>Standard</code>.
            
            @param desc the model in which to search
            @param root the entity which may have the property
            @return the reification style given by the property, or Standard if none
         */
        public ReificationStyle style( Model desc, Resource root )
            {
            Statement st = desc.getProperty( root, JenaModelSpec.reificationMode );
            return st == null ? ReificationStyle.Standard : JenaModelSpec.findStyle( st.getObject() );
            } 
        }
    
    public static class MemMakerCreator extends MakerCreator implements ModelMakerCreator
        {
        /**
            Answer the MemModelMaker with the reification style specified as the
            JenaModelSpec.reificationMode property of the root, or Standard if none.
        */
        public ModelMaker create( Model desc, Resource root ) 
            { return ModelFactory.createMemModelMaker( style( desc, root ) ); }
        }
    

    public static class FileMakerCreator extends MakerCreator implements ModelMakerCreator
        {
        /**
            Answer a FileModelMaker with reification style given by the JenaModelSpec.reificationMode
            of the root and file base given by the JenaModelSpec.fileBase of the root. The latter
            defaults to "/tmp", which probably counts as a bug.
            
            TODO replace /tmp with the non-implementation-specific temporary directory.
         */
        public ModelMaker create( Model desc, Resource root ) 
            { 
            Statement fb = desc.getProperty( root, JenaModelSpec.fileBase );
            String fileBase = fb == null ? "/tmp" : fb.getString();
            return ModelFactory.createFileModelMaker( fileBase, style( desc, root ) );
            }
        }
    
    public static class RDBMakerCreator implements ModelMakerCreator
        {
        public ModelMaker create( Model desc, Resource root )
            {
            return ModelFactory.createModelRDBMaker( createConnection( desc, root ) );
            }
    
        public static IDBConnection createConnection( Model description, Resource root )
            {
            Resource connection = description.listStatements( root, JenaModelSpec.hasConnection, (RDFNode) null ).nextStatement().getResource();
            String url = getURL( description, connection, JenaModelSpec.dbURL );
            String user = getString( description, connection, JenaModelSpec.dbUser );
            String password = getString( description, connection , JenaModelSpec.dbPassword );
            String className = getClassName( description, connection );
            String dbType = getDbType( description, connection );
            loadDrivers( dbType, className );
            return ModelFactory.createSimpleRDBConnection( url, user, password, dbType );
            }
    
        public static String getDbType( Model description, Resource connection )
            { return getString( description, connection, JenaModelSpec.dbType ); }
    
        public static String getClassName( Model description, Resource root )
            {
            Statement cnStatement = description.getProperty( root, JenaModelSpec.dbClass );
            if (cnStatement == null)
                return DriverMap.get( getDbType( description, root ) );
            else
                return cnStatement == null ? null : cnStatement.getString();
            }
        
        public static String getURL( Model description, Resource root, Property p )
            {
            return description.getRequiredProperty( root, p ).getResource().getURI();
            }
    
        public static String getString( Model description, Resource root, Property p )
            {
            return description.getRequiredProperty( root, p ).getString();
            }
        
        public static void loadDrivers( String dbType, String className )
            {
            try
                {
                Class.forName( "com.hp.hpl.jena.db.impl.Driver_" + dbType );
                if (className != null) Class.forName( className );
                }
            catch (ClassNotFoundException c)
                { throw new JenaException( c ); }
            }
        }
    }

⌨️ 快捷键说明

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