Move literals handling to models and collections
bergie opened this issue · comments
Now we have two different ways to handle literals:
- Literals from RDFa (and tools like Create.js) are stored as-is, as string values
- Literals from services like Stanbol are arrays of objects with keys like
@language
and@value
This difference makes for messy code. We should implement all literals in the same way, as collections of Literal objects (with subtypes like StringLiteral and UriLiteral). __toString
methods should be used to allow simple usage.
This would allow setting values with:
e.set({'rdfs:label': 'Foo'});
e.set({
'rdfs:label': new v.StringLiteral({
value: 'Foo',
lang: 'en'
})
});
e.set({'rdfs:label': 'Foo'}, { lang: 'en' });
And getting with:
"" + e.get('rdfs:label'); // Foo
"" + e.get(('rdfs:label').get('en'); // Foo
For this, we also need to add default language handling in VIE:
var v = new VIE();
v.getLang (); // the language of the document OR "en"
v.setLang("de"); // accepts language codes only in ISO 639-1 format
v.getLang(); // "de"