📄 ontmodelimpl.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 22 Feb 2003
* Filename $RCSfile: OntModelImpl.java,v $
* Revision $Revision: 1.99 $
* Release status $State: Exp $
*
* Last modified on $Date: 2007/01/26 12:11:40 $
* 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.rdf.listeners.StatementListener;
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.iterator.*;
import com.hp.hpl.jena.vocabulary.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.ontology.event.*;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.graph.compose.MultiUnion;
import com.hp.hpl.jena.graph.query.*;
import com.hp.hpl.jena.enhanced.*;
import com.hp.hpl.jena.shared.*;
import java.io.*;
import java.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* <p>
* Implementation of a model that can process general ontologies in OWL,
* DAML and similar languages.
* </p>
*
* @author Ian Dickinson, HP Labs
* (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
* @version CVS $Id: OntModelImpl.java,v 1.99 2007/01/26 12:11:40 ian_dickinson Exp $
*/
public class OntModelImpl
extends ModelCom
implements OntModel
{
// Constants
//////////////////////////////////
/**
* This variable is how the OntModel knows how to construct
* a syntax checker. This part of the design may change.
*/
static public String owlSyntaxCheckerClassName = "com.hp.hpl.jena.ontology.tidy.JenaChecker";
// Static variables
//////////////////////////////////
static private Log s_log = LogFactory.getLog( OntModelImpl.class );
/** Found from {@link owlSyntaxCheckerClassName}, must implement
* {@link OWLSyntaxChecker}. */
static private Class owlSyntaxCheckerClass;
// Instance variables
//////////////////////////////////
/** The model specification this model is using to define its structure */
protected OntModelSpec m_spec;
/** List of URI strings of documents that have been imported into this one */
protected Set m_imported = new HashSet();
/** Mode switch for strict checking mode */
protected boolean m_strictMode = true;
/** The union graph that contains the imports closure - there is always one of these, which may also be _the_ graph for the model */
protected MultiUnion m_union = new MultiUnion();
/** The listener that detects dynamically added or removed imports statments */
protected ImportsListener m_importsListener = null;
/** The event manager for ontology events on this model */
protected OntEventManager m_ontEventMgr = null;
/** Cached deductions model */
private Model m_deductionsModel = null;
// Constructors
//////////////////////////////////
/**
* <p>
* Construct a new ontology model, using the given model as a base. The document manager
* given in the specification object
* will be used to build the imports closure of the model if its policy permits.
* </p>
*
* @param model The base model that may contain existing statements for the ontology.
* if it is null, a fresh model is created as the base.
* @param spec A specification object that allows us to specify parameters and structure for the
* ontology model to be constructed.
*/
public OntModelImpl( OntModelSpec spec, Model model ) {
this( spec, makeBaseModel( spec, model ), true );
}
/**
* Construct a new ontology model from the given specification. The base model is
* produced using the baseModelMaker.
*/
public OntModelImpl( OntModelSpec spec ) {
this( spec, spec.createBaseModel(), true );
}
/**
*
* @param spec the specification for the OntModel
* @param model the base model [must be non-null]
* @param withImports If true, we load the imports as sub-models
*/
private OntModelImpl( OntModelSpec spec, Model model, boolean withImports ) {
// we haven't built the full graph yet, so we pass a vestigial form up to the super constructor
super( generateGraph( spec, model.getGraph() ), BuiltinPersonalities.model );
m_spec = spec;
// extract the union graph from whatever generateGraph() created
m_union = (getGraph() instanceof MultiUnion) ?
((MultiUnion) getGraph()) :
(MultiUnion) ((InfGraph) getGraph()).getRawGraph();
// add the global prefixes, if required
if (getDocumentManager().useDeclaredPrefixes()) {
withDefaultMappings( getDocumentManager().getDeclaredPrefixMapping() );
}
if (withImports) {
loadImports();
}
// force the inference engine, if we have one, to see the new graph data
rebind();
}
// External signature methods
//////////////////////////////////
/**
* <p>
* Answer a reference to the document manager that this model is using to manage
* ontology <-> mappings, and to load the imports closure. <strong>Note</strong>
* the default ontology model {@linkplain OntModelSpec specifications} each have
* a contained default document manager. Changing the document managers specified by
* these default specification may (in fact, probably will)
* affect other models built with the same specification
* policy. This may or may not be as desired by the programmer!
* </p>
* @return A reference to this model's document manager, obtained from the specification object
*/
public OntDocumentManager getDocumentManager() {
return m_spec.getDocumentManager();
}
/**
* <p>
* Answer an iterator that ranges over the ontology resources in this model, i.e.
* the resources with <code>rdf:type Ontology</code> or equivalent. These resources
* typically contain metadata about the ontology document that contains them.
* </p>
* <p>
* Specifically, the resources in this iterator will those whose type corresponds
* to the value given in the ontology vocabulary associated with this model, see
* {@link Profile#ONTOLOGY}.
* </p>
* <p>
* <strong>Note:</strong> the number of nodes returned by this iterator will vary according to
* the completeness of the deductive extension of the underlying graph. See class
* overview for more details.
* </p>
*
* @return An iterator over ontology resources.
*/
public ExtendedIterator listOntologies() {
checkProfileEntry( getProfile().ONTOLOGY(), "ONTOLOGY" );
return UniqueExtendedIterator.create(
findByTypeAs( getProfile().ONTOLOGY(), Ontology.class ) );
}
/**
* <p>
* Answer an iterator that ranges over the property resources in this model, i.e.
* the resources with <code>rdf:type Property</code> or equivalent. An <code>OntProperty</code>
* is equivalent to an <code>rdfs:Property</code> in a normal RDF graph; this type is
* provided as a common super-type for the more specific {@link ObjectProperty} and
* {@link DatatypeProperty} property types.
* </p>
* <p>
* Specifically, the resources in this iterator will those whose type corresponds
* to the value given in the ontology vocabulary associated with this model.
* </p>
* <p>
* <strong>Note:</strong> the number of nodes returned by this iterator will vary according to
* the completeness of the deductive extension of the underlying graph. See class
* overview for more details.
* </p>
*
* @return An iterator over property resources.
*/
public ExtendedIterator listOntProperties() {
return UniqueExtendedIterator.create(
findByTypeAs( RDF.Property, OntProperty.class ) );
}
/**
* <p>
* Answer an iterator that ranges over the object property resources in this model, i.e.
* the resources with <code>rdf:type ObjectProperty</code> or equivalent. An object
* property is a property that is defined in the ontology language semantics as a
* one whose range comprises individuals (rather than datatyped literals).
* </p>
* <p>
* Specifically, the resources in this iterator will those whose type corresponds
* to the value given in the ontology vocabulary associated with this model: see
* {@link Profile#OBJECT_PROPERTY}.
* </p>
* <p>
* <strong>Note:</strong> the number of nodes returned by this iterator will vary according to
* the completeness of the deductive extension of the underlying graph. See class
* overview for more details.
* </p>
*
* @return An iterator over object property resources.
*/
public ExtendedIterator listObjectProperties() {
checkProfileEntry( getProfile().OBJECT_PROPERTY(), "OBJECT_PROPERTY" );
return UniqueExtendedIterator.create(
findByTypeAs( getProfile().OBJECT_PROPERTY(), ObjectProperty.class ) );
}
/**
* <p>
* Answer an iterator that ranges over the datatype property resources in this model, i.e.
* the resources with <code>rdf:type DatatypeProperty</code> or equivalent. An datatype
* property is a property that is defined in the ontology language semantics as a
* one whose range comprises datatyped literals (rather than individuals).
* </p>
* <p>
* Specifically, the resources in this iterator will those whose type corresponds
* to the value given in the ontology vocabulary associated with this model: see
* {@link Profile#DATATYPE_PROPERTY}.
* </p>
* <p>
* <strong>Note:</strong> the number of nodes returned by this iterator will vary according to
* the completeness of the deductive extension of the underlying graph. See class
* overview for more details.
* </p>
*
* @return An iterator over datatype property resources.
*/
public ExtendedIterator listDatatypeProperties() {
checkProfileEntry( getProfile().DATATYPE_PROPERTY(), "DATATYPE_PROPERTY" );
return UniqueExtendedIterator.create(
findByTypeAs( getProfile().DATATYPE_PROPERTY(), DatatypeProperty.class ) );
}
/**
* <p>
* Answer an iterator that ranges over the functional property resources in this model, i.e.
* the resources with <code>rdf:type FunctionalProperty</code> or equivalent. A functional
* property is a property that is defined in the ontology language semantics as having
* a unique domain element for each instance of the relationship.
* </p>
* <p>
* Specifically, the resources in this iterator will those whose type corresponds
* to the value given in the ontology vocabulary associated with this model: see
* {@link Profile#FUNCTIONAL_PROPERTY}.
* </p>
*
* @return An iterator over functional property resources.
*/
public ExtendedIterator listFunctionalProperties() {
checkProfileEntry( getProfile().FUNCTIONAL_PROPERTY(), "FUNCTIONAL_PROPERTY" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -