W3C home > Mailing lists > Public > public-rdf-ruby@w3.org > July 2015

Re: Parsing & validating a document

From: Gregg Kellogg <gregg@greggkellogg.com>
Date: Wed, 22 Jul 2015 19:08:25 -0700
Message-ID: <1455582130235188642@unknownmsgid>
To: Stefan Novak <novast@ohsu.edu>
Cc: Gregg Kellogg <gregg@greggkellogg.net>, "public-rdf-ruby@w3.org" <public-rdf-ruby@w3.org>
On Jul 22, 2015, at 6:42 PM, Stefan Novak <novast@ohsu.edu> wrote:

  Hey Gregg,

Thanks for the quick reply! The CWL schemas are still in draft form, but I
can look into getting a PR prepped for the rdf-vocab repository. Are there
any recommendations for maintaining different versions of vocabularies? For
example, CWL has a draft-2 and draft-3 version available.

I did make some progress on my end:

   -

   I can create a Graph directly from a Turtle schema that I have available.
   -

   I can create a context from that graph and attach it to the document to
   expand it.
   -

   I can convert that context to a document graph to validate and query.

 This can be seen here
<https://gist.github.com/slnovak/55eb543195d1e54c3608>.

Last last piece of the puzzle is to query that graph. Since my attribute
values are being parsed and stored in the @id attribute, I assume that I
would bind the id: attribute to a solution field (such as :text). However,
as you can see in the above Gist, I’m getting node names returned. Is there
a way to query the @id attribute?

I appreciate any feedback in the last step for querying the RDF graph.

Briefly, you might want to consider querying the graph using the sparql
gem, or with RDF::Query natively. Otherwise, framing is a kind of query for
JSON-LD and jsonpath for JSON generically.

Most RDF applications will query with SPARQL or a native graph query
interface.

Gregg

 Thanks again for writing clean specs and good docs – they’re super helpful!

Cheers!

 On Jul 22, 2015, at 12:43 PM, Gregg Kellogg <gregg@greggkellogg.net> wrote:

  On Jul 21, 2015, at 6:30 PM, Stefan Novak <novast@ohsu.edu> wrote:

  Hi,

First off, thanks for piecing together a well-rounded library! I really
appreciate the documentation and specs available to make it easier to
implement RDF in a project of mine.

I’m having a bit of trouble wrapping my head around the best way to
implement a Ruby version of the Common Workflow Langauge
<file:///Users/novast/common-workflow-language.github.io>.

Specifically, I’m trying to figure out the best way to parse out a
Workflow object.
I’d appreciate any feedback to get up and running!

My assumptions:

   -

   There’s a Turtle schema available
   <https://rawgit.com/common-workflow-language/common-workflow-language.github.io/master/draft-2/cwl.ttl>
that
   contains a list of classes. I can successfully process that schema as a
   RDF Schema
   <https://github.com/ohsu-computational-biology/common_workflow/blob/master/lib/common_workflow/schema.rb#L20>,
   and convert it to a JSON-LD object
   <https://github.com/ohsu-computational-biology/common_workflow/blob/master/lib/common_workflow/workflow.rb#L44>
   .
   -

   There’s a JSON-LD context
   <https://rawgit.com/common-workflow-language/common-workflow-language.github.io/master/draft-2/cwl-context.jsonld>
published
   for the schema. (Thanks for the rdf-turtle gem!)
   -

   I can take the above graph from the schema and the context to create the
   input for a data frame
   <https://github.com/ohsu-computational-biology/common_workflow/blob/master/lib/common_workflow/workflow.rb#L33>
   .
   -

   With that input, I’m trying to frame a document (a simple CLW workflow
   <https://github.com/common-workflow-language/common-workflow-language/blob/master/conformance/draft-2/cat1-tool.cwl>),
   however the object I get back contains just the @context attribute and
   no @graph property. According to the example in the JSON-LD docs
   <https://github.com/ruby-rdf/json-ld#frame-a-document>, I was hoping to
   get a @graph object that I can convert back to an RDF graph object.

 So – my questions are:

   1.

   Is this the right approach?
   2.

   At what point can I validate that my document (i.e., cat1-tool.cwl)
   conforms to the schema.
   3.

   Is it better to traverse the framed document in the JSON-LD form? Or
   should I convert it back to an RDF graph to traverse / query it there?

 Thanks! I appreciate any feedback!

 Seems like you generally have the right approach. Generate an RDF graph
and then serialize/frame as JSON-LD.

 Validation probably needs to be done with the graph, rather than a
particular serialization. If you create an RDF::Vocabulary sub-class using
the schema, you can validate the graph using that, along with other loaded
vocabularies. You can create a local version of the vocabulary to use with
your code using RDF::VocabularyLoader (see the rdf-vocab gem Rakefile, for
an example [1]). Eventually, it may be that the vocabulary would go into
the rdf-vocab gem.

 Validation is done using the rdf-reasoner gem, with specific methods that
are described there. The structured-data Linter [2][3] makes use of this to
validate input documents against loaded vocabularies, so that might be
something for you to look into.

 It’s probably better to break down the task and just produce unframed
JSON-LD. You can then use the JSON-LD playground [4] to frame your data.
Once you’re happy with that, you can frame using the json-ld gem, as you do
now; if the frame isn’t correct, it might not result in any output, so
that’s probably the problem you’re dealing with right now.

 Gregg

 [1] https://github.com/ruby-rdf/rdf-vocab
[2] http://linter.structured-data.org
[3] https://github.com/structured-data/linter
[4] http://json-ld.org/playground/index.html
Received on Thursday, 23 July 2015 02:09:15 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:02:18 UTC