Skip to content

Support language tags for literals #15

fumi opened this Issue Jun 28, 2010 · 9 comments

4 participants

fumi commented Jun 28, 2010


I would like to distinguish language tags for RDF::Literal on spira. My sample code and
spec are in my github [1]. The changes are only at Spira::Types::String class.


And this is a script that needs to specify language tags.

require 'spira'
require 'linkeddata'

class Person
  include Spira::Resource
  has_many :name, :predicate =>, :type => String
  has_many :nick, :predicate => FOAF.nick, :type => String

repo = ""
Spira.add_repository!(:default, RDF::Repository.load(repo))

fumi = Person.for(RDF::URI(""))
puts fumi.nick
bhuga commented Jun 28, 2010

This is a problem, but it's really a problem that could better be solved at the RDF.rb level by wrapping string in an object that also tracks the encoded language. I will post an issue there.

bhuga commented Jun 28, 2010

See RDF.rb issue 30 at, which is how I'd like to solve this. You'd end up with:

fumi = Person.for(RDF::URI(""))
puts { |name| name.language }.inspect
#=> ["en","ja"]
fumi commented Jun 29, 2010

Your proposal for reading looks fine for me. How about writing in this case? Probably does it look like this? = "Name" = "en"!
bhuga commented Jun 29, 2010

That would be ideal, but it's a little bit difficult to do it quite like that without monkey-patching String, which I'm not too excited about. I can also do it with hooks, which is something I want anyway. Even if I did monkey patch String, it's still a little confusing, because if you set the text, but not the language, would you expect the language to reset, or not to change? So say you load up some data, and you have this:                  #=> "加藤文彦"  #=> "ja"

Then you do: = "Fumihiro Kato"

The question is:  # => "ja" or nil?
fumi commented Jun 30, 2010

Setting a plain literal should be reset as it is like setting a new string object and we can not know which language tag a user expects. So the answer is: = "Fumihiro Kato"  # => nil

It may be useful if spira also accepts to set a language tagged literal directly as a syntax suger. = '"Fumihiro Kato"@en'    # => "Fumihiro Kato"  # => "en"
heyLu commented Jan 9, 2011

Why not do it like this: = "Fumihiro Kato", :language => "en"

Would that be ok? And, which other options would have to be supported?

bhuga commented Jan 9, 2011

That is not valid ruby syntax. #name= cannot take multiple arguments.

ghost commented Dec 1, 2011

This appears to be supported using :type => Spira::Types::Native, at least for reading and using"My Name", :language => 'en') for writing.

@abrisse abrisse referenced this issue in cordawyn/spira Feb 20, 2013

Support language tags for literals #15

Datagraph, Inc. member

This project has moved to ruby-rdf/spira. If this issue is still relevant, please resubmit it over there.

@bendiken bendiken closed this Aug 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.