Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preserve data type #5

Closed
wants to merge 1 commit into from

Conversation

elf-pavlik
Copy link
Member

just noticed it and will post way of reproducing in hour or two ;)

@mcollina
Copy link
Collaborator

mcollina commented Dec 6, 2013

Cool! :) Let me know!

@elf-pavlik
Copy link
Member Author

sorry for this cryptic issue! we notticed it together with Markus Lanthaler during our short meeting in Graz yesterday and I didn't want to use too much time for writing proper bug report...

var levelgraph = require('levelgraph');                                                                                                                                                 
var lgJSONLD = require('levelgraph-jsonld');                                                                                                                                                                                                                                                 
var db = lgJSONLD(levelgraph('test'));                                                                          

var graz = {                                                                                                     
  "@context": {                                                                                                  
    "@vocab": "http://schema.org/"                                                                               
  },                                                                                                             
  "@id": "http://dbpedia.org/resource/Graz",
  "@type": "City",                                                         
  "name": "Graz",                                                                                                
  "geo": {                                                                                                       
    "latitude": 47.0708101,                                                                                      
    "longitude": 15.4382918                                                                                      
  }                                                                                                              
};                                                                                                               

db.jsonld.put(graz, function() {                                                                                 
  db.jsonld.get(graz["@id"], { "@context": graz["@context"] }, function(err, doc) {                              
    console.log(doc);                                                                                            
  });                                                                                                            
});

running it prints

{ '@context': { '@vocab': 'http://schema.org/' },
  '@id': 'http://dbpedia.org/resource/Graz',
  '@type': 'City',
  geo: 
   { '@id': '_:f26890d0-5e5f-11e3-b04e-e3cb44466f3c',
     latitude: '4.70708101E1',
     longitude: '1.54382918E1' },
  name: 'Graz' 

as you see latitude and longitude turned into strings

@mcollina
Copy link
Collaborator

mcollina commented Dec 6, 2013

this is fun! :)
Part of the problem is here: https://github.com/mcollina/levelgraph-jsonld/blob/master/index.js#L37-L48, as only s p o are copied, and not any type information of the triple.
Then, that information is not taken into account in here: https://github.com/mcollina/levelgraph-jsonld/blob/master/index.js#L144.

Would you like to propose a fix?

@elf-pavlik
Copy link
Member Author

i'll try to chew on it but in next days hitchhiking might take some of my time :(

i understand that we only need to preserve type of object since subject and predicate always stay IRIs. at first sight i didn't notice exact place where numbers get converted into strings!

maybe we could use Tripple Properties for that? https://github.com/mcollina/levelgraph#triple-properties something in lines: "objectType": "xsd:double"...

BTW this one looks relevant: http://json-ld.org/spec/latest/json-ld-api/#data-round-tripping

and another one: http://json-ld.org/spec/latest/json-ld/#dfn-value-type
as well as section directly after it: http://json-ld.org/spec/latest/json-ld/#type-coercion

@elf-pavlik
Copy link
Member Author

we also need to make sure that we can use it together with N3/Turtle extension ... will need to check how it happens over there!

@mcollina
Copy link
Collaborator

mcollina commented Dec 6, 2013

maybe we could use Tripple Properties for that? https://github.com/mcollina/levelgraph#triple-properties something in lines: "objectType": "xsd:double"...

Exactly, that was my idea, check what N3.js is doing and be consistent, so that the modules are interoperable. :)

@elf-pavlik
Copy link
Member Author

var lg = require('levelgraph');                                                                                  
var lgN3 = require('levelgraph-n3');                                                                                                                                              
var db = lgN3(lg('test'));                                                                                       

var turtle = "@prefix c: <http://example.org/cartoons#>.\n" +                                                    
             "@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.\n" +                                             
             "c:Tom a c:Cat.\n" +                                                                                
             "c:Jerry a c:Mouse;\n" +                                                                            
             "        c:smarterThan c:Tom;\n" +                                                                  
             "        c:place \"fantasy\";\n" +                                                                  
             "        c:iq \"200\"^^xsd:integer.";

db.n3.put(turtle, function() {                                                                                   
  db.get({ predicate: 'http://example.org/cartoons#iq' }, function(err, triples) {                               
    console.log(triples);                                                                                        
  });                                                                                                            
});

prints out

[ { subject: 'http://example.org/cartoons#Jerry',
    predicate: 'http://example.org/cartoons#iq',
    object: '"200"^^<http://www.w3.org/2001/XMLSchema#integer>',
    context: 'n3/contexts#default' } ]

and it makes sense to just store object type within the object itself 😄

i'll play with https://github.com/mcollina/levelgraph-jsonld/blob/master/index.js#L37-L48 and make sure that for object we add datatype to value in triples returned by jsonld.toRDF()

i hope to find some time tomorrow and just fix it... starting with writing proper tests!

@ghost ghost assigned elf-pavlik Dec 7, 2013
@mcollina
Copy link
Collaborator

mcollina commented Dec 7, 2013

👍
If you feel it will grow too much for a single file, split it across multiple ones in the lib/ folder.

@elf-pavlik
Copy link
Member Author

@mcollina please don't merge yet! i just wanted to share initial experiment and refactor both tests and implementation ... i need to go through jsonld.js since most of that logic exists already over there and i would prefer to reuse it instead of duplicating.

@elf-pavlik elf-pavlik closed this Dec 16, 2013
@elf-pavlik elf-pavlik deleted the issue/datatype branch December 16, 2013 10:55
@elf-pavlik elf-pavlik restored the issue/datatype branch December 16, 2013 10:58
@elf-pavlik
Copy link
Member Author

oops! i thought i can rebase and attach new pull request to this issue... looks like now i will need to create new PR!

@elf-pavlik elf-pavlik deleted the issue/datatype branch December 16, 2013 11:12
@mcollina
Copy link
Collaborator

what's the state on this?
You can reopen this PR if you want to.

@elf-pavlik
Copy link
Member Author

looks like i can't re-open this one and will need to create another one... need to stay careful in a future not to convert issues into pull-request!

end of this week and early next week i plan some time to re-implement it in new way also addressing #4

@elf-pavlik elf-pavlik restored the issue/datatype branch December 19, 2013 13:47
@elf-pavlik elf-pavlik deleted the issue/datatype branch December 20, 2013 22:34
This was referenced Dec 20, 2013
elf-pavlik pushed a commit that referenced this pull request Jan 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants