📄 ontresourceimpl.java
字号:
/*****************************************************************************
* Source code information
* -----------------------
* Original author Ian Dickinson, HP Labs Bristol
* Author email Ian.Dickinson@hp.com
* Package Jena 2
* Web http://sourceforge.net/projects/jena/
* Created 25-Mar-2003
* Filename $RCSfile: OntResourceImpl.java,v $
* Revision $Revision: 1.65 $
* Release status $State: Exp $
*
* Last modified on $Date: 2007/01/21 16:26:28 $
* by $Author: ian_dickinson $
*
* (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
* (see footer for full conditions)
*****************************************************************************/
// Package
///////////////
package com.hp.hpl.jena.ontology.impl;
// Imports
///////////////
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.enhanced.*;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.shared.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.rdf.model.impl.*;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.util.ResourceUtils;
import com.hp.hpl.jena.util.iterator.*;
import com.hp.hpl.jena.vocabulary.*;
import java.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* <p>
* Abstract base class to provide shared implementation for implementations of ontology
* resources.
* </p>
*
* @author Ian Dickinson, HP Labs
* (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
* @version CVS $Id: OntResourceImpl.java,v 1.65 2007/01/21 16:26:28 ian_dickinson Exp $
*/
public class OntResourceImpl
extends ResourceImpl
implements OntResource
{
// Constants
//////////////////////////////////
/** List of namespaces that are reserved for known ontology langauges */
public static final String[] KNOWN_LANGUAGES = new String[] {OWL.NS,
RDF.getURI(),
RDFS.getURI(),
DAMLVocabulary.NAMESPACE_DAML_2001_03_URI,
XSDDatatype.XSD};
// Static variables
//////////////////////////////////
/**
* A factory for generating OntResource facets from nodes in enhanced graphs.
* Note: should not be invoked directly by user code: use
* {@link com.hp.hpl.jena.rdf.model.RDFNode#as as()} instead.
*/
public static Implementation factory = new Implementation() {
public EnhNode wrap( Node n, EnhGraph eg ) {
if (canWrap( n, eg )) {
return new OntResourceImpl( n, eg );
}
else {
throw new ConversionException( "Cannot convert node " + n.toString() + " to OntResource");
}
}
public boolean canWrap( Node node, EnhGraph eg ) {
// node will support being an OntResource facet if it is a uri or bnode
return node.isURI() || node.isBlank();
}
};
private static final Log log = LogFactory.getLog( OntResourceImpl.class );
// Instance variables
//////////////////////////////////
// Constructors
//////////////////////////////////
/**
* <p>
* Construct an ontology resource represented by the given node in the given graph.
* </p>
*
* @param n The node that represents the resource
* @param g The enh graph that contains n
*/
public OntResourceImpl( Node n, EnhGraph g ) {
super( n, g );
}
// External signature methods
//////////////////////////////////
/**
* <p>Answer the model that this resource is attached to, assuming that it
* is an {@link OntModel}. If this resource is not attached to any model,
* or is (unusally) attached to a model that is not an <code>OntModel</code>,
* answer null.</p>
* @return The ont model that this resource is attached to, or null.
*/
public OntModel getOntModel() {
Model m = getModel();
return (m instanceof OntModel) ? (OntModel) m : null;
}
/**
* <p>
* Answer the ontology language profile that governs the ontology model to which
* this ontology resource is attached.
* </p>
*
* @return The language profile for this ontology resource
* @throws JenaException if the resource is not bound to an OntModel, since
* that's the only way to get the profile for the resource
*/
public Profile getProfile() {
try {
return ((OntModel) getModel()).getProfile();
}
catch (ClassCastException e) {
throw new JenaException( "Resource " + toString() + " is not attached to an OntModel, so cannot access its language profile" );
}
}
/**
* <p>Answer true if this resource is a symbol in one of the standard ontology
* languages supported by Jena: RDF, RDFS, OWL or DAML+OIL. Since these languages
* have restricted namespaces, this check is simply a convenient way of testing whether
* this resource is in one of those pre-declared namespaces.</p>
* @return True if this is a term in the language namespace for OWL, RDF, RDFS or DAML+OIL.
*/
public boolean isOntLanguageTerm() {
if (!isAnon()) {
for (int i = 0; i < KNOWN_LANGUAGES.length; i++) {
if (getURI().startsWith( KNOWN_LANGUAGES[i] )) {
return true;
}
}
}
return false;
}
// sameAs
/**
* <p>Assert equivalence between the given resource and this resource. Any existing
* statements for <code>sameAs</code> will be removed.</p>
* @param res The resource that is declared to be the same as this resource
* @exception OntProfileException If the {@link Profile#SAME_AS()} property is not supported in the current language profile.
*/
public void setSameAs( Resource res ) {
setPropertyValue( getProfile().SAME_AS(), "SAME_AS", res );
}
/**
* <p>Add a resource that is declared to be equivalent to this resource.</p>
* @param res A resource that declared to be the same as this resource
* @exception OntProfileException If the {@link Profile#SAME_AS()} property is not supported in the current language profile.
*/
public void addSameAs( Resource res ) {
addPropertyValue( getProfile().SAME_AS(), "SAME_AS", res );
}
/**
* <p>Answer a resource that is declared to be the same as this resource. If there is
* more than one such resource, an arbitrary selection is made.</p>
* @return res An ont resource that declared to be the same as this resource
* @exception OntProfileException If the {@link Profile#SAME_AS()} property is not supported in the current language profile.
*/
public OntResource getSameAs() {
return objectAsResource( getProfile().SAME_AS(), "SAME_AS" );
}
/**
* <p>Answer an iterator over all of the resources that are declared to be the same as
* this resource. Each elemeent of the iterator will be an {@link OntResource}.</p>
* @return An iterator over the resources equivalent to this resource.
* @exception OntProfileException If the {@link Profile#SAME_AS()} property is not supported in the current language profile.
*/
public ExtendedIterator listSameAs() {
return listAs( getProfile().SAME_AS(), "SAME_AS", OntResource.class );
}
/**
* <p>Answer true if this resource is the same as the given resource.</p>
* @param res A resource to test against
* @return True if the resources are declared the same via a <code>sameAs</code> statement.
*/
public boolean isSameAs( Resource res ) {
return hasPropertyValue( getProfile().SAME_AS(), "SAME_AS", res );
}
/**
* <p>Remove the statement that this resource is the same as the given resource. If this statement
* is not true of the current model, nothing happens.</p>
* @param res A resource that may be declared to be the sameAs this resource
*/
public void removeSameAs( Resource res ) {
removePropertyValue( getProfile().SAME_AS(), "SAME_AS", res );
}
// differentFrom
/**
* <p>Assert that the given resource and this resource are distinct. Any existing
* statements for <code>differentFrom</code> will be removed.</p>
* @param res The resource that is declared to be distinct from this resource
* @exception OntProfileException If the {@link Profile#DIFFERENT_FROM()} property is not supported in the current language profile.
*/
public void setDifferentFrom( Resource res ) {
setPropertyValue( getProfile().DIFFERENT_FROM(), "DIFFERENT_FROM", res );
}
/**
* <p>Add a resource that is declared to be equivalent to this resource.</p>
* @param res A resource that declared to be the same as this resource
* @exception OntProfileException If the {@link Profile#DIFFERENT_FROM()} property is not supported in the current language profile.
*/
public void addDifferentFrom( Resource res ) {
addPropertyValue( getProfile().DIFFERENT_FROM(), "DIFFERENT_FROM", res );
}
/**
* <p>Answer a resource that is declared to be distinct from this resource. If there is
* more than one such resource, an arbitrary selection is made.</p>
* @return res An ont resource that declared to be different from this resource
* @exception OntProfileException If the {@link Profile#DIFFERENT_FROM()} property is not supported in the current language profile.
*/
public OntResource getDifferentFrom() {
return objectAsResource( getProfile().DIFFERENT_FROM(), "DIFFERENT_FROM" );
}
/**
* <p>Answer an iterator over all of the resources that are declared to be different from
* this resource. Each elemeent of the iterator will be an {@link OntResource}.</p>
* @return An iterator over the resources different from this resource.
* @exception OntProfileException If the {@link Profile#DIFFERENT_FROM()} property is not supported in the current language profile.
*/
public ExtendedIterator listDifferentFrom() {
return listAs( getProfile().DIFFERENT_FROM(), "DIFFERENT_FROM", OntResource.class );
}
/**
* <p>Answer true if this resource is different from the given resource.</p>
* @param res A resource to test against
* @return True if the resources are declared to be distinct via a <code>differentFrom</code> statement.
*/
public boolean isDifferentFrom( Resource res ) {
return hasPropertyValue( getProfile().DIFFERENT_FROM(), "DIFFERENT_FROM", res );
}
/**
* <p>Remove the statement that this resource is different the given resource. If this statement
* is not true of the current model, nothing happens.</p>
* @param res A resource that may be declared to be differentFrom this resource
*/
public void removeDifferentFrom( Resource res ) {
removePropertyValue( getProfile().DIFFERENT_FROM(), "DIFFERENT_FROM", res );
}
// seeAlso
/**
* <p>Assert that the given resource provides additional information about the definition of this resource</p>
* @param res A resource that can provide additional information about this resource
* @exception OntProfileException If the {@link Profile#SEE_ALSO()} property is not supported in the current language profile.
*/
public void setSeeAlso( Resource res ) {
setPropertyValue( getProfile().SEE_ALSO(), "SEE_ALSO", res );
}
/**
* <p>Add a resource that is declared to provided additional information about the definition of this resource</p>
* @param res A resource that provides extra information on this resource
* @exception OntProfileException If the {@link Profile#SEE_ALSO()} property is not supported in the current language profile.
*/
public void addSeeAlso( Resource res ) {
addPropertyValue( getProfile().SEE_ALSO(), "SEE_ALSO", res );
}
/**
* <p>Answer a resource that provides additional information about this resource. If more than one such resource
* is defined, make an arbitrary choice.</p>
* @return res A resource that provides additional information about this resource
* @exception OntProfileException If the {@link Profile#SEE_ALSO()} property is not supported in the current language profile.
*/
public Resource getSeeAlso() {
return objectAsResource( getProfile().SEE_ALSO(), "SEE_ALSO" );
}
/**
* <p>Answer an iterator over all of the resources that are declared to provide addition
* information about this resource.</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -