Graph Traversal Question

20 views
Skip to first unread message

Andreas Wundsam

unread,
Jul 22, 2011, 3:28:37 AM7/22/11
to scardf
Hi,

We are running into what I am quite sure is a beginner's problem with
our initial testing.

Part of our graph looks like this:

<rdf:Description rdf:about="lccontent:System">
<j.0:currentContent rdf:resource="lccontent:System/16"/>
</rdf:Description>

<rdf:Description rdf:about="lccontent:System/16">
<dc:title>Or System Node</dc:title>
<j.0:childSeq rdf:nodeID="A4307"/>
</rdf:Description>

Conceptually, we have a symbolic resource ("lccontent:system") that is
a link to a versioned resource ("lccontent:System/16"), and this
resource has a title.I have a Scala Vocabulary defined for that
purpose:

object ContentVoc extends Vocabulary( "http://www.teleteach.com/rdf/
contentVocabulary#" ) {
val currentContent = prop( "currentContent" ) //
uriref("currentContent") or %("currentContent") yields the same result
}

Now I would like to traverse the tree as shown in the example

val title = (graph/system/currentContent/title/asString)

But this fails on compilation with

[error] ScaRDFTest.scala:23: overloaded method value / with
alternatives:
[error] [T(in method /)](nc: org.scardf.NodeToValueConverter[T(in
method /)])T(in method /) <and>
[error] [T(in method /)](bc: org.scardf.NodeBagConverter[T(in
method /)])T(in method /) <and>
[error] (predicate: org.scardf.UriRef)org.scardf.NodeBag
[error] cannot be applied to (com.hp.hpl.jena.rdf.model.Property)
[error] val systemNode = (graph/system/currentContent/title/
asString)

Intuitively, the problem seems to be that the Scala compiler does not
know that currentContent yields a SubjectNode. But I can't seem to
figure out how to solve that, as declaring the vocabulary with prop,
%, or uriref yields the same result.

Any hints?

Thanks.
-- Andi

Hrvoje Šimić

unread,
Jul 22, 2011, 3:41:55 AM7/22/11
to sca...@googlegroups.com
> [error] ScaRDFTest.scala:23: overloaded method value / ...

> [error]  cannot be applied to (com.hp.hpl.jena.rdf.model.Property)
> [error]     val systemNode = (graph/system/currentContent/title/
> asString)

Is 'title' a com.hp.hpl.jena.rdf.model.Property? It should be an
UriRef. As in Jena.uriref(title)

Scardf methods use Scardf types. You could make an implicit conversion
method Jena->Scardf, probably.

Hrvoje

Andreas Wundsam

unread,
Jul 22, 2011, 3:55:06 AM7/22/11
to scardf
> Is 'title' a com.hp.hpl.jena.rdf.model.Property? It should be an
> UriRef. As in Jena.uriref(title)

// graph is read from XML using JenaSerializer
val graph = new JenaSerializator( RdfXml ).readFrom( new
java.io.FileReader( "/tmp/rdf.xml" ) )

// 'title' is a DC_11 property:
com.hp.hpl.jena.vocabulary.DC_11.title

//Current content is a ScaRDF property, as in
object ContentVoc extends org.scardf.Vocabulary( "http://
www.teleteach.com/rdf/contentVocabulary#" ) {
val currentContent = prop( "currentContent" ) // or uriref, or %,
makes no difference
}

> Scardf methods use Scardf types. You could make an implicit conversion
> method Jena->Scardf, probably.

So what you're saying is that
1.) the type hierarchy of ScaRDF is different from the one Jena uses
2.) my graph, because it is read from XML is a 'Jena' graph
3.) the ScaRDF path traversal only works on graphs that are directly
constructed in ScaRDf, not when
the graph is read from XML using JenaSerializator?

-- Andi

Hrvoje Šimić

unread,
Jul 22, 2011, 4:09:45 AM7/22/11
to sca...@googlegroups.com
>> Scardf methods use Scardf types. You could make an implicit conversion
>> method Jena->Scardf, probably.
>
> So what you're saying is that
>  1.) the type hierarchy of ScaRDF is different from the one Jena uses
>  2.) my graph, because it is read from XML is a 'Jena' graph
>  3.) the ScaRDF path traversal only works on graphs that are directly
> constructed in ScaRDf, not when
> the graph is read from XML using JenaSerializator?

1. Yes
2. No
3. No

Scardf API doesn't depend on Jena. It just has an extension for
accessing Jena structures.

com.hp.hpl.jena.vocabulary.DC_11.title is a Jena object and NodeBag's
slash method doesn't work with Jena objects directly.

So you should create your own fields:

val title = Jena.uriref(com.hp.hpl.jena.vocabulary.DC_11.title)

or you can make an implicit conversion to do this automatically for
you (within the scope of implicits):

implicit def toUriRef( jenaRes: Resource ) = Jena.uriref( jenaRes )

All code is written from the top of my head, so beware of errors.

Hrvoje

Andreas Wundsam

unread,
Jul 22, 2011, 12:39:04 PM7/22/11
to scardf
OK, got quite a few steps further. Thanks for the quick reply!

One more question: Is there an elegant way to retrieve a 'Seq' ordered
list of values
from the graph when traversing? From looking at the source code, I
couldn't find any specific support for Seq elements (except for
building graphs). Am I overlooking something?

Thanks.

-- Andi

Hrvoje Šimić

unread,
Jul 25, 2011, 3:08:51 AM7/25/11
to sca...@googlegroups.com
Not sure I follow. NodeBags are Traversable, you can get a sequence with toSeq?

Hrvoje


2011/7/22 Andreas Wundsam <andreas...@teleteach.de>:

Andreas Wundsam

unread,
Jul 25, 2011, 4:49:37 AM7/25/11
to scardf
Hi,

to elaborate: a graph traversal (roughly: graph/parentNode/
currentVersion/children) returns a NodeBag with one node in it that is
an anonymous node of RDF type 'Seq' (A1 in the example). That node
could be represented in XML as:

<rdf:Description rdf:nodeID="A1">
<rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-
ns#Seq"/>
<rdf:_1 rdf:resource="child1"/>
<rdf:_2 rdf:resource="child2"/>
<rdf:_3 rdf:resource="child3"/>
</rdf:Description>

Now I'd like to iterate through the children of this node in order
(following the strange rdf:_1, _rdf:2 etc. predicates). Of course,
that can be done manually on the node, but I was wondering if ScaRDF
had any special mechanism for this iteration, because I would exepect
it to be a fairly common case.

-- Andi




On 25 Jul., 09:08, Hrvoje Šimić <hrvojesi...@gmail.com> wrote:
> Not sure I follow. NodeBags are Traversable, you can get a sequence with toSeq?
>
> Hrvoje
>
> 2011/7/22 Andreas Wundsam <andreas.wund...@teleteach.de>:

Hrvoje Šimić

unread,
Jul 25, 2011, 5:03:03 AM7/25/11
to sca...@googlegroups.com
I see. Scardf doesn't directly support rdf:Seq (container), only
rdf:List (collection). Perhaps collections are more suited for your
need?

Hrvoje


2011/7/25 Andreas Wundsam <andreas...@teleteach.de>:

Reply all
Reply to author
Forward
0 new messages