0.0
No release in over 3 years
A lightweight helper that makes inserting RDF triples (and quads) very convenient. It automatically converts strings into proper RDF::URI or RDF::Literal objects with sensible datatype guessing (including xsd:date and xsd:dateTime) and supports language tags.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 3.0
~> 3.13
 Project Readme

TripleEasy

Make RDF triples (and quads) easily.

triple_easy is a lightweight Ruby gem that provides a single convenient top-level function triplify to insert RDF statements into any RDF::Repository (or other mutable RDF store). It automatically converts plain strings into proper RDF::URI or RDF::Literal objects with sensible datatype guessing.

Installation

Add this line to your application's Gemfile:

gem 'triple_easy'

why "easy"?

  • You can pass URI strings or RDF::Resource objects as S/P/O and it does the most obvious thing.
  • In the Object position, for non-URI strings, it does some regexp matching to guess what Literal datatype it should be, and auto-creates that RDF Literal
  • If you, for example, explicitly want "http://example.org" in the Object position to be a Literal (string), then you can override the auto-detect (this is useful when facing a dct:identifier property, where the range is a string, even if the string is a URI!)

Examples of usage:

require 'triple_easy'

repo = RDF::Repository.new

# Basic triple
triplify("http://example.org/alice",
         "http://xmlns.com/foaf/0.1/name",
         "Alice Smith",  # string will default to language "en"
         repo)

# With language tag (non-English)
triplify("http://example.org/bob",
         "http://xmlns.com/foaf/0.1/name",
         "Bob Schmidt",
         repo,
         language: "de")

# With explicit datatype
triplify("http://example.org/charlie",
         "http://schema.org/age",
         "42",
         repo,
         datatype: RDF::XSD.integer)

# Date and DateTime auto-detection
triplify("http://example.org/diana",
         "http://schema.org/birthDate",
         "1995-06-15",          # → xsd:date
         repo)

triplify("http://example.org/diana",
         "http://schema.org/lastSeen",
         "2025-03-27T14:30:00", # → xsd:dateTime
         repo)

# Quad (with named graph / context)
triplify("http://example.org/eve",
         "http://xmlns.com/foaf/0.1/knows",
         "http://example.org/alice",
         repo,
         context: "http://example.org/my-graph")
         

to use in your classes:

module Example
   class MyExample
      include TripleEasy     # bring "triplify" into this class
      def initialize
      end
   end
end

Features

  • Automatic URI detection for subjects, predicates, and objects
  • Smart literal detection:
    • xsd:date and xsd:dateTime
    • xsd:float and xsd:integer
  • Language-tagged strings (default: English)
  • Optional explicit datatype (takes precedence)
  • Support for named graphs (context)
  • Returns true on success, false if any required argument is empty
  • Raises helpful errors for invalid URIs

Full API documentation is available on rubydoc.info.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rspec to run the tests.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/markwilkinson/triple-easy.

License

The gem is available as open source under the terms of the MIT License.

ACKNOWLEDGEMENTS

Developed in the context of the OSTrails project and the FAIR Champion initiative.

This project has received funding from the European Union’s Horizon Europe framework programme under grant agreement No. 101130187. Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Research Executive Agency. Neither the European Union nor the European Research Executive Agency can be held responsible for them.


Made with ❤️ for the FAIR community