Coder Social home page Coder Social logo

rdf-trix's Introduction

TriX Support for RDF.rb

TriX reader/writer for RDF.rb .

Gem Version Build Status Coverage Status Gitter chat

Description

This is a [Ruby][] implementation of a TriX reader and writer for RDF.rb. TriX is an XML-based RDF serialization format developed by HP Labs and Nokia.

Features

RDF::TriX parses TriX into statements or quads. It also serializes to TriX.

Install with gem install rdf-trix

  • 100% free and unencumbered public domain software.
  • Implements a complete parser and serializer for TriX.
  • Compatible with Ruby >= 3.0, and JRuby 9+.

Support for xml:base

The TriX reader natively supports xml:base in the top-level element without the need for an XSLT. This allows values of a uri element to be relative URIs and resolved against that base. The base can also be specified as an option to the reader.

For example:

<TriX xmlns="http://www.w3.org/2004/03/trix/trix-1/"
      xml:base="http://example.org/">
  <graph>
    <uri>graph1</uri>
    <triple>
      <uri>Bob</uri>
      <uri>wife</uri>
      <uri>Mary</uri>
    </triple>
    <triple>
      <uri>Bob</uri>
      <uri>name</uri>
      <plainLiteral>Bob</plainLiteral>
    </triple>
    <triple>
      <uri>Mary</uri>
      <uri>age</uri>
      <typedLiteral datatype="http://www.w3.org/2001/XMLSchema#integer">32</typedLiteral>
    </triple>
 </graph>
</TriX>

RDF-star

Both reader and writer include provisional support for RDF-star.

Internally, an RDF::Statement is treated as another resource, along with RDF::URI and RDF::Node, which allows an RDF::Statement to have a #subject or #object which is also an RDF::Statement.

RDF-star is supported by allowing a triple element to contain another triple as either or both the subject or object.

Note that this requires the rdfstar option to be se.

Note: This feature is subject to change or elimination as the standards process progresses.

For example:

<TriX xmlns="http://www.w3.org/2004/03/trix/trix-1/">
  <graph>
    <triple>
      <triple>
        <uri>http://example/s1</uri>
        <uri>http://example/p1</uri>
        <uri>http://example/o1</uri>
      </triple>
      <uri>http://example/p</uri>
      <uri>http://example/o</uri>
    </triple>
  </graph>
</TriX>

Usage

Instantiate a reader from a local file:

repo = RDF::Repository.load("etc/doap.trix", :format => :trix)

Define @base and @prefix definitions, and use for serialization using :base_uri an :prefixes options.

Canonicalize and validate using :canonicalize and :validate options.

Write a repository to a file:

RDF::TriX::Writer.open("etc/test.trix") do |writer|
   writer << repo
end

Change Log

See Release Notes on GitHub

Dependencies

Documentation

  • {RDF::TriX}
    • {RDF::TriX::Format}
    • {RDF::TriX::Reader}
    • {RDF::TriX::Writer}

Installation

The recommended installation method is via RubyGems. To install the latest official release of the RDF::TriX gem, do:

% [sudo] gem install rdf-trix

Download

To get a local working copy of the development repository, do:

% git clone git://github.com/ruby-rdf/rdf-trix.git

Alternatively, download the latest development version as a tarball as follows:

% wget https://github.com/ruby-rdf/rdf-trix/tarball/master

Mailing List

Authors

Contributors

Refer to the accompanying {file:CREDITS} file.

Contributing

This repository uses Git Flow to mange development and release activity. All submissions must be on a feature branch based on the develop branch to ease staging and integration.

  • Do your best to adhere to the existing coding conventions and idioms.
  • Don't use hard tabs, and don't leave trailing whitespace on any line. Before committing, run git diff --check to make sure of this.
  • Do document every method you add using [YARD][] annotations. Read the [tutorial][YARD-GS] or just look at the existing code for examples.
  • Don't touch the .gemspec or VERSION files. If you need to change them, do so on your private branch only.
  • Do feel free to add yourself to the CREDITS file and the corresponding list in the the README. Alphabetical order applies.
  • Don't touch the AUTHORS file. If your contributions are significant enough, be assured we will eventually add you in there.
  • Do note that in order for us to merge any non-trivial changes (as a rule of thumb, additions larger than about 15 lines of code), we need an explicit public domain dedication on record from you, which you will be asked to agree to on the first commit to a repo within the organization. Note that the agreement applies to all repos in the Ruby RDF organization.

License

This is free and unencumbered public domain software. For more information, see https://unlicense.org/ or the accompanying {file:UNLICENSE} file.

rdf-trix's People

Contributors

gkellogg avatar artob avatar

Stargazers

 avatar James Benner avatar  avatar  avatar

Watchers

 avatar  avatar Justin Coyne avatar Chris Beer avatar Aymeric Brisse avatar David Butler avatar Julien Pervillé avatar James Cloos avatar Dorian Taylor avatar tamsin woo avatar  avatar

Forkers

anukat2015

rdf-trix's Issues

Not working

This is not working for me with either REXML or Nokogiri:

repo1 = RDF::Repository.new
repo1 << RDF::Statement.new([example.a, example.prop, example.b])
RDF::Writer.open('./out.trix', :format => :trix) do | writer |
  repo1.each_statement do | statement | 
    writer << statement
  end
end

Gives:
ArgumentError: Node.replace requires a Node argument, and cannot accept a Document.
(You probably want to select a node from the Document with at() or search(), or create a new Node via Node.new().)

from /opt/local/lib/ruby/gems/1.8/gems/nokogiri-1.4.1/lib/nokogiri/xml/node.rb:724:in `verify_nodeishness'
from /opt/local/lib/ruby/gems/1.8/gems/nokogiri-1.4.1/lib/nokogiri/xml/node.rb:240:in `<<'
from /opt/local/lib/ruby/gems/1.8/gems/rdf-trix-0.0.3/lib/rdf/trix/writer.rb:174:in `format_triple'

And:
RDF::Writer.for(:trix).new(File.open('./out.trix','w'), :library => :rexml) do | writer |
repo1.each_statement do | statement |
writer << statement
end
end

Gives:

NoMethodError: undefined method `parent=' for nil:NilClass
from /opt/local/lib/ruby/1.8/rexml/parent.rb:19:in `<<'
from /opt/local/lib/ruby/gems/1.8/gems/rdf-trix-0.0.3/lib/rdf/trix/writer.rb:174:in `format_triple'
from /opt/local/lib/ruby/gems/1.8/gems/rdf-trix-0.0.3/lib/rdf/trix/writer/rexml.rb:88:in `call'
from /opt/local/lib/ruby/gems/1.8/gems/rdf-trix-0.0.3/lib/rdf/trix/writer/rexml.rb:88:in `create_element'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.