我认为扣除模型是按需填充的,它取决于特定的推理者如何使用扣除模型。很可能只在请求时生成一些推导的三元组,而不是将它们存储在推导模型中。例如,在下面的示例中,我们先打印 deductions 模型,然后打印整个模型,然后再打印 deductions 模型,我们可以看到所需的子类三元组只有在我们打印整个模型时才会出现。通常,您应该使用顶级模型,而不是演绎模型,除非您对推理器的实现以及它将使用演绎模型的目的有所了解。
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.RDFLanguages;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;
public class RDFSReasoningExample {
public static void main(String[] args) throws IOException {
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_RDFS_INF);
String content = (""
+ "@prefix : <urn:ex:>.\n"
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.\n"
+ "\n"
+ ":a rdfs:subClassOf :b .\n"
+ ":b rdfs:subClassOf :c .\n");
try ( InputStream in = new ByteArrayInputStream(content.getBytes()) ) {
RDFDataMgr.read(model, in, RDFLanguages.TTL);
}
System.out.println("* Write the deductions model");
RDFDataMgr.write(System.out, model.getDeductionsModel(), RDFLanguages.NT);
System.out.println("* Write the model");
RDFDataMgr.write(System.out, model, RDFLanguages.NT);
System.out.println("* Write the deductions model again");
RDFDataMgr.write(System.out, model.getDeductionsModel(), RDFLanguages.NT);
}
}
* Write the deductions model
…nothing about :a, :b, or :c…
* Write the model
…
<urn:ex:a> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <urn:ex:b> .
<urn:ex:b> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <urn:ex:c> .
<urn:ex:c> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <urn:ex:c> .
<urn:ex:a> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <urn:ex:a> .
<urn:ex:a> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <urn:ex:c> .
<urn:ex:b> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <urn:ex:b> .
…
* Write the deductions model again
…nothing about :a, :b, or :c…