📄 modelfactory.java
字号:
/*
(c) Copyright 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
[See end of file]
$Id: ModelFactory.java,v 1.51 2007/01/09 16:48:41 ian_dickinson Exp $
*/
package com.hp.hpl.jena.rdf.model;
import java.util.Set;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.graph.compose.Union;
import com.hp.hpl.jena.graph.impl.*;
import com.hp.hpl.jena.assembler.Assembler;
import com.hp.hpl.jena.assembler.AssemblerHelp;
import com.hp.hpl.jena.db.*;
import com.hp.hpl.jena.db.impl.*;
import com.hp.hpl.jena.rdf.model.impl.*;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.shared.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.ontology.daml.DAMLModel;
import com.hp.hpl.jena.ontology.daml.impl.DAMLModelImpl;
import com.hp.hpl.jena.ontology.impl.OntModelImpl;
/**
ModelFactory provides methods for creating standard kinds of Model.
(ModelFactoryBase is helper functions for it).
*/
public class ModelFactory extends ModelFactoryBase
{
/**
No-one can make instances of this.
*/
private ModelFactory()
{}
/**
The standard reification style; quadlets contribute to reified statements,
and are visible to listStatements().
*/
public static final ReificationStyle Standard = ReificationStyle.Standard;
/**
The convenient reification style; quadlets contribute to reified statements,
but are invisible to listStatements().
*/
public static final ReificationStyle Convenient = ReificationStyle.Convenient;
/**
The minimal reification style; quadlets do not contribute to reified statements,
and are visible to listStatements().
*/
public static final ReificationStyle Minimal = ReificationStyle.Minimal;
/**
Each Model created by ModelFactory has a default set of prefix mappings.
These mappings are copied from a (static) default PrefixMapping which is
set by setDefaultModelPrefixes. It is the reference to a PrefixMapping that
is retained, not a copy of it, so a user may set the defaults with this method
and continue to modify it; the modifications will appear in the next model to
be created.
<p>
When a Model is created from an existing Graph, the prefixes of that Graph
are not disturbed; only ones not present in the Graph are added.
@param pm the default prefixes to use
@return the previous default prefix mapping
*/
public static PrefixMapping setDefaultModelPrefixes( PrefixMapping pm )
{ return ModelCom.setDefaultModelPrefixes( pm ); }
/**
Answer the current default model prefixes PrefixMapping object.
*/
public static PrefixMapping getDefaultModelPrefixes()
{ return ModelCom.getDefaultModelPrefixes(); }
/**
Answer a ModelSpec which can create models to the specifications in the RDF
description. The root of the description is the unique resource of type ModelSpec.
@deprecated superceeded by the Assembler system
*/
public static ModelSpec createSpec( Model desc )
{ return ModelSpecFactory.createSpec( desc ); }
/**
Answer a ModelSpec which can create models to the specifcations in the RDF
description rooted at the given root.
@deprecated superceeded by the Assembler system
*/
public static ModelSpec createSpec( Resource root, Model desc )
{ return ModelSpecFactory.createSpec( ModelSpecFactory.withSchema( desc ), root ); }
/**
Answer a fresh Model created according to the ModelSpec argument.
@deprecated superceeded by the Assembler system
*/
public static Model createModel( ModelSpec desc )
{ return desc.createFreshModel(); }
/**
Answer a Model constructed from the single resource in
<code>singleRoot</code> of type <code>ja:Model</code>.
See the Assembler howto (doc/assembler/assembler-howto.html)
for documentation of Assembler descriptions. See also
<code>findAssemblerRoots</code> to find the set of possible
roots in a description, and <code>assemblerModelFrom(Resource)</code>
for assembling a model from its single description.
*/
public static Model assembleModelFrom( Model singleRoot )
{ return assembleModelFrom( AssemblerHelp.singleModelRoot( singleRoot ) ); }
/**
Answer a Set of resources present in <code>m</code> that are
explicitly or implicitly of type ja:Object, ie, suitable as roots for
<code>assemblerModelFrom</code>. Note that the resource
objects returned need <i>not</i> have <code>m</code> as
their <code>getModel()</code> - they may be members of an
extended constructed model.
*/
public static Set findAssemblerRoots( Model m )
{ return AssemblerHelp.findAssemblerRoots( m ); }
/**
Answer a Model as described the the Assembler specification rooted
at the Resource <code>root</code> in its Model. <code>Resource</code>
must be of rdf:type <code>ja:Object</code>, where <code>ja</code>
is the prefix of Jena Assembler objects.
*/
public static Model assembleModelFrom( Resource root )
{ return Assembler.general.openModel( root ); }
/**
Answer a fresh Model created according to the given specification and based on
any underlying model with the given name.
@param desc the ModelSpec which describes the kind of model to create
@param name the name of the base model in the underlying ModelMaker
@return a fresh model based over the named model
@deprecated superceeded by the Assembler system
*/
public static Model createModelOver( ModelSpec desc, String name )
{ return desc.createModelOver( name ); }
/**
Answer a fresh Model with the default specification and Standard reification style
[reification triples contribute to ReifiedStatements, and are visible to listStatements,
etc].
*/
public static Model createDefaultModel()
{ return createDefaultModel( Standard ); }
/**
Answer a new memory-based model with the given reification style
*/
public static Model createDefaultModel( ReificationStyle style )
{ return new ModelCom( Factory.createGraphMem( style ) ); }
/**
Answer a read-only Model with all the statements of this Model and any
statements "hidden" by reification. That model is dynamic, ie
any changes this model will be reflected that one.
*/
public static Model withHiddenStatements( Model m )
{ return ModelReifier.withHiddenStatements( m ); }
/**
construct a new memory-based model that does not capture reification triples
(but still handles reifyAs() and .as(ReifiedStatement).
*/
public static Model createNonreifyingModel()
{ return createDefaultModel( Minimal ); }
/**
Answer a model that encapsulates the given graph. Existing prefixes are
undisturbed.
@param g A graph structure
@return A model presenting an API view of graph g
*/
public static Model createModelForGraph( Graph g ) {
return new ModelCom( g );
}
/**
Answer a ModelMaker that constructs memory-based Models that
are backed by files in the root directory. The Model is loaded from the
file when it is opened, and when the Model is closed it is written back.
The model is given the Standard reification style.
@param root the name of the directory in which the backing files are held
@return a ModelMaker linked to the files in the root
*/
public static ModelMaker createFileModelMaker( String root )
{ return createFileModelMaker( root, Standard ); }
/**
Answer a ModelMaker that constructs memory-based Models that
are backed by files in the root directory. The Model is loaded from the
file when it is opened, and when the Model is closed it is written back.
@param root the name of the directory in which the backing files are held
@param style the desired reification style
@return a ModelMaker linked to the files in the root
*/
public static ModelMaker createFileModelMaker( String root, ReificationStyle style )
{ return new ModelMakerImpl( new FileGraphMaker( root, style ) ); }
/**
Answer a ModelMaker that constructs memory-based Models that do
not persist past JVM termination. The model has the Standard reification
style.
@return a ModelMaker that constructs memory-based models
*/
public static ModelMaker createMemModelMaker()
{ return createMemModelMaker( Standard ); }
/**
Answer a ModelMaker that constructs memory-based Models that do
not persist past JVM termination, with the given reification style.
@param style the reification style for the model
@return a ModelMaker that constructs memory-based models
*/
public static ModelMaker createMemModelMaker( ReificationStyle style )
{ return new ModelMakerImpl( new SimpleGraphMaker( style ) ); }
/**
Answer a ModelMaker that accesses database-backed Models on
the database at the other end of the connection c with the usual
Standard reification style.
@param c a connection to the database holding the models
@return a ModelMaker whose Models are held in the database at c
*/
public static ModelMaker createModelRDBMaker( IDBConnection c )
{ return createModelRDBMaker( c, Standard ); }
/**
Answer a ModelMaker that accesses database-backed Models on
the database at the other end of the connection c with the given
reification style.
@param c a connection to the database holding the models
@param style the desired reification style
@return a ModelMaker whose Models are held in the database at c
*/
public static ModelMaker createModelRDBMaker
( IDBConnection c, ReificationStyle style )
{ return new ModelRDBMaker( new GraphRDBMaker( c, style ) ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -