SWRLRuleEngineAPI:错误的 class 格式出现在 Eclipse 和 NetBeans IDE 中,同时进行 SWRL 推理
SWRLRuleEngineAPI: wrong class format appears in both Eclipse and NetBeans IDEs while doing SWRL inference
我有一个简单的 ontology 并尝试进行 SWRL 推理。在 Protege 3.5(内部版本 663)上,Jess 和 Drools 引擎按预期工作,同时使用 SWRL API 发生错误。如 SWRLRuleEngineAPI 中所述,我正在使用以下代码:
SWRLRuleEngine ruleEngine = P3SWRLRuleEngineFactory.create(owlModel);
SWRLFactory factory = new SWRLFactory(owlModel);
SWRLImp imp = factory.createImp("Person(?x) ∧ hasGender(?x, male) → Male(?x)");
ruleEngine.infer();
classes = owlModel.getUserDefinedOWLNamedClasses();
for (Iterator it = classes.iterator(); it.hasNext();) {
OWLNamedClass cls = (OWLNamedClass) it.next();
Collection instances = cls.getInstances(false);
System.out.println("Class " + cls.getBrowserText() + " (" + instances.size() + ")");
for (Iterator jt = instances.iterator(); jt.hasNext();) {
OWLIndividual individual = (OWLIndividual) jt.next();
System.out.println(" - " + individual.getBrowserText());
}
}
所有 Protege API jar 都被正确引用,代码编译良好并且模型被正确读取。但是在激活规则引擎时Eclipse和NetBeans都出现如下错误(SWRLRuleEngine ruleEngine = P3SWRLRuleEngineFactory.create(owlModel))
:
INFO: Updating underlying frames model in 1 ms
Rule engine 'Jess' registered with the SWRLTab rule engine manager.
Oct 14, 2015 8:00:10 AM org.protege.swrltab.p3.P3SWRLRuleEngineFactory registerRuleEngine
INFO: Rule engine 'Jess' registered with the SWRLTab rule engine manager.
Plugin 'SWRLJessTab' registered with the SWRLTab plugin manager.
Oct 14, 2015 8:00:10 AM edu.stanford.smi.protegex.owl.swrl.P3SWRLTabPluginManager registerPlugin
INFO: Plugin 'SWRLJessTab' registered with the SWRLTab plugin manager.
Rule engine 'Drools' registered with the SWRLTab rule engine manager.
Oct 14, 2015 8:00:10 AM org.protege.swrltab.p3.P3SWRLRuleEngineFactory registerRuleEngine
INFO: Rule engine 'Drools' registered with the SWRLTab rule engine manager.
Plugin 'SWRLDroolsTab' registered with the SWRLTab plugin manager.
Oct 14, 2015 8:00:10 AM edu.stanford.smi.protegex.owl.swrl.P3SWRLTabPluginManager registerPlugin
INFO: Plugin 'SWRLDroolsTab' registered with the SWRLTab plugin manager.
Plugin 'SQWRLQueryTab' registered with the SWRLTab plugin manager.
Oct 14, 2015 8:00:10 AM edu.stanford.smi.protegex.owl.swrl.P3SWRLTabPluginManager registerPlugin
INFO: Plugin 'SQWRLQueryTab' registered with the SWRLTab plugin manager.
java.lang.RuntimeException: wrong class format
at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:251)
at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:202)
at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:109)
at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49)
at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:122)
at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.superInterfaces(BinaryTypeBinding.java:1152)
at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.implementsInterface(ReferenceBinding.java:888)
at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isCompatibleWith0(ReferenceBinding.java:1036)
at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isCompatibleWith(ReferenceBinding.java:987)
at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:3963)
at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:3951)
at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:555)
at org.eclipse.jdt.internal.compiler.lookup.Scope.getConstructor(Scope.java:1882)
at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.resolveType(AllocationExpression.java:359)
at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:210)
at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:463)
at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:252)
at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:422)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1148)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1258)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:538)
at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:763)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:468)
at org.drools.commons.jci.compilers.EclipseJavaCompiler.compile(EclipseJavaCompiler.java:358)
at org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJavaCompiler.java:49)
at org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.java:370)
at org.drools.compiler.DialectCompiletimeRegistry.compileAll(DialectCompiletimeRegistry.java:47)
at org.drools.compiler.PackageRegistry.compileAll(PackageRegistry.java:101)
at org.drools.compiler.PackageBuilder.compileAll(PackageBuilder.java:966)
at org.drools.compiler.PackageBuilder.compileAllRules(PackageBuilder.java:802)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:791)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:462)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:664)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:48)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:35)
at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.defineDRLResource(Unknown Source)
at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.defineDRLRule(Unknown Source)
at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.resetRuleEngine(Unknown Source)
at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.(Unknown Source)
at org.protege.swrlapi.drools.DroolsSWRLRuleEngineCreator.create(Unknown Source)
at org.protege.swrltab.p3.P3SWRLRuleEngineFactory.create(Unknown Source)
at org.protege.swrltab.p3.P3SWRLRuleEngineFactory.create(Unknown Source)
at com.demo.application.OWLAPIDemoApplication.main(OWLAPIDemoApplication.java:107)
Caused by: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.(ClassFileReader.java:372)
at org.drools.commons.jci.compilers.EclipseJavaCompiler.createNameEnvironmentAnswer(EclipseJavaCompiler.java:275)
at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:246)
... 42 more
Exception in thread "main" org.protege.swrlapi.exceptions.SWRLRuleEngineException: Error creating rule engine Drools. Exception: org.protege.owl.portability.exceptions.TargetRuleEngineException. Message: internal error generating Drools rule
rule scm_cls when CDA($c:c) then SCA sca1=new SCA($c, $c); ECA eca=new ECA($c, $c); SCA sca2=new SCA($c, "owl:Thing"); SCA sca3=new SCA("owl:Nothing", $c); inferrer.infer(sca1, eca, sca2, sca3); end
wrong class format
at org.protege.swrltab.p3.P3SWRLRuleEngineFactory.create(Unknown Source)
at org.protege.swrltab.p3.P3SWRLRuleEngineFactory.create(Unknown Source)
at com.demo.application.OWLAPIDemoApplication.main(OWLAPIDemoApplication.java:107)
Caused by: org.protege.owl.portability.exceptions.TargetRuleEngineException: internal error generating Drools rule
rule scm_cls when CDA($c:c) then SCA sca1=new SCA($c, $c); ECA eca=new ECA($c, $c); SCA sca2=new SCA($c, "owl:Thing"); SCA sca3=new SCA("owl:Nothing", $c); inferrer.infer(sca1, eca, sca2, sca3); end
wrong class format
at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.defineDRLRule(Unknown Source)
at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.resetRuleEngine(Unknown Source)
at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.(Unknown Source)
at org.protege.swrlapi.drools.DroolsSWRLRuleEngineCreator.create(Unknown Source)
... 3 more
Caused by: java.lang.RuntimeException: wrong class format
at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:251)
at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:202)
at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:109)
at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49)
at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:122)
at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.superInterfaces(BinaryTypeBinding.java:1152)
at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.implementsInterface(ReferenceBinding.java:888)
at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isCompatibleWith0(ReferenceBinding.java:1036)
at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isCompatibleWith(ReferenceBinding.java:987)
at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:3963)
at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:3951)
at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:555)
at org.eclipse.jdt.internal.compiler.lookup.Scope.getConstructor(Scope.java:1882)
at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.resolveType(AllocationExpression.java:359)
at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:210)
at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:463)
at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:252)
at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:422)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1148)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1258)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:538)
at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:763)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:468)
at org.drools.commons.jci.compilers.EclipseJavaCompiler.compile(EclipseJavaCompiler.java:358)
at org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJavaCompiler.java:49)
at org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.java:370)
at org.drools.compiler.DialectCompiletimeRegistry.compileAll(DialectCompiletimeRegistry.java:47)
at org.drools.compiler.PackageRegistry.compileAll(PackageRegistry.java:101)
at org.drools.compiler.PackageBuilder.compileAll(PackageBuilder.java:966)
at org.drools.compiler.PackageBuilder.compileAllRules(PackageBuilder.java:802)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:791)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:462)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:664)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:48)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:35)
at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.defineDRLResource(Unknown Source)
... 7 more
Caused by: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.(ClassFileReader.java:372)
at org.drools.commons.jci.compilers.EclipseJavaCompiler.createNameEnvironmentAnswer(EclipseJavaCompiler.java:275)
at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:246)
... 42 more
Java Result: 1
更新:降级到 Java 7 后出现以下问题:
Exception in thread "main" java.lang.NullPointerException at
org.protege.owl.portability.p3.converters.P3OWLAxiomConverter.completeBulkConversion(Unknown
Source) at
org.protege.swrlapi.core.impl.AbstractSWRLRuleEngine.writeInferredKnowledge2OWL(Unknown
Source) at
org.protege.swrlapi.core.impl.AbstractSWRLRuleEngine.infer(Unknown
Source) at
com.demo.application.OWLAPIDemoApplication.main(OWLAPIDemoApplication.java:125)
Java Result: 1
Protege版本问题。我通过降级到 Martin O'Connor Answer 建议的 3.4.8 版本解决了这个问题,该版本已经过广泛审查。
谢谢大家的努力。
我有一个简单的 ontology 并尝试进行 SWRL 推理。在 Protege 3.5(内部版本 663)上,Jess 和 Drools 引擎按预期工作,同时使用 SWRL API 发生错误。如 SWRLRuleEngineAPI 中所述,我正在使用以下代码:
SWRLRuleEngine ruleEngine = P3SWRLRuleEngineFactory.create(owlModel);
SWRLFactory factory = new SWRLFactory(owlModel);
SWRLImp imp = factory.createImp("Person(?x) ∧ hasGender(?x, male) → Male(?x)");
ruleEngine.infer();
classes = owlModel.getUserDefinedOWLNamedClasses();
for (Iterator it = classes.iterator(); it.hasNext();) {
OWLNamedClass cls = (OWLNamedClass) it.next();
Collection instances = cls.getInstances(false);
System.out.println("Class " + cls.getBrowserText() + " (" + instances.size() + ")");
for (Iterator jt = instances.iterator(); jt.hasNext();) {
OWLIndividual individual = (OWLIndividual) jt.next();
System.out.println(" - " + individual.getBrowserText());
}
}
所有 Protege API jar 都被正确引用,代码编译良好并且模型被正确读取。但是在激活规则引擎时Eclipse和NetBeans都出现如下错误(SWRLRuleEngine ruleEngine = P3SWRLRuleEngineFactory.create(owlModel))
:
INFO: Updating underlying frames model in 1 ms Rule engine 'Jess' registered with the SWRLTab rule engine manager. Oct 14, 2015 8:00:10 AM org.protege.swrltab.p3.P3SWRLRuleEngineFactory registerRuleEngine INFO: Rule engine 'Jess' registered with the SWRLTab rule engine manager. Plugin 'SWRLJessTab' registered with the SWRLTab plugin manager. Oct 14, 2015 8:00:10 AM edu.stanford.smi.protegex.owl.swrl.P3SWRLTabPluginManager registerPlugin INFO: Plugin 'SWRLJessTab' registered with the SWRLTab plugin manager. Rule engine 'Drools' registered with the SWRLTab rule engine manager. Oct 14, 2015 8:00:10 AM org.protege.swrltab.p3.P3SWRLRuleEngineFactory registerRuleEngine INFO: Rule engine 'Drools' registered with the SWRLTab rule engine manager. Plugin 'SWRLDroolsTab' registered with the SWRLTab plugin manager. Oct 14, 2015 8:00:10 AM edu.stanford.smi.protegex.owl.swrl.P3SWRLTabPluginManager registerPlugin INFO: Plugin 'SWRLDroolsTab' registered with the SWRLTab plugin manager. Plugin 'SQWRLQueryTab' registered with the SWRLTab plugin manager. Oct 14, 2015 8:00:10 AM edu.stanford.smi.protegex.owl.swrl.P3SWRLTabPluginManager registerPlugin INFO: Plugin 'SQWRLQueryTab' registered with the SWRLTab plugin manager. java.lang.RuntimeException: wrong class format at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:251) at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:202) at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:109) at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49) at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:122) at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.superInterfaces(BinaryTypeBinding.java:1152) at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.implementsInterface(ReferenceBinding.java:888) at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isCompatibleWith0(ReferenceBinding.java:1036) at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isCompatibleWith(ReferenceBinding.java:987) at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:3963) at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:3951) at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:555) at org.eclipse.jdt.internal.compiler.lookup.Scope.getConstructor(Scope.java:1882) at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.resolveType(AllocationExpression.java:359) at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:210) at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:463) at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:252) at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:422) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1148) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1258) at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:538) at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:763) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:468) at org.drools.commons.jci.compilers.EclipseJavaCompiler.compile(EclipseJavaCompiler.java:358) at org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJavaCompiler.java:49) at org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.java:370) at org.drools.compiler.DialectCompiletimeRegistry.compileAll(DialectCompiletimeRegistry.java:47) at org.drools.compiler.PackageRegistry.compileAll(PackageRegistry.java:101) at org.drools.compiler.PackageBuilder.compileAll(PackageBuilder.java:966) at org.drools.compiler.PackageBuilder.compileAllRules(PackageBuilder.java:802) at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:791) at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:462) at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:664) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:48) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:35) at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.defineDRLResource(Unknown Source) at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.defineDRLRule(Unknown Source) at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.resetRuleEngine(Unknown Source) at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.(Unknown Source) at org.protege.swrlapi.drools.DroolsSWRLRuleEngineCreator.create(Unknown Source) at org.protege.swrltab.p3.P3SWRLRuleEngineFactory.create(Unknown Source) at org.protege.swrltab.p3.P3SWRLRuleEngineFactory.create(Unknown Source) at com.demo.application.OWLAPIDemoApplication.main(OWLAPIDemoApplication.java:107) Caused by: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.(ClassFileReader.java:372) at org.drools.commons.jci.compilers.EclipseJavaCompiler.createNameEnvironmentAnswer(EclipseJavaCompiler.java:275) at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:246) ... 42 more Exception in thread "main" org.protege.swrlapi.exceptions.SWRLRuleEngineException: Error creating rule engine Drools. Exception: org.protege.owl.portability.exceptions.TargetRuleEngineException. Message: internal error generating Drools rule rule scm_cls when CDA($c:c) then SCA sca1=new SCA($c, $c); ECA eca=new ECA($c, $c); SCA sca2=new SCA($c, "owl:Thing"); SCA sca3=new SCA("owl:Nothing", $c); inferrer.infer(sca1, eca, sca2, sca3); end wrong class format at org.protege.swrltab.p3.P3SWRLRuleEngineFactory.create(Unknown Source) at org.protege.swrltab.p3.P3SWRLRuleEngineFactory.create(Unknown Source) at com.demo.application.OWLAPIDemoApplication.main(OWLAPIDemoApplication.java:107) Caused by: org.protege.owl.portability.exceptions.TargetRuleEngineException: internal error generating Drools rule rule scm_cls when CDA($c:c) then SCA sca1=new SCA($c, $c); ECA eca=new ECA($c, $c); SCA sca2=new SCA($c, "owl:Thing"); SCA sca3=new SCA("owl:Nothing", $c); inferrer.infer(sca1, eca, sca2, sca3); end wrong class format at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.defineDRLRule(Unknown Source) at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.resetRuleEngine(Unknown Source) at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.(Unknown Source) at org.protege.swrlapi.drools.DroolsSWRLRuleEngineCreator.create(Unknown Source) ... 3 more Caused by: java.lang.RuntimeException: wrong class format at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:251) at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:202) at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:109) at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49) at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:122) at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.superInterfaces(BinaryTypeBinding.java:1152) at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.implementsInterface(ReferenceBinding.java:888) at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isCompatibleWith0(ReferenceBinding.java:1036) at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isCompatibleWith(ReferenceBinding.java:987) at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:3963) at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:3951) at org.eclipse.jdt.internal.compiler.lookup.Scope.computeCompatibleMethod(Scope.java:555) at org.eclipse.jdt.internal.compiler.lookup.Scope.getConstructor(Scope.java:1882) at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.resolveType(AllocationExpression.java:359) at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:210) at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:463) at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:252) at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:422) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1148) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1258) at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:538) at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:763) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:468) at org.drools.commons.jci.compilers.EclipseJavaCompiler.compile(EclipseJavaCompiler.java:358) at org.drools.commons.jci.compilers.AbstractJavaCompiler.compile(AbstractJavaCompiler.java:49) at org.drools.rule.builder.dialect.java.JavaDialect.compileAll(JavaDialect.java:370) at org.drools.compiler.DialectCompiletimeRegistry.compileAll(DialectCompiletimeRegistry.java:47) at org.drools.compiler.PackageRegistry.compileAll(PackageRegistry.java:101) at org.drools.compiler.PackageBuilder.compileAll(PackageBuilder.java:966) at org.drools.compiler.PackageBuilder.compileAllRules(PackageBuilder.java:802) at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:791) at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:462) at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:664) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:48) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:35) at org.protege.swrlapi.drools.DroolsSWRLRuleEngine.defineDRLResource(Unknown Source) ... 7 more Caused by: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.(ClassFileReader.java:372) at org.drools.commons.jci.compilers.EclipseJavaCompiler.createNameEnvironmentAnswer(EclipseJavaCompiler.java:275) at org.drools.commons.jci.compilers.EclipseJavaCompiler.findType(EclipseJavaCompiler.java:246) ... 42 more Java Result: 1
更新:降级到 Java 7 后出现以下问题:
Exception in thread "main" java.lang.NullPointerException at org.protege.owl.portability.p3.converters.P3OWLAxiomConverter.completeBulkConversion(Unknown Source) at org.protege.swrlapi.core.impl.AbstractSWRLRuleEngine.writeInferredKnowledge2OWL(Unknown Source) at org.protege.swrlapi.core.impl.AbstractSWRLRuleEngine.infer(Unknown Source) at com.demo.application.OWLAPIDemoApplication.main(OWLAPIDemoApplication.java:125) Java Result: 1
Protege版本问题。我通过降级到 Martin O'Connor Answer 建议的 3.4.8 版本解决了这个问题,该版本已经过广泛审查。 谢谢大家的努力。