📄 digreasoner.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 July 19th 2003
* Filename $RCSfile: DIGReasoner.java,v $
* Revision $Revision: 1.11 $
* Release status $State: Exp $
*
* Last modified on $Date: 2007/01/02 11:49:27 $
* by $Author: andy_seaborne $
*
* (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
* [See end of file]
* ****************************************************************************/
// Package
///////////////
package com.hp.hpl.jena.reasoner.dig;
// Imports
///////////////
import java.io.*;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.reasoner.rulesys.Util;
import com.hp.hpl.jena.util.FileUtils;
import com.hp.hpl.jena.vocabulary.ReasonerVocabulary;
/**
* <p>
* This reasoner is the generator of inf-graphs that can use an external DIG inference engine
* to perform DL reasoning tasks.
* </p>
*
* @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
* @version Release @release@ ($Id: DIGReasoner.java,v 1.11 2007/01/02 11:49:27 andy_seaborne Exp $)
*/
public class DIGReasoner
implements Reasoner
{
// Constants
//////////////////////////////////
// Static variables
//////////////////////////////////
/** The graph capabilities of the infgraphs generated by this reasoner */
protected Capabilities capabilities;
// Instance variables
//////////////////////////////////
/** A graph that contains ontology definition data (tbox) */
protected Graph m_tbox;
/** Reference to the factory that created this reasoner */
protected ReasonerFactory m_factory;
/** The original configuration properties, if any */
protected Resource m_configuration;
/** The URL to use to connect to the external reasoner */
protected String m_extReasonerURL = DIGConnection.DEFAULT_REASONER_URL;
/** The profile of the ontology language we're expecting */
protected OntModelSpec m_ontLang = getModelSpec( ProfileRegistry.OWL_LANG );
/** The axioms that provide additional triples based on the language we're processing */
protected Model m_axioms = null;
// Constructors
//////////////////////////////////
/**
* <p>Construct a DIG reasoner, that can generate inference graphs binding
* an external DIG inference engine (e.g. Racer) to a given source graph.<p>
* @param tbox Optional schema to bind to this reasoner instance. Unlike other Jena
* reasoners, pre-binding a tbox to a DIG reasoner does not allow any
* efficiencies to be exploited.
* @param factory The reasoner factory that created this reasoner
* @param configuration Optional resource to which is attached configuration
* parameters for this reasoner
*/
public DIGReasoner( Graph tbox, ReasonerFactory factory, Resource configuration ) {
m_tbox = tbox;
m_factory = factory;
m_configuration = configuration;
configure( configuration );
}
// External signature methods
//////////////////////////////////
/**
* <p>Bind a schema, or tbox, to this DIG reasoner. This does not have any efficiency
* value in DIG reasoners, since we must re-load the entire tbox into each new instance
* of a DIG inference graph.<p>
* @param tbox The graph containing the ontology (tbox) data
* @return A new DIG reasoner containing the tbox data
* @see com.hp.hpl.jena.reasoner.Reasoner#bindSchema(com.hp.hpl.jena.graph.Graph)
*/
public Reasoner bindSchema( Graph tbox ) {
return new DIGReasoner( tbox, m_factory, m_configuration );
}
/**
* <p>Bind a schema, or tbox, to this DIG reasoner. This does not have any efficiency
* value in DIG reasoners, since we must re-load the entire tbox into each new instance
* of a DIG inference graph.<p>
* @param tbox A model wrapping the graph containing the ontology (tbox) data
* @return A new DIG reasoner containing the tbox data
* @see com.hp.hpl.jena.reasoner.Reasoner#bindSchema(com.hp.hpl.jena.graph.Graph)
*/
public Reasoner bindSchema(Model tbox) {
return bindSchema( tbox.getGraph() );
}
/**
* <p>Bind the given data graph to any existing t-box schema that we have, and answer
* the resulting inference graph.</p>
* @param data A graph containing the source data
* @return A new inference graph that will apply the DIG reasoner to the combination
* of the tbox and data graphs.
*/
public InfGraph bind( Graph data ) {
return new DIGInfGraph( data, this );
}
/**
* Not available.
* @exception UnsupportedOperationException
*/
public void setDerivationLogging( boolean logOn ) {
throw new UnsupportedOperationException( "DIG reasoner does not support derivation logging" );
}
/**
* <p>Answer the capabilities of this reasoner.</p>
* @return An RDF model denoting the capabilties of the reasoner
*/
public Model getReasonerCapabilities() {
return (m_factory == null) ? null : m_factory.getCapabilities();
}
/**
* <p>Add this reasoner's description to the given configuration model.</p>
* @param configSpec A configuration model to add this reasoner's configuration to
* @param base The base URI in the given model to which we will attach the configuration
* of this reasoner.
*/
public void addDescription( Model configSpec, Resource base ) {
if (m_configuration != null) {
StmtIterator i = m_configuration.listProperties();
while (i.hasNext()) {
Statement st = i.nextStatement();
configSpec.add(base, st.getPredicate(), st.getObject());
}
}
}
/**
* Determine whether the given property is recognized and treated specially
* by this reasoner. This is a convenience packaging of a special case of getCapabilities.
* @param property the property which we want to ask the reasoner about, given as a Node since
* this is part of the SPI rather than API
* @return true if the given property is handled specially by the reasoner.
*/
public boolean supportsProperty(Property property) {
if (m_factory == null) return false;
Model caps = m_factory.getCapabilities();
Resource root = caps.getResource(m_factory.getURI());
return caps.contains(root, ReasonerVocabulary.supportsP, property);
}
/**
* Set a configuration parameter for the reasoner. The supported parameters
* are:
* <ul>
* <li>PROPderivationLogging - set to true to enable recording all rule derivations</li>
* <li>PROPtraceOn - set to true to enable verbose trace information to be sent to the logger INFO channel</li>
* </ul>
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -