📄 ontpropertyimpl.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 31-Mar-2003
* Filename $RCSfile: OntPropertyImpl.java,v $
* Revision $Revision: 1.24 $
* Release status $State: Exp $
*
* Last modified on $Date: 2007/01/02 11:49:47 $
* by $Author: andy_seaborne $
*
* (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 java.util.*;
import com.hp.hpl.jena.enhanced.*;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.iterator.*;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.util.iterator.Filter;
/**
* <p>
* Implementation of the abstraction representing a general ontology property.
* </p>
*
* @author Ian Dickinson, HP Labs
* (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
* @version CVS $Id: OntPropertyImpl.java,v 1.24 2007/01/02 11:49:47 andy_seaborne Exp $
*/
public class OntPropertyImpl
extends OntResourceImpl
implements OntProperty
{
// Constants
//////////////////////////////////
// Static variables
//////////////////////////////////
/**
* A factory for generating OntProperty 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 OntPropertyImpl( n, eg );
}
else {
throw new ConversionException( "Cannot convert node " + n + " to OntProperty");
}
}
public boolean canWrap( Node node, EnhGraph eg ) {
// node will support being an OntProperty facet if it has rdf:type owl:Property or equivalent
Profile profile = (eg instanceof OntModel) ? ((OntModel) eg).getProfile() : null;
return (profile != null) && profile.isSupported( node, eg, OntProperty.class );
}
};
// Instance variables
//////////////////////////////////
// Constructors
//////////////////////////////////
/**
* <p>
* Construct an ontology property 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 OntPropertyImpl( Node n, EnhGraph g ) {
super( n, g );
}
// External signature methods
//////////////////////////////////
/**
* <p>
* Answer true to indicate that this resource is an RDF property.
* </p>
*
* @return True.
*/
public boolean isProperty() {
return true;
}
/**
* @see Property#getOrdinal()
*/
public int getOrdinal() {
return ((Property) as( Property.class )).getOrdinal();
}
// subPropertyOf
/**
* <p>Assert that this property is sub-property of the given property. Any existing
* statements for <code>subPropertyOf</code> will be removed.</p>
* @param prop The property that this property is a sub-property of
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public void setSuperProperty( Property prop ) {
setPropertyValue( getProfile().SUB_PROPERTY_OF(), "SUB_PROPERTY_OF", prop );
}
/**
* <p>Add a super-property of this property.</p>
* @param prop A property that is a super-property of this property.
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public void addSuperProperty( Property prop ) {
addPropertyValue( getProfile().SUB_PROPERTY_OF(), "SUB_PROPERTY_OF", prop );
}
/**
* <p>Answer a property that is the super-property of this property. If there is
* more than one such property, an arbitrary selection is made.</p>
* @return A super-property of this property
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public OntProperty getSuperProperty() {
return objectAsProperty( getProfile().SUB_PROPERTY_OF(), "SUB_PROPERTY_OF" );
}
/**
* <p>Answer an iterator over all of the properties that are declared to be super-properties of
* this property. Each elemeent of the iterator will be an {@link OntProperty}.</p>
* @return An iterator over the super-properties of this property.
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public ExtendedIterator listSuperProperties() {
return listSuperProperties( false );
}
/**
* <p>Answer an iterator over all of the properties that are declared to be super-properties of
* this property. Each elemeent of the iterator will be an {@link OntProperty}.</p>
* @param direct If true, only answer the direcly adjacent properties in the
* property hierarchy: i.e. eliminate any property for which there is a longer route
* to reach that child under the super-property relation.
* @return An iterator over the super-properties of this property.
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public ExtendedIterator listSuperProperties( boolean direct ) {
return listDirectPropertyValues( getProfile().SUB_PROPERTY_OF(), "SUB_PROPERTY_OF", OntProperty.class, getProfile().SUB_PROPERTY_OF(), direct, false );
}
/**
* <p>Answer true if the given property is a super-property of this property.</p>
* @param prop A property to test.
* @param direct If true, only consider the direcly adjacent properties in the
* property hierarchy
* @return True if the given property is a super-property of this property.
*/
public boolean hasSuperProperty( Property prop, boolean direct ) {
return hasPropertyValue( getProfile().SUB_PROPERTY_OF(), "SUB_PROPERTY_OF", prop );
}
/**
* <p>Remove the given property from the super-properties of this property. If this statement
* is not true of the current model, nothing happens.</p>
* @param prop A property to be removed from the super-properties of this property
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public void removeSuperProperty( Property prop ) {
removePropertyValue( getProfile().SUB_PROPERTY_OF(), "SUB_PROPERTY_OF", prop );
}
/**
* <p>Assert that this property is super-property of the given property. Any existing
* statements for <code>subPropertyOf</code> on <code>prop</code> will be removed.</p>
* @param prop The property that is a sub-property of this property
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public void setSubProperty( Property prop ) {
// first we have to remove all of the inverse sub-prop links
checkProfile( getProfile().SUB_PROPERTY_OF(), "SUB_PROPERTY_OF" );
for (StmtIterator i = getModel().listStatements( null, getProfile().SUB_PROPERTY_OF(), this ); i.hasNext(); ) {
i.removeNext();
}
((OntProperty) prop.as( OntProperty.class )).addSuperProperty( this );
}
/**
* <p>Add a sub-property of this property.</p>
* @param prop A property that is a sub-property of this property.
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public void addSubProperty( Property prop ) {
((OntProperty) prop.as( OntProperty.class )).addSuperProperty( this );
}
/**
* <p>Answer a property that is the sub-property of this property. If there is
* more than one such property, an arbitrary selection is made.</p>
* @return A sub-property of this property
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public OntProperty getSubProperty() {
checkProfile( getProfile().SUB_PROPERTY_OF(), "SUB_PROPERTY_OF" );
return (OntProperty) getModel().listStatements( null, getProfile().SUB_PROPERTY_OF(), this )
.nextStatement()
.getSubject()
.as( OntProperty.class );
}
/**
* <p>Answer an iterator over all of the properties that are declared to be sub-properties of
* this property. Each element of the iterator will be an {@link OntProperty}.</p>
* @return An iterator over the sub-properties of this property.
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public ExtendedIterator listSubProperties() {
return listSubProperties( false );
}
/**
* <p>Answer an iterator over all of the properties that are declared to be sub-properties of
* this property. Each element of the iterator will be an {@link OntProperty}.</p>
* @param direct If true, only answer the direcly adjacent properties in the
* property hierarchy: i.e. eliminate any property for which there is a longer route
* to reach that child under the sub-property relation.
* @return An iterator over the sub-properties of this property.
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public ExtendedIterator listSubProperties( boolean direct ) {
return listDirectPropertyValues( getProfile().SUB_PROPERTY_OF(), "SUB_PROPERTY_OF", OntProperty.class, getProfile().SUB_PROPERTY_OF(), direct, true );
}
/**
* <p>Answer true if the given property is a sub-property of this property.</p>
* @param prop A property to test.
* @param direct If true, only consider the direcly adjacent properties in the
* property hierarchy
* @return True if the given property is a sub-property of this property.
*/
public boolean hasSubProperty( Property prop, boolean direct ) {
return ((OntProperty) prop.as( OntProperty.class )).hasSuperProperty( this, direct );
}
/**
* <p>Remove the given property from the sub-properties of this property. If this statement
* is not true of the current model, nothing happens.</p>
* @param prop A property to be removed from the sub-properties of this property
* @exception OntProfileException If the {@link Profile#SUB_PROPERTY_OF()} property is not supported in the current language profile.
*/
public void removeSubProperty( Property prop ) {
((OntProperty) prop.as( OntProperty.class )).removeSuperProperty( this );
}
// domain
/**
* <p>Assert that the given resource represents the class of individuals that form the
* domain of this property. Any existing <code>domain</code> statements for this property are removed.</p>
* @param res The resource that represents the domain class for this property.
* @exception OntProfileException If the {@link Profile#DOMAIN()} property is not supported in the current language profile.
*/
public void setDomain( Resource res ) {
setPropertyValue( getProfile().DOMAIN(), "DOMAIN", res );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -