You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by 锐光刘 <ti...@gmail.com> on 2012/01/07 15:38:27 UTC

Could I ignore the blank node ?Or what's the usage of them?

I am new in the field of JENA,so don't laugh at me about this
question,please.
My question is about the blank node,since I have no idea how to treat them.
When I list the root class of a OWL file,there are a lot of blank
nodes,even more than the class with URI.Such as

http://xmlns.com/wordnet/1.6/Agent-3
-51cb51a0:134b85abd5d:-7fd3
-51cb51a0:134b85abd5d:-7fc1
-51cb51a0:134b85abd5d:-7fc4
-51cb51a0:134b85abd5d:-7fc7
-51cb51a0:134b85abd5d:-7fca
-51cb51a0:134b85abd5d:-7fcc
-51cb51a0:134b85abd5d:-7fce
-51cb51a0:134b85abd5d:-7fd1

1.the first question is that why there are so many blank nodes created as
root class and what's the usage of them?

then,when I list the statements of the file,I found there are also many
statements with blank node ,for example:
class: -51cb51a0:134b85abd5d:-7fcc
 [-51cb51a0:134b85abd5d:-7fcc, http://www.w3.org/2002/07/owl#minCardinality,
"1"^^http://www.w3.org/2001/XMLSchema#nonNegativeInteger]
 [-51cb51a0:134b85abd5d:-7fcc, http://www.w3.org/2002/07/owl#onProperty,
http://www.mindswap.org/2004/owl/funding#source]
 [-51cb51a0:134b85abd5d:-7fcc,
http://www.w3.org/1999/02/22-rdf-syntax-ns#type,
http://www.w3.org/2002/07/owl#Restriction]
class:-51cb51a0:134b85abd5d:-7fce
 [-51cb51a0:134b85abd5d:-7fce, http://www.w3.org/2002/07/owl#someValuesFrom,
http://www.mindswap.org/2004/owl/funding#Funding]
 [-51cb51a0:134b85abd5d:-7fce, http://www.w3.org/2002/07/owl#onProperty,
http://www.mindswap.org/2004/owl/funding#fundedBy]
 [-51cb51a0:134b85abd5d:-7fce,
http://www.w3.org/1999/02/22-rdf-syntax-ns#type,
http://www.w3.org/2002/07/owl#Restriction]

2.the second question is that why do these blank nodes exist? I can't find
them in the Protégé gragh ,but only see them when I parse the file with
JENA.

Another situation is that when you list all the statements of a class which
have URI, some statements are very similar,since the subject and predicate
of the statement are same while one object is a resource with URI and
another is a blank node.for example
the statements for class  http://www.owl-ontologies.com/animal.owl#Giraffe is
three
 [http://www.owl-ontologies.com/animal.owl#Giraffe,
http://www.w3.org/2000/01/rdf-schema#subClassOf, 72947f0e:134b7e616e0:-7ff9]
 [http://www.owl-ontologies.com/animal.owl#Giraffe,
http://www.w3.org/2000/01/rdf-schema#subClassOf,
http://www.owl-ontologies.com/animal.owl#Herbivore]
 [http://www.owl-ontologies.com/animal.owl#Giraffe,
http://www.w3.org/1999/02/22-rdf-syntax-ns#type,
http://www.w3.org/2002/07/owl#Class]

3.the third question is that is the blank node( 72947f0e:134b7e616e0:-7ff9 )
here a  complement or equal class of
http://www.owl-ontologies.com/animal.owl#Herbivore.If it is ,why  to
created a blank node ?

Because I want to receate a model with part of the information from another
model,so I list all the statements and add them to the new CreatedModel.But
I don't know how to deal with the ones with blank node.If I ignore
them,that't OK.the new model have no problems.But I add the ones with blank
node,there are always display errors.such as

Exception in thread "main" com.hp.hpl.jena.ontology.ConversionException:
Cannot convert node 2761081c:134b875e25b:-7ffb to OntClass: it does not
have rdf:type owl:Class or equivalent
 at com.hp.hpl.jena.ontology.impl.OntClassImpl$1.wrap(OntClassImpl.java:82)
 at com.hp.hpl.jena.enhanced.EnhNode.convertTo(EnhNode.java:142)
at com.hp.hpl.jena.enhanced.EnhNode.convertTo(EnhNode.java:22)
 at com.hp.hpl.jena.enhanced.Polymorphic.asInternal(Polymorphic.java:54)
at com.hp.hpl.jena.enhanced.EnhNode.as(EnhNode.java:97)
 at
com.hp.hpl.jena.ontology.impl.OntResourceImpl$ObjectAsMapper.map1(OntResourceImpl.java:1607)
 at
com.hp.hpl.jena.ontology.impl.OntResourceImpl$ObjectAsMapper.map1(OntResourceImpl.java:1601)
 at com.hp.hpl.jena.util.iterator.Map1Iterator.next(Map1Iterator.java:35)
at
com.hp.hpl.jena.ontology.impl.OntResourceImpl.computeDirectValues(OntResourceImpl.java:1493)
 at
com.hp.hpl.jena.ontology.impl.OntResourceImpl.listDirectPropertyValues(OntResourceImpl.java:1466)
 at
com.hp.hpl.jena.ontology.impl.OntClassImpl.listSuperClasses(OntClassImpl.java:195)
 at
com.hp.hpl.jena.ontology.impl.OntClassImpl.isHierarchyRoot(OntClassImpl.java:722)
 at
com.hp.hpl.jena.ontology.impl.OntModelImpl$1.accept(OntModelImpl.java:527)
 at
com.hp.hpl.jena.ontology.impl.OntModelImpl$1.accept(OntModelImpl.java:524)
at
com.hp.hpl.jena.util.iterator.FilterKeepIterator.accept(FilterKeepIterator.java:22)
 at
com.hp.hpl.jena.util.iterator.FilterIterator.hasNext(FilterIterator.java:44)

But when I add all the namespace of another model to the new one and want
to create a blank node with given name then add it to the model to solve
it,it doesn't work.My method is that
Resource s = CreatedModel.createResource("
http://www.owl-ontologies.com/animal.owl#Herbivore");
Property p = CreatedModel.createProperty("
http://www.w3.org/2000/01/rdf-schema#subClassOf");
Resource o = CreatedModel.createResource(new
AnonId("72947f0e:134b7e616e0:-7ff8"));
CreatedModel.add(s,p,o);

After this process, when I list the statement of the CreatedModel, the new
created blank node is not  72947f0e:134b7e616e0:-7ff8, but a random one.

4.So the last question is that could I ignore the statements with blank
node when I recreate a new model , will this affect the result ?Or how to
create and add a new created blank node with given name to the model?


I am very graceful for who can help!
Best Wishes!

Re: Could I ignore the blank node ?Or what's the usage of them?

Posted by Dave Reynolds <da...@gmail.com>.
On 07/01/2012 14:38, 锐光刘 wrote:
> I am new in the field of JENA,so don't laugh at me about this
> question,please.

Of course not, we all have had to learn this stuff at some time.

> My question is about the blank node,since I have no idea how to treat them.
> When I list the root class of a OWL file,there are a lot of blank
> nodes,even more than the class with URI.Such as
>
> http://xmlns.com/wordnet/1.6/Agent-3
> -51cb51a0:134b85abd5d:-7fd3
> -51cb51a0:134b85abd5d:-7fc1
> -51cb51a0:134b85abd5d:-7fc4
> -51cb51a0:134b85abd5d:-7fc7
> -51cb51a0:134b85abd5d:-7fca
> -51cb51a0:134b85abd5d:-7fcc
> -51cb51a0:134b85abd5d:-7fce
> -51cb51a0:134b85abd5d:-7fd1
>
> 1.the first question is that why there are so many blank nodes created as
> root class and what's the usage of them?
>
> then,when I list the statements of the file,I found there are also many
> statements with blank node ,for example:
> class: -51cb51a0:134b85abd5d:-7fcc
>   [-51cb51a0:134b85abd5d:-7fcc, http://www.w3.org/2002/07/owl#minCardinality,
> "1"^^http://www.w3.org/2001/XMLSchema#nonNegativeInteger]
>   [-51cb51a0:134b85abd5d:-7fcc, http://www.w3.org/2002/07/owl#onProperty,
> http://www.mindswap.org/2004/owl/funding#source]
>   [-51cb51a0:134b85abd5d:-7fcc,
> http://www.w3.org/1999/02/22-rdf-syntax-ns#type,
> http://www.w3.org/2002/07/owl#Restriction]
> class:-51cb51a0:134b85abd5d:-7fce
>   [-51cb51a0:134b85abd5d:-7fce, http://www.w3.org/2002/07/owl#someValuesFrom,
> http://www.mindswap.org/2004/owl/funding#Funding]
>   [-51cb51a0:134b85abd5d:-7fce, http://www.w3.org/2002/07/owl#onProperty,
> http://www.mindswap.org/2004/owl/funding#fundedBy]
>   [-51cb51a0:134b85abd5d:-7fce,
> http://www.w3.org/1999/02/22-rdf-syntax-ns#type,
> http://www.w3.org/2002/07/owl#Restriction]

When OWL is encoded in RDF you need some way to represent structured 
expressions such as the owl Restrictions. This is done by creating blank 
nodes to represent the Restrictions and the OWL class is then a 
subClassOf (or equivalent to) to the Restriction resource. This is what 
is happening in your example.

> 2.the second question is that why do these blank nodes exist? I can't find
> them in the Protégé gragh ,but only see them when I parse the file with
> JENA.

They are in the graph in both cases.

Protégé is choosing to show you just an OWL view of the data and it is 
hiding the blank nodes but showing you the Restrictions that those blank 
nodes encode.

Jena is showing you the full details of what is in the graph. From the 
point of view of RDF, RDFS and OWL/full these blank nodes are genuine 
resources (of type owl:Restriction) from an OWL/DL point of view they 
are part of the RDF machinery for encoding OWL expressions. The Jena 
OntAPI gives you convenience methods like isRestriction and 
as*Restriction to work with these resources.

> Another situation is that when you list all the statements of a class which
> have URI, some statements are very similar,since the subject and predicate
> of the statement are same while one object is a resource with URI and
> another is a blank node.for example
> the statements for class  http://www.owl-ontologies.com/animal.owl#Giraffe is
> three
>   [http://www.owl-ontologies.com/animal.owl#Giraffe,
> http://www.w3.org/2000/01/rdf-schema#subClassOf, 72947f0e:134b7e616e0:-7ff9]
>   [http://www.owl-ontologies.com/animal.owl#Giraffe,
> http://www.w3.org/2000/01/rdf-schema#subClassOf,
> http://www.owl-ontologies.com/animal.owl#Herbivore]
>   [http://www.owl-ontologies.com/animal.owl#Giraffe,
> http://www.w3.org/1999/02/22-rdf-syntax-ns#type,
> http://www.w3.org/2002/07/owl#Class]

That's not a different case.

> 3.the third question is that is the blank node( 72947f0e:134b7e616e0:-7ff9 )
> here a  complement or equal class of
> http://www.owl-ontologies.com/animal.owl#Herbivore.

You haven't shown the statements which refer to 
72947f0e:134b7e616e0:-7ff9 so we can't tell you that for certain.

> If it is ,why  to
> created a blank node ?

Same as above. You need to have something represent the class which is 
the complement of Herbivore.

Specifically if you look at the rules in [1] you'll see that the RDF 
encoding of the OWL axioms:

    Class: eg:Giraffe
      SubClassOf: ObjectComplementOf (eg:Herbivore)

is, in Turtle syntax:

    eg:Giraffe a owl:Class;
        rdfs:subClassOf [a owl:Class;  owl:complementOf eg:Heribore] .

this corresponds to the triples:

    eg:Giraffe rdf:type owl:Class .
    eg:Giraffe rdfs:subClassOf _:1 .
    _:1 rdf:type owl:Class .
    _:1 owl:complementOf eg:Heribore .

> Because I want to receate a model with part of the information from another
> model,so I list all the statements and add them to the new CreatedModel.But
> I don't know how to deal with the ones with blank node.If I ignore
> them,that't OK.

Not OK. The statements which include those blank nodes are an essential 
part of the model so you need to add those, or some equivalent, to the 
new model as well.

> But when I add all the namespace of another model to the new one and want
> to create a blank node with given name then add it to the model to solve
> it,it doesn't work.My method is that
> Resource s = CreatedModel.createResource("
> http://www.owl-ontologies.com/animal.owl#Herbivore");
> Property p = CreatedModel.createProperty("
> http://www.w3.org/2000/01/rdf-schema#subClassOf");
> Resource o = CreatedModel.createResource(new
> AnonId("72947f0e:134b7e616e0:-7ff8"));
> CreatedModel.add(s,p,o);
>
> After this process, when I list the statement of the CreatedModel, the new
> created blank node is not  72947f0e:134b7e616e0:-7ff8, but a random one.

There are several ways to handle this depending on what you want to achieve.

(1) Just add the statements.

If you have statement S from model1 and you want to add that statement 
to model2 then just do:

     model2.add( S )

It doesn't matter if S mentions blank nodes or not.

(2) If you want to create a resource with the same identity but have be 
"in" model2 so that you can add new properties do it then do:

    Resource bn2 = bn.inModel( model2 );

where bn is the Resource corresponding to the original blank node.

(3) If you want the new model to have the same structure as the original 
but use fresh blank nodes then create a new blank node yourself:

     Resource bn2 = model2.createResource()

and use a HashMap to record the blank node you have created to 
correspond to each source blank node.

> 4.So the last question is that could I ignore the statements with blank
> node when I recreate a new model , will this affect the result ?

See above, no you can't just ignore blank nodes.

Dave

[1] 
http://www.w3.org/TR/owl2-mapping-to-rdf/#Translation_of_Axioms_without_Annotations