我创建了一个基于本体的安全警报。在阅读了一些数据(个人)之后,它变得非常大,所以我决定使用 Jena Rule Reasoner 来确定一些事实。我主要给个人类型和属性并使用一些正则表达式。这是一个小的(构造的)示例,当其信息与正则表达式匹配时,它为个人提供“多重”类型:
[testRuleContent: (?X ns:hasClassification ?Y), (?Y ns:hasText ?Z), regex(?Z, '. Multiple. ') -> (?X rdf:type ns:Multiple)]
为了使用推理器,我根据之前加载的本体创建了一个 infModel:
RuleReasoner ruleReasoner = new RuleReasoner("GenaralRuleReasoner");
//read rules from file
List<Rule> ruleList = Rule.parseRules(Rule.parseRules(rd));
com.hp.hpl.jena.reasoner.Reasoner reasoner = new GenericRuleReasoner(ruleList);
//jenaOntology is the ontology with the data
InfModel inferredOntotlogy = ModelFactory.createInfModel(reasoner, jenaOntology);
inferredOntotlogy.prepare();
这没有问题,我可以将 infModel 写入具有添加类型的文件中。
查询某些个体的推断本体的最佳方法是什么(在本例中,类型为:“多个”)?
目前我在推断模型上使用“listStatements()”:
Resource multiple = inferredOntotlogy.getResource("file:/C:/ns#Multiple");
StmtIterator iter = inferredOntotlogy.listStatements(null, RDF.type, multiple);
while (iter.hasNext()) {
Resource subject = iter.next().getSubject();
//Individual ind = subject.as(Individual.class);
String indUri = iter.next().getSubject().getURI();
演员表抛出一个异常(它只有一个带有 Uri 的节点)。但是我得到了个人的有效 Uri,并且可以在没有新属性的情况下使用基本本体模型(我只需要它们来获取搜索到的个人,因此它是一个可能的解决方案)。
类似的尝试是在推断模型上使用 getDeductionsModel() 来获取 Model -> OntModel 并查询它(可能使用 SPARQL)。
但我更喜欢一种查询推断模型的简单方法。有这样的解决方案吗?或者你能给我一个提示如何以最好的方式处理这种情况吗?