我创建了一个基于本体的安全警报。在阅读了一些数据(个人)后,它变得相当大,所以我决定使用耶拿规则推理者来确定一些事实。我主要给出个人类型和属性,并使用一些正则表达式。下面是一个小的(构造的)示例,当它的信息与regex匹配时,它为个人提供了"multiple“类型:
testRuleContent:(?X ns:hasText ?Y),(?Y :hasText ?Z),regex(?Z,'.Multiple.') -> (?X rdf:类型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写入一个文件中,并添加类型。
有什么更好的方法来查询某些个人的推断本体(在本例中,那些类型为:"Multiple")?
目前,我在推断模型上使用了"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()获取模型-> OntModel并查询它(可能使用SPARQL)。
但是id提供了一种查询推断模型的简单方法。有这样的解决办法吗?或者你能告诉我如何最好地处理这种情况吗?
发布于 2014-02-19 13:34:54
我现在就使用fow的资源。它提供了我需要的所有功能。我应该仔细看看API。
我回答了我自己的问题,把它标记为明天解决了。
https://stackoverflow.com/questions/21860497
复制相似问题