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

User Story : parameterized queries #592

Open
tfrancart opened this issue May 14, 2024 · 2 comments
Open

User Story : parameterized queries #592

tfrancart opened this issue May 14, 2024 · 2 comments
Labels
kind: Idea for later 💡 Maybe one day... what: JSON query JSON query format loading and saving

Comments

@tfrancart
Copy link
Contributor

tfrancart commented May 14, 2024

The goal is to create query templates, and indicate which variables in this query template could be choosed by a user. Then users can be proposed with very simple forms containing only these variables to select, without having to redesign the entire query.
This opens the possibility to offer multiple simple forms to end-users, using the same value selection widgets as in Sparnatural.

The story is the following:

  1. An administrator creates a Sparnatural query and store it somewhere, probably on a server (see User Story : query history #591). For example "All museums that are located in Any Country, with photo and geo coordinates"
  2. The administrator associates it with "variable bindings" to mark the variables that can be assigned by a user. For example the variable "Museum_2" in our example
  3. This parameterized query is saved somewhere, with a name a description. For example "List museums in a country".
  4. An end-user can select this parameterized query. He is presented with a very simple form containing only one field : "Country".
  5. The end-user selects a Country in the same widget as the original widget in Sparnatural
  6. He runs the query, and gets a list of musuem with photo and geo coordinates.

VocBench actually has this functionnality:

  1. Store query:

image

  1. Create variable binding:

image

  1. Store parametrized query

image

  1. End-user loads the query:

image

  1. End-user is presented with a simple form with only the variable binding to enter:

image

end-user selects a value:

image

  1. End-user runs the query:

image

@antoine37120

@tfrancart tfrancart added kind: Idea for later 💡 Maybe one day... what: JSON query JSON query format loading and saving labels May 14, 2024
@tfrancart
Copy link
Contributor Author

Metaphacts also have something like this when saving queries:

image

@tfrancart
Copy link
Contributor Author

tfrancart commented Jul 3, 2024

I. A new webcomponent

<spar-natural-form
	src="config.ttl"
	query="query.json"
	form="form.json"
/>

II. The form configuration file

form.json :

{
	"bindings": [
		{
			"variable" : "Country_4",
			"node" : {
				"type" : "UserPrompt",
				"name" : {
					"en" : "Country",
					"fr" : "Pays"
				}
			}
		},
		{
			"variable" : "Person_10",
			"node" : {
				"type" : "UserPrompt",
				"name" : {
					"en" : "Author",
					"fr" : "Auteur"
				}
			}
		}
	]	
}

III. The query json file (saved from Sparnatural)

image

query.json:

{
  "distinct": true,
  "variables": [
    {
      "termType": "Variable",
      "value": "Artwork_1"
    },
    {
      "termType": "Variable",
      "value": "Country_4"
    },
    {
      "termType": "Variable",
      "value": "Image_6"
    }
  ],
  "order": null,
  "branches": [
    {
      "line": {
        "s": "Artwork_1",
        "p": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#displayedAt",
        "o": "Museum_2",
        "sType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Artwork",
        "oType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Museum",
        "values": []
      },
      "children": [
        {
          "line": {
            "s": "Museum_2",
            "p": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#country",
            "o": "Country_4",
            "sType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Museum",
            "oType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Country",
            "values": []
          },
          "children": []
        }
      ]
    },
    {
      "line": {
        "s": "Artwork_1",
        "p": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#thumbnail",
        "o": "Image_6",
        "sType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Artwork",
        "oType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Image",
        "values": []
      },
      "children": [],
      "optional": true
    },
    {
      "line": {
        "s": "Artwork_1",
        "p": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#description",
        "o": "Text_8",
        "sType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Artwork",
        "oType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Text",
        "values": []
      },
      "children": [],
      "optional": true
    },
    {
      "line": {
        "s": "Artwork_1",
        "p": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#author",
        "o": "Person_10",
        "sType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Artwork",
        "oType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Person",
        "values": []
      },
      "children": [],
      "optional": true
    }
  ]
}

IV The generated form

image

IV The final query

Si l'utilisateur saisi seulement le pays mais pas l'auteur, alors:

  • la valeur du pays est injecté dans la requête
  • le critère d'auteur de la requête est supprimé car :
    • il est mis en optional
    • il n'est pas dans les variables sélectionnées de la requête
    • aucune valeur n'a été positionné pour lui

Requête JSON finale:

{
  "distinct": true,
  "variables": [
    {
      "termType": "Variable",
      "value": "Artwork_1"
    },
    {
      "termType": "Variable",
      "value": "Country_4"
    },
    {
      "termType": "Variable",
      "value": "Image_6"
    }
  ],
  "order": null,
  "branches": [
    {
      "line": {
        "s": "Artwork_1",
        "p": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#displayedAt",
        "o": "Museum_2",
        "sType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Artwork",
        "oType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Museum",
        "values": []
      },
      "children": [
        {
          "line": {
            "s": "Museum_2",
            "p": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#country",
            "o": "Country_4",
            "sType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Museum",
            "oType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Country",
            "values": [
            	{
                "label": "France (3987)",
                "rdfTerm": {
                  "type": "uri",
                  "value": "http://fr.dbpedia.org/resource/France"
                }
               }
            ]
          },
          "children": []
        }
      ]
    },
    {
      "line": {
        "s": "Artwork_1",
        "p": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#thumbnail",
        "o": "Image_6",
        "sType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Artwork",
        "oType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Image",
        "values": []
      },
      "children": [],
      "optional": true
    },
    {
      "line": {
        "s": "Artwork_1",
        "p": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#description",
        "o": "Text_8",
        "sType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Artwork",
        "oType": "http://ontologies.sparna.fr/sparnatural-demo-dbpedia#Text",
        "values": []
      },
      "children": [],
      "optional": true
    }
  ]
}

V We could use other inputs than user forms

Par exemple pour positionner une variable à la date du jour, ou par un bout de script:

{
	"bindings": [
		{
			"variable" : "Country_1",
			"node" : {
				"type" : "UserPrompt",
				"name" : {
					"en" : "Select a country",
					"fr" : "Sélectionner un pays"
				}
			}
		},
		{
			"variable" : "Date_2",
			"node" : {
				"type" : "DynamicValueProvider",
				"valueProvider" : "TypescriptClassNameOfTheValueProvider"
			}
		}
	]	
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: Idea for later 💡 Maybe one day... what: JSON query JSON query format loading and saving
Projects
None yet
Development

No branches or pull requests

1 participant