Skip to content

Support language tags for literals #15

Closed
fumi opened this Issue Jun 28, 2010 · 9 comments

4 participants

@fumi
fumi commented Jun 28, 2010

Hi,

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.

[1] http://github.com/fumi/spira

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

require 'spira'
require 'linkeddata'

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

repo = "http://fumi.me/foaf.rdf"
Spira.add_repository!(:default, RDF::Repository.load(repo))

fumi = Person.for(RDF::URI("http://fumi.me/foaf.rdf#me"))
puts fumi.name
puts fumi.nick
@bhuga
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
bhuga commented Jun 28, 2010

See RDF.rb issue 30 at http://github.com/bendiken/rdf/issues/issue/30, which is how I'd like to solve this. You'd end up with:

fumi = Person.for(RDF::URI("http://fumi.me/foaf.rdf#me"))
puts fumi.name.map { |name| name.language }.inspect
#=> ["en","ja"]
@fumi
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?

fumi.name = "Name"
fumi.name.language = "en"
fumi.save!
@bhuga
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:

fumi.name                  #=> "加藤文彦"
fumi.name.language  #=> "ja"

Then you do:

fumi.name = "Fumihiro Kato"

The question is:

fumi.name.language  # => "ja" or nil?
@fumi
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:

fumi.name = "Fumihiro Kato"
fumi.name.language  # => nil

It may be useful if spira also accepts to set a language tagged literal directly as a syntax suger.

fumi.name = '"Fumihiro Kato"@en'
fumi.name    # => "Fumihiro Kato"
fumi.name.language  # => "en"
@heyLu
heyLu commented Jan 9, 2011

Why not do it like this:

fumi.name = "Fumihiro Kato", :language => "en"

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

@bhuga
bhuga commented Jan 9, 2011

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

@ghost
ghost commented Dec 1, 2011

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

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

Support language tags for literals #15

@bendiken
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.