ruby-rdf / json-ld

Ruby JSON-LD reader/writer for RDF.rb
The Unlicense
232 stars 27 forks source link

gen_context script usage #60

Closed s0rin closed 1 year ago

s0rin commented 1 year ago

To create a context from an RDFS/OWL definition using the script/gen_context script several parameters are mandatory required, but no example is documented.

Attempted to do with the ontology https://d-nb.info/standards/elementset/gnd.rdf, but got the following error:

$ ruby gen_context.rb --body --initial gnd_20221010.rdf --language en --output gnd_context --prefix "https://d-nb.info/standards/elementset" --vocab "https://d-nb.info/standards/vocab/gnd"

        from /home/rails5/.rbenv/versions/3.2.2/lib/ruby/3.2.0/json/common.rb:216:in `parse'
        from gen_context.rb:69:in `block in <main>'
        from /home/rails5/.rbenv/versions/3.2.2/lib/ruby/3.2.0/getoptlong.rb:863:in `block in each'
        from /home/rails5/.rbenv/versions/3.2.2/lib/ruby/3.2.0/getoptlong.rb:860:in `loop'
        from /home/rails5/.rbenv/versions/3.2.2/lib/ruby/3.2.0/getoptlong.rb:860:in `each'
        from gen_context.rb:66:in `<main>'

What am I doing wrong here?

gkellogg commented 1 year ago

This is mostly an internal tool, but there is some documentation:

ruby gen_context.rb --help

Usage: script/gen_context [options] URL ...
  --body          Include the vocabulary definition in the body of the document
  --hierarchical  Create a hierachy using 'children' as reverse of rdfs:subClassOf
  --initial       Initial context to load, overrides default
  --language      Default language for vocabulary
  --output, -o    Output to the specified file path
  --prefix        space-separated prefix uri combination
  --quiet         Supress most output other than progress indicators
  --verbose       Detail on execution
  --vocab         Set context @vocab to specified URI
  --help, -?      This message

The --initial option expects a JSON-LD context, while you're providing the oncology itself.

There was a bug in some of the necessary code, which I've updated on the develop branch and will be out in the next release. If you clone the gem on your machine, do a bundle install, then run bundle exec ruby script/gen_context --language en --prefix "https://d-nb.info/standards/elementset" --vocab "https://d-nb.info/standards/vocab/gnd" https://d-nb.info/standards/elementset/gnd.rdf. You can add a --output option, but the next argument is treated as the output file.

s0rin commented 1 year ago

Although gen_context is mentioned and recomended in the documentation https://github.com/ruby-rdf/json-ld#features, it won't be installed within the gem, but with git clone https://github.com/ruby-rdf/json-ld.git, then cd json-ld and bundle install and I guess this is the reason why it is an internal tool.

s0rin commented 1 year ago

./json-ld/script/gen_context --language en --prefix "https://d-nb.info/standards/elementset" --vocab "https://d-nb.info/standards/vocab/gnd" https://d-nb.info/standards/elementset/gnd.rdf --output context.json runs without error now, thank you!

gkellogg commented 1 year ago

I could consider merging it into bin/jsonld, which is installed, if it is popular enough.

s0rin commented 1 year ago

Personally I am using this script and it would be useful to be available after gem installation.