RdfContext version 0.5.4 with provisional RDFa 1.1 support

Posted by Gregg Kellogg Fri, 07 May 2010 05:25:00 GMT

I just released version 0.5.4 of RdfContext to GitHub and GemCutter. This version is notable for including support for RDFa 1.1 parsing. This is still based on an Working Draft, so it will likely change in the future.

RDFa 1.1 includes support for profiles, vocabularies and terms. And supports using URIs or CURIEs or terms anywhere that's legal within an HTML document. Right now, only the XHTML+RDFa profile is supported.

Default term URI using @vocab.

RDFa 1.1 allows URIs to be expressed using an NCName, called a term, by using the @vocab attribute, an author can define a URI to be used for a bare word to turn it into a URI. Take for example the following:

<div vocab="http://xmlns.com/foaf/0.1/">
   <p about="#me" typeof="Person" property="name">Gregg Kellogg</p>
</div>

willgenerate the following triples:

<#me> a foaf:Person;
  foaf:name "Gregg Kellogg" .

Profile documents for defining prefixes and terms

A Profile document allows the specification of a set of URI mappings and term mappings in a single document. These documents are RDF formatted, and may or may not be RDFa. The following shows an example Profile document:

@prefix rdfa: <http://www.w3.org/ns/rdfa#> .
[ rdfa:prefix "foaf"; rdfa:uri "http://xmlns.com/foaf/0.1/"] .
[ rdfa:prefix "dc"; rdfa:uri "http://purl.org/dc/terms/"] .
[ rda:term "name"; rdfa:uri "http://xmlns.com/foaf/0.1/name"] .
[ rda:term "created"; rdfa:uri "http://purl.org/dc/terms/created"] .

This bit profile results in namespace mappings and a bare terms. Multiple vocabularies may be used together to create a namespace composed of terms from several vocabularies, without needing to describe them explicitly. These may then be used in a document as follows:

<div profile="http://example.com/my_vocab">
  <p about="#me">
    <span property="name">Gregg Kellogg</span>
    is the author of
    <a rel="created"
        resource="http://github.com/gkellogg/rdf_context">
      RdfContext
    </a>
  </p>
</div>

Namespace definitions

RDFa 1.1 deprecates the use of @xmlns for defining namespace prefixes. The @prefix attribute defines one or more mappings between prefixes and URIs. For example:

<div prefix="foaf: http://xmlns.com/foaf/0.1/ dc: http://purl.org/dc/terms/">
  <p about="#me">
    <span property="foaf:name">Gregg Kellogg</span>
    is the author of
    <a rel="dc:created"
        resource="http://github.com/gkellogg/rdf_context">
      RdfContext
    </a>
  </p>
</div>

Defines and uses two different namespace mappings.

URIs Everywhere

In RDFa 1.0, certain attributes took a URI, others a CURIE, and still others either a URI or a Safe CURIE. This is confusing, and RDFa 1.1 now allows either URIs, CURIEs, or SafeCURIEs to be used most anywhere (SafeCURIEs are maintained for backwards compatibility). For example:

<div>
    <p about="#me">
      <span property="http://xmlns.com/foaf/0.1/name">
        Gregg Kellogg
      </span>
      is the author of
      <a rel="http://purl.org/dc/terms/created"
          resource="http://github.com/gkellogg/rdf_context">
        RdfContext
      </a>
    </p>
  </div>
  

Change History

The following is the change log for this version of RdfContext. Note that one change may potentially break existing code: URIRef#namespace no longer throughs an exception if a mapping is not found. Other changes are noted here:

  • RDFa 1.1 parsing supported (based on RDFa Core 1.1 W3C Working Draft 22 April 2010)
  • Fix URIRef#short_name (and consequently #base and #namespace) to not extract a non-hierarchical path as a short_name
  • Namespace no longer uses URIRef, but just acts on strings.
  • Namespace#new does not take an optional _fragment_ argument any longer.
  • Added Namespace#to_s to output "prefix: uri" format
  • Graph#qname first trys generating using bound namespaces, then adds well-known namespaces.
  • URIRef#to_qname and #to_namespace No longer generates an exception. Each take either a Hash or an Array of namespaces and tries them from longest to shortest.
  • Improved Turtle and XML serializers in use of namespaces.
  • Generate pending messages if RDFa tests skipped due to lack of Redland installation.
  • Change dcterms: prefix to dc: (fully compatible with previous /elements/ definitions)

RdfContext version 0.5.1 brings Turtle and enhanced RDF/XML serializers

Posted by Gregg Kellogg Sat, 03 Apr 2010 05:57:00 GMT

 Just pushed version 0.5.1 of RdfContext to GitHub and Gemcutter. This version includes a Serializer framework, including a AbstractSerializer, RecursiveSerializer and Turtle and RDF/XML serializers based on these. The RDF/XML serializer is a big improvement over the previous version, including Typed element names an RDF Container folding using parseType="collection".

RdfContext includes native Ruby parsers for RDF/XML, RDFa and N3-rdf, which includes Turtle and N-Triples. All parsers pass W3C tests (included in specs). It also includes context-aware quad store, with in-memory and SQLite3 storage models.

RdfContext gem released 1

Posted by Gregg Kellogg Sun, 03 Jan 2010 23:40:00 GMT

I've released version 0.4.4 of the RdfContext gem. As the name implies, RdfContext supports contextual data-stores bound to graphs, along with a ConjunctiveGraph providing the union of contexts within a given data-store.

  • Parses RDF/XML, RDFa and N3. RDF/XML and RDFa both pass all relevant W3C test cases (may be run through specs).
  • Graph and ConjunctiveGraph with pluggable data-stores. MemoryStore and SQLite3Store both support contexts as well as quoted-graphs and formulae, although no appropriate graph classes yet exist.
  • Graphs serialize to N-Triples and RDF/XML.
  • An RDF distiller runs on this site to test out different parsers. This is also useful for running automated RDFa Test Harness. 

RdfContext is based, in part on Tom Morris' Reddy gem. See the readme on GitHub for more information. MemoryStore, SQLite3Store and ConjunctiveGraph are largely ports of Python RDFLib.

rdfa_parser gem released

Posted by Gregg Kellogg Sun, 18 Oct 2009 20:11:00 GMT

I just released version 0.1.0 of the rdfa_parser_gem. This parser is written in pure Ruby and uses Nokogiri XML parsing. It passes all XHTML1 test cases and most of the existing test cases for HTML4 and HTML5.

The gem is based on previous work done by Ben Adida and some libraries borrowed from the Reddy Gem.

The project is hosted on GitHub, feel free to clone. You can try out the parser through a distiller.

Restful action caching

Posted by Gregg Kellogg Sat, 29 Aug 2009 23:35:00 GMT

Caching actions without layout can be complicated when multiple request formats are used. In particular, an HTML response may use a dynamic layout, in which case you want to use the :layout => false option. However, other formats (such as XML) don't use a layout, but the :layout => false option to _caches_action_ does not properly cache the body in this case. To solve the problem, create two caches action statements:

caches_action :show,
              :if => lambda { |c| c.request.format == :html },
              :cache_path => lambda { |c| c.cache_key },
              :layout => false   caches_action :show,
              :unless => lambda{ |c| c.request.format == :html },
              :cache_path => lambda { |c| c.cache_key },
              :layout => true

Also, relying on the accept header may not cause the action caching module to detect the appropriate format. Try this in your application_controller:

before_filter :set_explicit_request_format
def set_explicit_request_format
  # Set format explicitly from accept header, unless it's already set
  request.format = :html if request.format == :any
  params[:format] ||= request.format.to_sym.to_s
end

Detecting action caching within controller

Posted by Gregg Kellogg Sat, 29 Aug 2009 23:12:00 GMT

Rails offers three forms of caching within your controller: page, action and fragment. Page caching results in the fastest access times, as the results of the first call to an action are saved in a file so that subsequent accesses never even hit rails. However, for most applications, this isn't useful, as there may be dynamic content on a page, and this does not allow for authentication. Fragment caching is the most detailed, and allows different parts of a page to be cached and allows you to check for the presence of a cached fragment within your controller (or view), but it requires the most maintenance of cache keys. Action caching is a nice compromise between the two. It allows the controller to get into the action but takes care of cache key creation. It also allows for a dynamic layout using the :layout option. However, in some actions, the amount of work done by the controller may be non-trivial, so it would be nice to check for the presence of the cache within the body of the controller action. This can be solved by borrowing some code from within ActionController::Cachine::Actions.

def index
  cache_path = ActionCachePath.new(self, cache_key)
  return if self.read_fragment(cache_path.path)
  # body of action
end

Controlling your own cache keys is also useful, particularly for actions that may take a number of parameters:

def cache_key
  key = "#{params[:controller]}/#{params[:action]}"
  params.each_pair {|k, v| key += ":#{k}=#{v.gsub(/\s/, "_")}
  key
end

ButtonLabels updated for Rails 2.3

Posted by Gregg Kellogg Mon, 09 Mar 2009 03:18:00 GMT

The ButtonLabels plugin described in another post has been updated for Rails 2.3.

HTTP Digest Authentication in Rails 2.3 3

Posted by Gregg Kellogg Sun, 08 Mar 2009 21:30:00 GMT

After a fair amount of work, I'm happy to report that HTTP Digest Authentication is now a part of Rails 2.3. Although I put the finishing touches to get this into the release, it is based on work done by Dan Manges and Xavier Shay . Also, thanks to Don Parish for bug fixes and improvements after original acceptance.

Read more about HTTP Digest Authentication in Rails 2.3 Ryan's Scraps. Relevant Lighthouse entries: 1230, 1848, and 2000. The last one includes a change, not yet approved for 2.3, which allows for using the HA1 part of the digest to store a hash of the password, rather than the cleartext of the original version. Hopefully, we'll get a version of that in soon. Also, the current implementation depends on using a session secret when computing the nonce. 2000 proposes a way to avoid this so no session is required.

Hopefully. we'll see the open issues resolved and get this into a 2.3.1 update.

Gregg