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

📄 damlmodelimpl.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************
 * Source code information
 * -----------------------
 * Original author    Ian Dickinson, HP Labs Bristol
 * Author email       Ian.Dickinson@hp.com
 * Package            Jena
 * Created            5 Jan 2001
 * Filename           $RCSfile: DAMLModelImpl.java,v $
 * Revision           $Revision: 1.20 $
 * 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.net.*;
import java.io.*;
import java.util.*;

import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.shared.JenaException;
import com.hp.hpl.jena.util.iterator.*;
import com.hp.hpl.jena.datatypes.*;
import com.hp.hpl.jena.datatypes.TypeMapper;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.ontology.daml.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.ontology.impl.*;
import com.hp.hpl.jena.vocabulary.*;



/**
 * <p>
 * Implementation for the DAML model interface, which is a specialisation of a Jena
 * RDF store for the application of storing and manipulating DAML objects.  The
 * specialisations include storing a set of DAML wrapper objects that provide a
 * convenience interface to the underlying RDF statements, and providing a set of
 * indexes for efficiently retrieving these objects.
 * </p>
 *
 * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
 * @version CVS info: $Id: DAMLModelImpl.java,v 1.20 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 DAMLModelImpl
    extends OntModelImpl
    implements DAMLModel
{
    // Constants
    //////////////////////////////////


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

    /** Encodes which Java class to instantiate for a given DAML class */
    protected static Object[][] DAML_CLASS_TABLE = new Object[][] {
        // DAML class instance                   Corresponding java class
        { DAML_OIL.Class,                        DAMLClassImpl.class },
        { RDFS.Class,                            DAMLClassImpl.class },

        { DAML_OIL.Restriction,                  DAMLRestrictionImpl.class },

        { DAML_OIL.List,                         DAMLListImpl.class },

        { DAML_OIL.Ontology,                     DAMLOntologyImpl.class },

        { DAML_OIL.Property,                     DAMLPropertyImpl.class },
        { RDF.Property,                          DAMLPropertyImpl.class },

        { DAML_OIL.DatatypeProperty,             DAMLDatatypePropertyImpl.class },
        { DAML_OIL.ObjectProperty,               DAMLObjectPropertyImpl.class },

        { DAML_OIL.UniqueProperty,               DAMLPropertyImpl.class },
        { DAML_OIL.TransitiveProperty,           DAMLObjectPropertyImpl.class },
        { DAML_OIL.UnambiguousProperty,          DAMLObjectPropertyImpl.class }
    };


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

    /** The loader that will load DAML source documents for this store */
    private DAMLLoader m_loader = new DAMLLoader( this );



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

    /**
     * Constructor, initialises internal data structures.
     */
    public DAMLModelImpl( OntModelSpec spec, Model m ) {
        super( spec, m );

        // create well-known values
        initStore();
    }



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

    /**
     * <p>Create an (optionally anonymous) Ontology (big-'O') element,
     * which holds meta-information for the ontology (small-'o').
     * <b>N.B.</b> This does not create a new
     * ontology, it simply makes an entry in the current model.</p>
     *
     * @param uri The URI for the new Ontology, or null to create an anonymous
     *            Ontology. Ideally provide the URL in which the Ontology is
     *            stored.
     *            Conventionally, in the RDF/XML serialization, we have
     *            <pre>
     *             &lt;daml:Ontology rdf:about=""&gt;
     *            </pre>
     *            The empty URIref in the above RDF/XML is known as a
     *            <Q>same document reference</Q> and expands to the
     *            URL of the current file.
     * @return A new DAMLOntology object, which is created by adding the
     *         appropriate statements to the RDF model.
     */
    public DAMLOntology createDAMLOntology( String uri ) {
        return (DAMLOntology) createOntResource( DAMLOntology.class, getProfile().ONTOLOGY(), uri );
    }


    /**
     * <p>Create an (optionally anonymous) instance of the given class.</p>
     *
     * @param damlClass The class of the newly created DAMLInstance
     * @param uri The URI for the new instance, or null to create an anonymous instance.
     * @return A new DAMLInstance object.
     */
    public DAMLInstance createDAMLInstance( DAMLClass damlClass, String uri ) {
        return (DAMLInstance) createOntResource( DAMLInstance.class, damlClass, uri );
    }


    /**
     * <p>Create an anonymous data instance, which has the given datatype and value.</p>
     * @param datatype A resource denoting the datatype of the new data instance object
     * @param value The value of the data instance
     * @return A new DAMLDataInstance object.
     */
    public DAMLDataInstance createDAMLDataInstance( Resource datatype, Object value ) {
        return createDAMLDataInstance( TypeMapper.getInstance().getTypeByName( datatype.getURI() ), value );
    }


    /**
     * <p>Create an anonymous data instance, which has the given datatype and value.</p>
     * @param datatype A resource denoting the datatype of the new data instance object
     * @param value The value of the data instance
     * @return A new DAMLDataInstance object.
     */
    public DAMLDataInstance createDAMLDataInstance( RDFDatatype datatype, Object value ) {
        Resource bNode = createResource( getResource( datatype.getURI() ) );
        bNode.addProperty( RDF.value, createTypedLiteral( value, datatype ) );
        return (DAMLDataInstance) bNode.as( DAMLDataInstance.class );
    }


    /**
     * <p>Create an anonymous data instance, which has the given value and an appropriate datatype.</p>
     * @param value The value of the data instance
     * @return A new DAMLDataInstance object.
     */
    public DAMLDataInstance createDAMLDataInstance( Object value ) {
        RDFDatatype datatype = TypeMapper.getInstance().getTypeByValue( value );
        if (datatype == null) {
            throw new JenaException( "Could not determine an appropriate datatype for value " + value );
        }
        else {
            return createDAMLDataInstance( datatype, value );
        }
    }


    /**
     * <p>Create an (optionally anonymous) DAML class.</p>
     *
     * @param uri The URI for the new class, or null to create an anonymous class.
     * @return A new DAMLClass object, which is created by adding the
     *         appropriate statements to the RDF model.
     */
    public DAMLClass createDAMLClass( String uri ) {
        return (DAMLClass) createOntResource( DAMLClass.class, getProfile().CLASS(), uri );
    }


    /**
     * <p>Create a DAML property. Note that it is recommended
     * to use one of the more specific property classes from the new DAML release:
     * see {@link #createDAMLObjectProperty} or {@link #createDAMLDatatypeProperty}.</p>
     *
     * @param uri The URI for the new property. May not be null.
     * @return A new DAMLProperty object, which is created by adding the
     *         appropriate statements to the RDF model.
     */
    public DAMLProperty createDAMLProperty( String uri ) {
        return (DAMLProperty) createOntResource( DAMLProperty.class, getProfile().PROPERTY(), uri );
    }


    /**
     * <p>Create a DAML object property. An object property has ontology individuals
     * (instances) in its range, whereas a datatype property has concrete data literals
     * in the range.</p>
     *
     * @param uri The URI for the new object property. May not be null.
     * @return A new <code>DAMLObjectProperty</code> object.
     */
    public DAMLObjectProperty createDAMLObjectProperty( String uri ) {
        return (DAMLObjectProperty) createOntResource( DAMLObjectProperty.class, getProfile().OBJECT_PROPERTY(), uri );
    }


    /**
     * <p>Create an (optionally anonymous) DAML datatype property. A datatype property has
     * concrete data literals
     * in its range, whereas an object property has ontology individuals (instances)
     * in the range.</p>
     *
     * @param uri The URI for the new datatype property. May not be null.
     * @return A new DAMLDatatypeProperty object.
     */
    public DAMLDatatypeProperty createDAMLDatatypeProperty( String uri ) {
        return (DAMLDatatypeProperty) createOntResource( DAMLDatatypeProperty.class, getProfile().DATATYPE_PROPERTY(), uri );
    }

    /**
     * <p>Create an empty DAML list.</p>
     *
     * @return A new empty DAMLList.
     */
    public DAMLList createDAMLList() {
        return (DAMLList) getResource( DAML_OIL.nil.getURI() ).as( DAMLList.class );
    }


    /**
     * <p>Create a new DAML list containing the given elements.</p>
     *
     * @param elements An iterator over the elements to be added to the list
     * @return A new empty DAMLList.
     */
    public DAMLList createDAMLList( Iterator elements ) {
        DAMLList l = createDAMLList();
        if (elements.hasNext()) {
            // put the first element on the list
            RDFNode n = (RDFNode) elements.next();
            l = (DAMLList) l.cons( n );

            // now add the remaining elements to the end of the list
            while (elements.hasNext()) {
                l.add( (RDFNode) elements.next() );
            }
        }

        return l;
    }


    /**
     * <p>Create a new DAML list containing the given elements.</p>
     *
     * @param elements An array of RDFNodes that will be the elements of the list
     * @return A new empty DAMLList.
     */
    public DAMLList createDAMLList( RDFNode[] elements ) {
        return createDAMLList( Arrays.asList( elements ).iterator() );
    }


    /**
     * <p>Create an (optionally anonymous) DAML Restriction.</p>
     *
     * @param uri The URI for the new restriction, or null to create
     *            an anonymous restriction.
     * @return A new DAMLRestriction object.
     */
    public DAMLRestriction createDAMLRestriction( String uri ) {
        return (DAMLRestriction) createOntResource( DAMLRestriction.class, getProfile().RESTRICTION(), uri );
    }


    /**
     * <p>Create a DAML Datatype representing values from some concrete domain.</p>
     *
     * @param uri The URI that is both the URI of this datatype value, and the identifier

⌨️ 快捷键说明

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