You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by aidy lewis <ai...@gmail.com> on 2013/01/08 18:42:53 UTC

Identify Blank Nodes

Hi,

I have a RDF statement that I have added to the Jena model. The
statement contains a blank node.

_:blankNode <urn:b> <urn:c> .

To identify this blank node, I am using the isAnon method.

// Scala code

model.listStatements().toList().foreach(f =>
      println(f.getSubject.getLocalName + " " + f.getSubject.isAnon))

//


For some reason, true is not being returned for the blank node.

Am I using the correct approach?

-- 
Aidy

Re: Identify Blank Nodes

Posted by Andy Seaborne <an...@apache.org>.
On 08/01/13 17:42, aidy lewis wrote:
> Hi,
>
> I have a RDF statement that I have added to the Jena model. The
> statement contains a blank node.
>
> _:blankNode <urn:b> <urn:c> .
>
> To identify this blank node, I am using the isAnon method.
>
> // Scala code
>
> model.listStatements().toList().foreach(f =>
>        println(f.getSubject.getLocalName + " " + f.getSubject.isAnon))
>
> //
>
>
> For some reason, true is not being returned for the blank node.

I get "null true" (code below)

If you get something non-null from getLocalName then it isn't a blank 
node.  It's a URI node.

f.getSubject.getLocalName is the local name of a URI.

The bNode label is:
    f.getSubject.getId.getLabelString


---------------------
package dev

import com.hp.hpl.jena.sparql.sse.SSE
import com.hp.hpl.jena.rdf.model.ModelFactory
import com.hp.hpl.jena.rdf.model.Statement

object ReportBNode {
   def main(arrgs:Array[String]) : Unit = {
     import scala.collection.JavaConversions._
     val triple = SSE.parseTriple("(_:blankNode <urn:b> <urn:c>)")
     val model = ModelFactory.createDefaultModel()
     model.getGraph.add(triple)
     model.listStatements().foreach(f =>
        println(f.getSubject.getId.getLabelString + " " + 
f.getSubject.isAnon()))
   }
}
---------------------


>
> Am I using the correct approach?
>