📄 damlmodelimpl.java
字号:
* of the concrete domain type (e.g. as an XSD datatype).
* @return A new DAMLDatatype object.
*/
public DAMLDatatype createDAMLDatatype( String uri ) {
Resource dt = getResource( uri );
dt.addProperty( RDF.type, DAML_OIL.Datatype );
return (DAMLDatatype) dt.as( DAMLDatatype.class );
}
/**
* <p>Create a new DAML value that is a member of the given class. The appropriate
* {@link DAMLCommon} sub-class will be instantiated, so, for example, if the <code>damlClass</code>
* is {@link DAML_OIL#Restriction}, a {@link DAMLRestriction}
* object will be returned. Note that if a URI is given, and a value with that
* URI already exists in the model, that instance will be returned instead of
* creating a new DAML value. This is necessary to maintain consistency of the model.</p>
*
* @param uri The URI of the new DAML value, or null for an anonymous value
* @param damlClass The class to which the new DAML value will belong
* @return An instance of a DAMLCommon value that corresponds to the given class.
*/
public DAMLCommon createDAMLValue( String uri, Resource damlClass ) {
Class javaClass = DAMLInstance.class;
// see if we can match the DAML class to a known type
for (int i = 0; i < DAML_CLASS_TABLE.length; i++) {
if (DAML_CLASS_TABLE[i][0].equals( damlClass )) {
javaClass = (Class) DAML_CLASS_TABLE[i][1];
break;
}
}
return (DAMLCommon) createOntResource( javaClass, damlClass, uri );
}
/**
* <p>Answer the DAML value that corresponds to the given URI, if it exists in the
* model. If the URI does not match any of the resources presently in the model,
* null is returned.</p>
*
* @param uri The URI of the DAML resource to look for.
* @return An existing DAML resource from the model, matching uri, or null if
* no such resource is found.
*/
public DAMLCommon getDAMLValue( String uri ) {
Node n = Node.createURI( uri );
if (getGraph().queryHandler().containsNode( n )) {
return (DAMLCommon) ((Resource) asRDFNode( n )).as( DAMLCommon.class );
}
else {
return null;
}
}
/**
* <p>Answer the DAML value that corresponds to the given URI, if it exists in the
* model. If the URI does not match any of the resources presently in the model,
* create a new DAML resource with the given URI and vocabulary, from the given
* DAML class.</p>
*
* @param uri The URI of the DAML resource to look for.
* @param damlClass The class of the new resource to create if no existing resource
* is found.
* @return An existing DAML resource from the model, matching uri, or a new
* resource if no existing resource is found.
*/
public DAMLCommon getDAMLValue( String uri, DAMLClass damlClass ) {
DAMLCommon res = getDAMLValue( uri );
return (res == null && damlClass != null) ? createDAMLValue( uri, damlClass ) : res;
}
/**
* <p>Answer an iterator over all DAML classes that are presently in the model.</p>
*
* @return An iterator over all currently defined classes (including Restrictions).
*/
public ExtendedIterator listDAMLClasses() {
return UniqueExtendedIterator.create( findByTypeAs( getProfile().CLASS(), null, DAMLClass.class ) );
}
/**
* <p>Answer an iterator over all DAML properties that are presently in the model.</p>
*
* @return An iterator over all currently defined properties (i.e. rdf:Property and
* all sub-classes).
*/
public ExtendedIterator listDAMLProperties() {
return UniqueExtendedIterator.create( findByTypeAs( getProfile().PROPERTY(), null, DAMLProperty.class ) );
}
/**
* <p>Answer an iterator over all DAML instances that are presently in the model.</p>
*
* @return An iterator over all currently defined DAML instances.
*/
public ExtendedIterator listDAMLInstances() {
return UniqueExtendedIterator.create( listIndividuals().mapWith( new Map1() {
public Object map1(Object x){ return ((Resource) x).as( DAMLInstance.class );} } ) );
}
/**
* <p>Answer a resource from the current model with the given uri, viewed as a DAML Class.</p>
* @param uri The uri of the resource to fetch
* @return The class resource with the given URI, or null
*/
public DAMLClass getDAMLClass( String uri ) {
Node n = Node.createURI( uri );
if (getGraph().queryHandler().containsNode( n )) {
return (DAMLClass) ((Resource) asRDFNode( n )).as( DAMLClass.class );
}
else {
return null;
}
}
/**
* <p>Answer a resource from the current model with the given uri, viewed as a DAML Property.</p>
* @param uri The uri of the resource to fetch
* @return The property resource with the given URI, or null
*/
public DAMLProperty getDAMLProperty( String uri ) {
Node n = Node.createURI( uri );
if (getGraph().queryHandler().containsNode( n )) {
return (DAMLProperty) ((Resource) asRDFNode( n )).as( DAMLProperty.class );
}
else {
return null;
}
}
/**
* <p>Answer a resource from the current model with the given uri, viewed as a DAML Instance.</p>
* @param uri The uri of the resource to fetch
* @return The instance resource with the given URI, or null
*/
public DAMLInstance getDAMLInstance( String uri ) {
Node n = Node.createURI( uri );
if (getGraph().queryHandler().containsNode( n )) {
return (DAMLInstance) ((Resource) asRDFNode( n )).as( DAMLInstance.class );
}
else {
return null;
}
}
/**
* <p>Read the ontology indicated by the given uri. Note that, depending on the settings in the
* embedded {@link DAMLLoader}, ontology import statements embedded in this document will be
* processed and the ontologies fetched and loaded.</p>
*
* @param uri The URI identifying an ontology to be added.
* @param base The base URI for any relative names that are loaded from the source document
* @param lang Denotes the language the statements are represented in.
* @return self.
* @see Model#read( String, String )
*/
public Model read( String uri, String base, String lang ) {
try {
URL url = new URL( uri );
return read( url.openStream(), base, lang );
}
catch (IOException e) {
throw new OntologyException( "I/O error while reading from uri " + uri );
}
}
/**
* <p>Answer a reference to the loader for this DAML model</p>
*
* @return a DAMLLoader reference
*/
public DAMLLoader getLoader() {
return m_loader;
}
/**
* </p>Answer true if the most recent load operation was successful. If not,
* consult {@link DAMLLoader#getStatus} for details, and check error log.</p>
*
* @return True if the most recent model load was successful
*/
public boolean getLoadSuccessful() {
return getLoader().getStatus() == DAMLLoader.STATUS_OK;
}
/**
* <p>Answer a reference to the XML datatype registry for this model, that can be used to
* map between XML data marked up using XML Schema data descriptions, and Java objects.
* This method has changed since Jena1, and now uses the much more clearly defined mechanism
* for datatypes that has been specified for RDF. This updated specification is represented
* in Jena2 via the <code>com.hp.hpl.jena.datatypes</code> package.
* </p>
*
* @return An XML datatype mapper
*/
public TypeMapper getDatatypeRegistry() {
return TypeMapper.getInstance();
}
/**
* <p>Flag to control whether accessing the DAML store will take into account equivalence classes for
* properties and resources, using <code>daml:equivalentTo</code> and similar
* statements. In Jena 2, equivalence processing is delegated to the inference
* engine that is used to wrap the graph. Therefore, setting a flag at this API level
* is not useful, and this method is therefore deprecated.</p>
*
* @param useEquivalence If true, accessing properties and resources will check for
* equivalent values, at a cost of reduced performance.
* @deprecated Not useful in Jena2, since equivalence processing is handled by the inference graph.
*/
public void setUseEquivalence( boolean useEquivalence ) {
}
/**
* <p>Answer true if the model will consider equivalence classes when accessing
* properties and resources. See {@link #setUseEquivalence} for details.
* In Jena 2, equivalence processing is delegated to the inference
* engine that is used to wrap the graph. Therefore, setting a flag at this API level
* is not useful, and this method is therefore deprecated.</p>
*
* @return True if equivalence classes are being considered.
* @deprecated Not useful in Jena2, since equivalence processing is handled by the inference graph.
*/
public boolean getUseEquivalence() {
return true;
}
// Internal implementation methods
//////////////////////////////////
/**
* Initialise the store with well-known values.
*/
protected void initStore() {
}
/**
* Answer true if the model contains the given resource.
*
* @param uri The string URI of the resource to test
* @return True if the resource appears in any subject, predicate or object position in the model.
*/
protected boolean containsResource( String uri ) {
return containsResource( getResource( uri ) );
}
//==============================================================================
// Inner class definitions
//==============================================================================
}
/*
(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 + -