GeoKnow / Jassa

JAvascript Suite for Sparql Access
25 stars 3 forks source link

[FEATURE-REQUEST] Add languageFilter to criteria #11

Open leipert opened 10 years ago

leipert commented 10 years ago
store.addMap({
    name: 'castles',
    template: [{
        id: '?s',
        name: '?l'
    }],
    from: '?s a dbpedia-owl:Castle ; rdfs:label ?l ; '
});

var criteria = {name: {$regex: filterText, $lang: "en"}};

looks much better than

store.addMap({
    name: 'castles',
    template: [{
        id: '?s',
        name: '?l'
    }],
    from: '?s a dbpedia-owl:Castle ; rdfs:label ?l ; '
         + 'Filter(langMatches(lang(?l), "en"))'
});

var criteria = {name: {$regex: filterText}};
leipert commented 10 years ago

@Aklakan I propose the following structure for a sponate language filter. Imagine you have the following JSON result from a SPARQL request:

{
   "head": {
      "link": [],
      "vars": ["id", "a", "b", "c"]
   },
   "results": {
      "distinct": false,
      "ordered": true,
      "bindings": [
         {
           "id": { "type": "uri", "value": "http://e.org/a" },
           "a":  { "type": "literal", "value": "No Language" },
           "b":  { "type": "literal", "xml:lang": "de", "value": "Deutsch" },
           "c":  { "type": "literal", "xml:lang": "en", "value": "Only en" }
         },
         {
           "id": { "type": "uri", "value": "http://e.org/a" },
           "a":  { "type": "literal", "value": "No Language" },
           "b":  { "type": "literal", "xml:lang": "en", "value": "Englisch" },
           "c":  { "type": "literal", "xml:lang": "en", "value": "Only en" }
         },
      ]
   }
}

Only one language:

var langFilter = {$lang: 'de'}
var criteria = {a: langFilter, b: langFilter, c: langFilter}
var flow = store.example.find(criteria)
flow.asList()
    .done(function(docs) {
        console.log(docs);
    });
// Prints
// [{id: "http://e.org/a", a: null, b: "Deutsch", c: null}]

Multiple Languages in prefered order:

var langFilter = {$lang: ['de','en']}
var criteria = {a: langFilter, b: langFilter, c: langFilter}
var flow = store.example.find(criteria)
flow.asList()
    .done(function(docs) {
        console.log(docs);
    });
// Prints
// [{id: "http://e.org/a", a: null, b: "Deutsch", c: "Only en"}]

With wildcard:

var langFilter = {$lang: ['de','en','*']}
var criteria = {a: langFilter, b: langFilter, c: langFilter}
var flow = store.example.find(criteria)
flow.asList()
    .done(function(docs) {
        console.log(docs);
    });
// Prints
// [{id: "http://e.org/a", a: "No Language", b: "Deutsch", c: "Only en"}]