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

📄 damlpropertyimpl.java

📁 jena2.5.4推理机系统的一种最基本实现 HP实验室出品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
 * Source code information
 * -----------------------
 * Original author    Ian Dickinson, HP Labs Bristol
 * Author email       Ian.Dickinson@hp.com
 * Package            Jena
 * Created            4 Jan 2001
 * Filename           $RCSfile: DAMLPropertyImpl.java,v $
 * Revision           $Revision: 1.12 $
 * Release status     Preview-release $State: Exp $
 *
 * Last modified on   $Date: 2007/01/08 14:40:30 $
 *               by   $Author: ian_dickinson $
 *
 * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
 * (see footer for full conditions)
 *****************************************************************************/

// Package
///////////////
package com.hp.hpl.jena.ontology.daml.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.ontology.daml.*;
import com.hp.hpl.jena.ontology.impl.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.iterator.*;
import com.hp.hpl.jena.vocabulary.*;


/**
 * <p>Encapsulates a property in a DAML ontology.  According to the specification,
 * a daml:Property is an alias for rdf:Property.  It also acts as the super-class for
 * more semantically meaningful property classes: datatype properties and object properties.
 * The DAML spec also allows any property to be unique (that is, it defines UniqueProperty
 * as a sub-class of Property), so uniqueness is modelled here as an attribute of a DAMLProperty.</p>
 *
 * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
 * @version CVS info: $Id: DAMLPropertyImpl.java,v 1.12 2007/01/08 14:40:30 ian_dickinson Exp $
 * @deprecated The DAML API is scheduled to be removed from Jena 2.6 onwards. Please use the DAML profile in the main ontology API
 */
public class DAMLPropertyImpl
    extends OntPropertyImpl
    implements DAMLProperty
{
    // Constants
    //////////////////////////////////


    // Static variables
    //////////////////////////////////

    /**
     * A factory for generating DAMLProperty 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 DAMLPropertyImpl( n, eg );
            }
            else {
                throw new ConversionException( "Cannot convert node " + n.toString() + " to DAMLProperty" );
            }
        }

        public boolean canWrap( Node node, EnhGraph eg ) {
            return hasType( node, eg, DAML_OIL.Property ) ||
                   hasType( node, eg, DAML_OIL.DatatypeProperty ) ||
                   hasType( node, eg, DAML_OIL.ObjectProperty );
        }
    };


    // Instance variables
    //////////////////////////////////

    /** Vocabulary */
    private DAMLVocabulary m_vocabulary = VocabularyManager.getDefaultVocabulary();

    /** Property accessor for domain */
    private PropertyAccessor m_propDomain = new PropertyAccessorImpl( getVocabulary().domain(), this );

    /** Property accessor for range */
    private PropertyAccessor m_propRange = new PropertyAccessorImpl( getVocabulary().range(), this );

    /** Property accessor for subPropertyOf */
    private PropertyAccessor m_propSubPropertyOf = new PropertyAccessorImpl( getVocabulary().subPropertyOf(), this );

    /** Property accessor for samePropertyAs */
    private PropertyAccessor m_propSamePropertyAs = new PropertyAccessorImpl( getVocabulary().samePropertyAs(), this );

    /** DAMLCommon delegate */
    private DAMLCommon m_common = null;


    // Constructors
    //////////////////////////////////

    /**
     * <p>
     * Construct a DAML 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 DAMLPropertyImpl( Node n, EnhGraph g ) {
        super( n, g );
        m_common = new DAMLCommonImpl( n, g );
    }



    // External signature methods
    //////////////////////////////////

    // delegate to DAMLCommon what we can
    /** @deprecated */
    public void setRDFType( Resource rdfClass, boolean replace ) { m_common.setRDFType( rdfClass, replace ); }
    public DAMLModel getDAMLModel()                              { return m_common.getDAMLModel(); }
    public ExtendedIterator getRDFTypes( boolean complete )      { return m_common.getRDFTypes( complete ); }
    public DAMLVocabulary getVocabulary()                        { return m_vocabulary; }
    public LiteralAccessor prop_label()                          { return m_common.prop_label(); }
    public LiteralAccessor prop_comment()                        { return m_common.prop_comment(); }
    public PropertyAccessor prop_equivalentTo()                  { return m_common.prop_equivalentTo(); }
    public PropertyAccessor prop_type()                          { return m_common.prop_type(); }

    /**
     * <p>Answer an iterator over all of the DAML objects that are equivalent to this
     * class, which will be the union of <code>daml:equivalentTo</code> and
     * <code>daml:sameClassAs</code>.</p>
     *
     * @return an iterator ranging over every equivalent DAML class
     */
    public ExtendedIterator getEquivalentValues() {
        ConcatenatedIterator i = new ConcatenatedIterator(
                       // first the iterator over the equivalentTo values
                       m_common.getEquivalentValues(),
                       // followed by the samePropertyAs values
                       getSameProperties() );

        return UniqueExtendedIterator.create( i ).mapWith( new AsMapper( DAMLProperty.class ) );
    }


    /**
     * Answer the set of equivalent values to this value, but not including the
     * value itself.  The iterator will range over a set: each element occurs only
     * once.
     *
     * @return An iteration ranging over the set of values that are equivalent to this
     *         value, but not itself.
     */
    public ExtendedIterator getEquivalenceSet() {
        Set s = new HashSet();

        s.add( this );
        for (Iterator i = getEquivalentValues();  i.hasNext();  s.add( i.next() ) );
        s.remove( this );

        return WrappedIterator.create( s.iterator() );
    }




    /**
     * Set the flag to indicate that this property is to be considered
     * unique - that is, it is defined by the DAML class UniqueProperty.
     *
     * @param unique True for a unique property
     */
    public void setIsUnique( boolean unique ) {
        if (unique) {
            // add the unique type to this property
            addRDFType( getVocabulary().UniqueProperty() );
        }
        else {
            // remove the transitive type from this property
            removeProperty( RDF.type, getVocabulary().UniqueProperty() );
        }
    }


    /**
     * Answer true if this property is to be considered unique, that is
     * it is characterised by the DAML class UniqueProperty
     *
     * @return True if this property is unique
     */
    public boolean isUnique() {
        return hasRDFType( getVocabulary().UniqueProperty() );

⌨️ 快捷键说明

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