Skip to content

New JSON query structure #770

@tfrancart

Description

@tfrancart
  • Objectives:
    • follow Traqula algebra structure as it will replace sparqljs
    • specify the query structure as a strict extension of the Traqula SPARQL algebra
    • enhanced compatibility with LLMs:
      • ability to explicitely embed children criterias in the object part of the criteria (so we understand they are tied to the object)
      • avoid repetition of the common subject in a serie of AND criterias (introduce a bgpSameSubject kind of pattern)
      • clearly associate the variable + type in a single entity
      • clearly associate the label to the variable (introduce a LabelledVariable kind of pattern)
      • refactor the "order" part like a standard order clause. When loading a query in the UI, if the order clause is not on a single variable which is the first one, ignore it
  • new features:
    • ability to express prefixes in the query
    • clear disctinction between values in the query vs. filters. Any fixed value, be it an IRI or a Literal, would go in a values clause and not a filters clause

Test query

Image

Proposed example structure:

{
  // all this to mimic Traqula
  "type": "query",
  "subType": "select",
  "distinct": true,
  "variables": [
    {
      "type" : "term",
      "subType": "variable",
      "value": "Artwork_1"
    }
  ],

  // "order": null,
  // change order to mimic sparqljs, but in our case this can be only the first variable in the query
  "solutionModifiers": {
    "order": {
      "type": "solutionModifier",
      "subType": "order",
      "orderDefs": [
        {
          "expression": {
            "type": "term",
            "subType": "variable",
            "value": "Artwork_1"
          },
          // si on a besoin de mettre un DESC
          // "descending": true
        }
      ]
    },
    "limitOffset": {
      "type": "solutionModifier",
      "subType": "limitOffset",
      "limit": 1000
    }
  },

  // change "branches" to "where"
  // and this is a single object, not an array. The array is bgpSameSubject
  //  "branches": [
  "where": {
    "type" : "pattern",
    "subType" : "bgpSameSubject",
    "subject": {
      // new type variable with an rdf:type
      "type": "term",
      "subType": "variable",
      "value": "Artwork_1",
      "rdfType": "https://data.mydomain.com/ontologies/sparnatural-config/Artwork"      
    },
    // list of predicate object pairs associated to the same subject declared above
    "predicateObjectPairs": [
      {
        "type": "predicateObjectPair",
        "predicate": {
          "type": "term",
          "subType": "namedNode",
          "value": "https://data.mydomain.com/ontologies/sparnatural-config/Artwork_displayedAt"
        },
        "object" : {
          "type": "objectCriteria",
          "variable": {
            "type": "term",
            "subType": "variable",
            "value": "Museum_2",
            "rdfType": "https://data.mydomain.com/ontologies/sparnatural-config/Museum"  
          },
          // either "values", either "filters", either "predicateObjectPairs"
          // here a predicateObjectPair means we have a WHERE associated to the variable declared above
          "predicateObjectPairs": [
            {
              "type": "predicateObjectPair",
              // here : if we need to switch optional / notExists this will be a "subType"
              // "subType": "optional",
              // "subType": "notExists",
              "predicate": {
                "type": "term",
                "subType": "namedNode",
                "value": "https://data.mydomain.com/ontologies/sparnatural-config/Museum_country"
              },
              "object" : {
                "termType": "objectCriteria",
                "variable": {
                  "type": "term",
                  "subType": "variable",
                  "value": "Country_4",
                  "rdfType": "https://data.mydomain.com/ontologies/sparnatural-config/Country"
                },
                // we would always have "values", and if we have a single value, we set
                // it as the object value instead of a VALUES clause
                // fixed values set by "values" clause instead of "filters"
                "values": [
                  {
                    // something closer to Traqula than to rdfjs here
                    "type": "term",
                    "subType" : "namedNode",
                    "value": "http://dbpedia.org/resource/France",
                    "label": "France"
                  },
                  {
                    "type": "term",
                    "subType" : "labelledIri",
                    "value": "http://dbpedia.org/resource/Italy",
                    "label": "Italy"
                  }
                ]                     
              }                     
            }
          ]
        }
      }
      {
        "type": "predicateObjectPair",
        "predicate": {
          "type": "term",
          "subType": "namedNode",
          "value": "https://data.mydomain.com/ontologies/sparnatural-config/Artwork_author"
        },
        "object" : {
          "type": "objectCriteria",
          "variable": {
            "type": "term",
            "subType": "variable",
            "value": "Person_6",
            "rdfType": "https://data.mydomain.com/ontologies/sparnatural-config/Person"
          },
          "values": [
            {
              "type": "term",
              "subType" : "namedNode",
              "value": "http://dbpedia.org/resource/Leonardo_da_Vinci",
              "label": "Leonardo da Vinci"
            }
          ]
        }
      },
      {
        "type": "predicateObjectPair",
        "predicate": {
          "type": "term",
          "subType": "namedNode",
          "value": "https://data.mydomain.com/ontologies/sparnatural-config/Artwork_creationYear"
        },
        "object" : {
          "termType": "ObjectCriteria",
          "variable": {
            "type": "term",
            "subType": "variable",
            "value": "Date_8",
            "rdfType": "https://data.mydomain.com/ontologies/sparnatural-config/Date"
          },
          // here a LabelledFilter, that is a custom filter with a label
          // note : fixed literal values, like for a Boolean widget, would go in a "values" clause
          "filters": [
            {
              "type": "labelledFilter",
              "label": "between 1800 and 1901",
              "filter": {
                // here we would have different kind of filters depending on the widget
                "type": "numberFilter",
                "min": 1800,
                "max": 1901
              }
            }
          ]
        }
      }
    ]
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions