📄 debugowl.java
字号:
/******************************************************************
* File: DebugOWL.java
* Created by: Dave Reynolds
* Created on: 12-Jun-2003
*
* (c) Copyright 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
* [See end of file]
* $Id: DebugOWL.java,v 1.33 2007/01/02 11:50:30 andy_seaborne Exp $
*****************************************************************/
package com.hp.hpl.jena.reasoner.rulesys.test;
import java.util.Iterator;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.graph.compose.Union;
//import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.util.PrintUtil;
import com.hp.hpl.jena.vocabulary.*;
import com.hp.hpl.jena.reasoner.*;
import com.hp.hpl.jena.reasoner.rulesys.*;
import com.hp.hpl.jena.reasoner.rulesys.impl.oldCode.*;
import com.hp.hpl.jena.shared.WrappedIOException;
//import com.hp.hpl.jena.reasoner.transitiveReasoner.TransitiveReasonerFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.*;
/**
* Test harnness for investigating OWL reasoner correctness and performance
* on specific local test files. Unit testing is done using OWLWGTester or simplar,
* this code is a debugging tools rather than a tester.
*
* @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
* @version $Revision: 1.33 $ on $Date: 2007/01/02 11:50:30 $
*/
public class DebugOWL {
/** The base reasoner being tested */
Reasoner reasoner;
/** The raw tests data as a Graph */
Graph testdata;
/** The (optional) schema graph used in interpreting the test data */
Graph schema;
/** The inference graph under test */
InfGraph infgraph;
/** Concepts created by testGenerator, [layer, index] */
Node[] concepts;
/** Instances of each concept */
Node[] instances;
/** Instance properties */
Node[] properties;
static Log logger = LogFactory.getLog(DebugOWL.class);
/** reasoner config: experimental ruleset and config */
public static final int EXPT = 1;
/** reasoner config: normal OWL-FB */
public static final int OWLFB = 2;
/** reasoner config: normal OWL forward */
public static final int OWL = 3;
/** reasoner config: normal RDFS */
public static final int RDFSFB = 4;
/** reasoner config: final RDFS - hybrid + TGC */
public static final int RDFSFinal = 5;
/** reasoner config: experimental OWL */
public static final int OWLExpt = 6;
/** reasoner config: LP RDFS exp */
public static final int RDFSLPExpt = 7;
/**
* Construct an empty test harness.
*/
public DebugOWL(int config) {
testdata = Factory.createGraphMem();
schema = null;
switch(config) {
case EXPT:
reasoner = GenericRuleReasonerFactory.theInstance().create(null);
GenericRuleReasoner grr = (GenericRuleReasoner)reasoner;
grr.setMode(GenericRuleReasoner.HYBRID);
try {
grr.setRules(Rule.parseRules(Util.loadRuleParserFromResourceFile("etc/expt.rules")));
} catch (WrappedIOException e) {
System.out.println("Failed to open rules file: " + e.getCause() );
System.exit(1);
}
// grr.setTransitiveClosureCaching(true);
// grr.setOWLTranslation(true);
// grr.setTraceOn(true);
break;
case OWLFB:
reasoner = OWLFBRuleReasonerFactory.theInstance().create(null);
// ((OWLFBRuleReasoner)reasoner).setTraceOn(true);
break;
case OWL:
reasoner = OWLRuleReasonerFactory.theInstance().create(null);
// ((OWLRuleReasoner)reasoner).setTraceOn(true);
break;
case RDFSFB:
reasoner = RDFSFBRuleReasonerFactory.theInstance().create(null);
break;
case RDFSFinal:
reasoner = RDFSRuleReasonerFactory.theInstance().create(null);
break;
case OWLExpt:
reasoner = OWLExptRuleReasonerFactory.theInstance().create(null);
// ((OWLExptRuleReasoner)reasoner).setTraceOn(true);
break;
case RDFSLPExpt:
try {
List rules = Rule.parseRules(Util.loadRuleParserFromResourceFile("etc/expt.rules"));
reasoner = new FBRuleReasoner(rules);
} catch (WrappedIOException e) {
System.out.println("Failed to open rules file: " + e.getCause());
System.exit(1);
}
break;
}
}
/**
* Load a test data set from file.
*/
public void load(String testFile) {
testdata = FileManager.get().loadModel(testFile).getGraph();
schema = null;
}
/**
* Load both a schema and an instance data file.
*/
public void load(String schemaFile, String testFile) {
testdata = FileManager.get().loadModel(testFile).getGraph();
schema = FileManager.get().loadModel(schemaFile).getGraph();
}
/**
* Create an artificial data set. This variant puts schema and
* instance data into the same testdata graph.
* @param depth the depth of the concept tree
* @param NS the number of subclasses at each tree level
* @param NI the number of instances of each concept
* @param withProps if true then properties are created for each concept and instiated for every third instance
*/
public void createTest(int depth, int NS, int NI, boolean withProps) {
// Calculate total store sizes and allocate
int numClasses = 0;
int levelSize = 1;
for (int i = 0; i < depth; i++) {
levelSize *= NS;
numClasses += levelSize;
}
concepts = new Node[numClasses];
properties = new Node[numClasses];
instances = new Node[numClasses * NI];
logger.info("Classes: " + numClasses +" Instances: " + (numClasses * NI)
+ (withProps ? " with properties" : ""));
// Create the tree
testdata = Factory.createGraphMem();
// First level
int conceptPtr = 0;
int levelStart = 0;
int levelEnd = 0;
int instancePtr = 0;
for (int i = 0; i < depth; i++) {
// Class tree
Node property = null;
if (i == 0) {
for (int j = 0; j < NS; j++) {
Node concept = Node.createURI("concept" + conceptPtr);
if (withProps) {
property = Node.createURI("prop" + conceptPtr);
properties[conceptPtr] = property;
}
concepts[conceptPtr++] = concept;
}
} else {
for (int j = levelStart; j < levelEnd; j++) {
Node superConcept = concepts[j];
for (int k = 0; k < NS; k++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -