0

I am working about inference in Jena. I have begin with the Jena official tutorial I am trying to display in console the InfModel result by using the following code:

infModel.write(System.out, "RDF/XML-ABBREV");

But the result is not clean, it shows many informations that are not necessary. It show this:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns="urn:x-hp:eg/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" > 
  <rdf:Description rdf:about="http://www.w3.org/2001/XMLSchema#double">
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Datatype"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.w3.org/2001/XMLSchema#float">
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Datatype"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#short"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#byte"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#decimal"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#date"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#duration"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#unsignedLong"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#unsignedShort"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#nonPositiveInteger"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#long"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#unsignedInt"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#time"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#dateTime"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#int"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#unsignedByte"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.w3.org/2001/XMLSchema#unsignedLong">
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Datatype"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#unsignedLong"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#long"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#float"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#time"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#dateTime"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#duration"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#date"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
    <owl:equivalentClass rdf:resource="http://www.w3.org/2001/XMLSchema#unsignedLong"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.w3.org/2002/07/owl#backwardCompatibleWith">
    <rdfs:domain rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
    <rdfs:range rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
    <rdfs:subPropertyOf rdf:resource="http://www.w3.org/2002/07/owl#backwardCompatibleWith"/>
    <rdfs:range rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
    <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
    <rdfs:domain rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.w3.org/2001/XMLSchema#unsignedByte">
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Datatype"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#unsignedLong"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#unsignedInt"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#int"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#long"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#byte"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#short"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#unsignedByte"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/XMLSchema#unsignedShort"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#dateTime"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#boolean"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#time"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#float"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#duration"/>
    <owl:disjointWith rdf:resource="http://www.w3.org/2001/XMLSchema#date"/>
    <owl:equivalentClass rdf:resource="http://www.w3.org/2001/XMLSchema#unsignedByte"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A0">
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdf:type rdf:resource="urn:x-hp:eg/Bundle"/>
    <rdf:type rdf:resource="urn:x-hp:eg/GameBundle"/>
    <owl:sameAs rdf:nodeID="A0"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.w3.org/2001/XMLSchema#hexBinary">
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Datatype"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.w3.org/2002/07/owl#Restriction">
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Restriction"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
    <owl:equivalentClass rdf:resource="http://www.w3.org/2002/07/owl#Restriction"/>
  </rdf:Description>
  <rdf:Description rdf:about="urn:x-hp:eg/Bundle">
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
    <rdfs:subClassOf rdf:resource="urn:x-hp:eg/Bundle"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
    <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
    <owl:equivalentClass rdf:resource="urn:x-hp:eg/Bundle"/>
  </rdf:Description>
</rdf:RDF>

Do you know how to display the InfModel most proprely? Thanks for you help.

Community
  • 1
  • 1

1 Answers1

1

But the result is not clean,

The result is perfectly clean; it's well formed data with logical inferences drawn from the data that you provided.

it shows many informations that are not necessary.

I'm not sure whether you mean that: (i) the data is incorrect (i.e., that it doesn't necessarily follow from the input) or that (ii) it's just data that you're not interested in (i.e., that it's data that's not necessary to you). (i) is not correct; the inferred statements do follow from the data. E.g., xsd:float is disjoint from xsd:date. (ii) may be correct; you haven't told use what data you need and what you don't, so we can't really say what data you want or don't want. You haven't shown your code, either, so it's hard to know where your inferences are coming from.

If you're using Pellet, then you might be interested in How can I extract all inferences? from the Pellet FAQ, which describes the use of the ModelExtractor:

   // Create an inference extractor
   ModelExtractor extractor = new ModelExtractor(model);

   // Extract default set of inferences
   Model inferences = extractor.extractModel();

If you're not using Pellet, then you can still use Jena's Model's listStatements to list some statements from a model. You can create a Selector that will pull just the statements that you consider "necessary." (Until you tell us what's "necessary," we can't really help you in implementing the Selector, though.)

listStatements

StmtIterator listStatements(Selector s)

List the statements matching a selector. A statment is considered to match if the test method of s returns true when called on s.

Model also has an add(StmtIterator) method, so you could listStatements from your InfModel, and add them to another model, and then print that second model.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353