1

我正在使用 OWL 和 SWRL API 构建一个 Maven 项目。我想使用以下代码检索存储在 .owl 文件中的所有规则:

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.swrlapi.core.SWRLAPIRule;
import org.swrlapi.core.SWRLRuleEngine;
import org.swrlapi.factory.SWRLAPIFactory;

import java.io.*;
import java.util.Set;

public class ManagingRules {

    public static void main(String[] args) throws OWLOntologyCreationException {

        OWLOntologyManager m = OWLManager.createOWLOntologyManager();
        OWLOntology ontology = m.loadOntologyFromOntologyDocument(new File("pwidasFinale.owl"));

        //taking SWRLs list
        SWRLRuleEngine ruleEngine = SWRLAPIFactory.createSWRLRuleEngine(ontology);

        // Get SWRL rules  
        Set<SWRLAPIRule> sets = ruleEngine.getSWRLRules();

        for(SWRLAPIRule item : sets){
            System.out.println(item.toString());
        }   
    }
}

没有编译错误。但是当我运行这个课程时,我收到了这个通知

Exception in thread "main" org.swrlapi.exceptions.NoRegisteredSWRLRuleEnginesException: no registered SWRL rule engines
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:47)
    at org.swrlapi.factory.SWRLAPIFactory.createSWRLRuleEngine(SWRLAPIFactory.java:39)
    at ManagingRules.main(ManagingRules.java:20)

实际上,.owl 文件中存储了 15 条规则。

请告诉我在哪里修复它。

我一直在寻找一个方便的教程或 SWRL API 的常见问题解答,包括这个. 但是,它似乎并没有太大帮助。

PS我的编码技术很差

4

1 回答 1

1

问题不在于输入文件,而在于没有可用的注册 SWRL 规则引擎。此设置很可能在使用 SWRLAPIFactory 之前在 Protege 中执行。

此处描述了此要求: https ://github.com/protegeproject/swrlapi/

If you'd like to be able to execute SWRL rules or SQWRL queries you will need a SWRLAPI-based rule engine implementation. Currently, a Drools-based SWRL rule engine implementation is provided. This implementation is also hosted on Maven Central.

我相信您需要将该页面中描述的依赖项添加到您的项目中。

于 2017-04-23T09:41:26.320 回答