| component-id | type | name | description | work-package | project | resource | demo | release-date | release-number | release-link | doi | changelog | licence | contributors | related-components | bibliography | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
melody-software |
WebApplication |
MELODY |
MELODY is a dashboarding system for designing and publishing data stories based on Linked Open Data. |
|
polifonia-project |
2022/05/12 |
v0.1.1 |
10.5281/zenodo.6637345 |
|
|
|
|
MELODY - Make mE a Linked Open Data StorY is a dashboarding system that allows users familiar with Linked Open Data to create web-ready data stories.
- Authenticate with GitHub to create a new story.
- Access data from any SPARQL endpoint.
- Select the layout template of your story.
- Include charts, sections, filters, and descriptions.
- Preview the final data story while creating it.
- Embed or export your data story and single charts in several formats.
See the full documentation at https://polifonia-project.github.io/dashboard/.
MELODY exposes a lightweight HTTP API that returns either a simple text response or a full "data story" payload rendered by a template. It is useful for quickly embedding a single text block, a small visualization, or a complete story in external applications.
GET /melody/api
POST /melody/api
- Run a SPARQL query and inject values into a text template.
- Return text, JSON, or HTML depending on your integration needs.
- Provide a full "complex" configuration to build multi-block responses (text + charts) and optionally supply your own CSS/JS.
-
Simple request (no
config_file)format=html: returns the filled text astext/html(no wrapper template).- Any other value (or no
format): returns plain text astext/plain.
-
Complex request (
config_fileprovided)format=json: returns JSON (the full payload).format=text: returns the joined text blocks astext/plain.- Default (
format=htmlor omitted): returns HTML rendered byapi_template.html.
Required:
sparql_endpoint: SPARQL endpoint URL.query: SPARQL query string (may include placeholders like<<<uri1>>>).content: template with placeholders (plain text or one or more HTML elements, e.g.,Label: <<<label>>>or<h3>Label: <<<label>>></h3>).- One or more placeholder values (e.g.,
uri1=http://example.org/item/1).
Optional:
format:html|text(default istextfor simple requests).
Required:
config_file: a JSON string or URL to a JSON configuration.
Optional:
format:html|json|text(default ishtmlfor complex requests).- Any placeholder values referenced in the config (e.g.,
uri1=...).
Note: format and placeholder values are passed as request parameters (outside
the config_file JSON).
The config_file JSON can define:
contentblocks (text and/or data_viz)style(optional CSS URL)script(optional JS URL)
A complex config is a JSON object with a top-level content map. Each entry is
a block with:
type:textordata_vizsparql_endpoint: SPARQL endpoint URLquery: SPARQL query (can include placeholders like<<<uri1>>>)content: for text blocks, a template (plain text or HTML)viz_typeandencodings: for data visualization blocks
A full, real-world example is provided in:
documentation/api_complex_example.json
Shortened example (first two blocks only):
{
"content": {
"01": {
"type": "text",
"sparql_endpoint": "http://localhost:3030/chad-kg/sparql",
"query": "SELECT ?label WHERE { <<<uri1>>> rdfs:label ?label } LIMIT 1",
"content": "<h1><<<label>>></h1>"
},
"02": {
"type": "text",
"sparql_endpoint": "http://localhost:3030/chad-kg/sparql",
"query": "SELECT ?item ?label WHERE { VALUES ?item {<<<uri1>>>} ?item rdfs:label ?label }",
"content": "<p>Label: <<<label>>></p>"
}
}
}Data visualization block example:
{
"content": {
"timeline1": {
"type": "data_viz",
"viz_type": "timeline",
"sparql_endpoint": "http://localhost:3030/chad-kg/sparql",
"query": "SELECT ?item ?begin ?end WHERE { ?item <http://www.cidoc-crm.org/cidoc-crm/P4_has_time-span> ?ts . ?ts <http://www.cidoc-crm.org/cidoc-crm/P82a_begin_of_the_begin> ?begin ; <http://www.cidoc-crm.org/cidoc-crm/P82b_end_of_the_end> ?end . }",
"encodings": {
"item": "item",
"begin": "begin",
"end": "end",
"colors": [
"#A62176"
]
}
}
}
}To call the API, pass format and placeholder values outside the config:
curl -G "http://127.0.0.1:5000/melody/api" \
--data-urlencode "format=json" \
--data-urlencode "config_file={...}" \
--data-urlencode "uri1=http://example.org/item/1"Simple request (plain text)
curl -G "http://127.0.0.1:5000/melody/api" \
--data-urlencode "sparql_endpoint=http://localhost:3030/chad-kg/sparql" \
--data-urlencode "query=SELECT ?label WHERE { <<<uri1>>> rdfs:label ?label } LIMIT 1" \
--data-urlencode "content=Label: <<<label>>>" \
--data-urlencode "uri1=http://example.org/item/1"Simple request (HTML response)
curl -G "http://127.0.0.1:5000/melody/api" \
--data-urlencode "format=html" \
--data-urlencode "sparql_endpoint=http://localhost:3030/chad-kg/sparql" \
--data-urlencode "query=SELECT ?label WHERE { <<<uri1>>> rdfs:label ?label } LIMIT 1" \
--data-urlencode "content=<h3>Label: <<<label>>></h3>" \
--data-urlencode "uri1=http://example.org/item/1"Complex request (HTML by default, custom style/script)
curl -G "http://127.0.0.1:5000/melody/api" \
--data-urlencode "config_file={\"style\":\"https://example.org/app.css\",\"script\":\"https://example.org/app.js\",\"content\":{\"block1\":{\"type\":\"text\",\"sparql_endpoint\":\"http://localhost:3030/chad-kg/sparql\",\"query\":\"SELECT ?label WHERE { <<<uri1>>> rdfs:label ?label } LIMIT 1\",\"content\":\"<h2>Label: <<<label>>></h2>\"}}}" \
--data-urlencode "uri1=http://example.org/item/1"Complex request (JSON)
curl -G "http://127.0.0.1:5000/melody/api" \
--data-urlencode "format=json" \
--data-urlencode "config_file={\"content\":{\"block1\":{\"type\":\"text\",\"sparql_endpoint\":\"http://localhost:3030/chad-kg/sparql\",\"query\":\"SELECT ?label WHERE { <<<uri1>>> rdfs:label ?label } LIMIT 1\",\"content\":\"Label: <<<label>>>\"}}}" \
--data-urlencode "uri1=http://example.org/item/1"Embed in a webpage (iframe)
<iframe
src="http://127.0.0.1:5000/melody/api?format=html&sparql_endpoint=http%3A%2F%2Flocalhost%3A3030%2Fchad-kg%2Fsparql&query=SELECT%20%3Flabel%20WHERE%20%7B%20%3C%3C%3Curi1%3E%3E%3E%20rdfs%3Alabel%20%3Flabel%20%7D%20LIMIT%201&content=%3Ch3%3ELabel%3A%20%3C%3C%3Clabel%3E%3E%3E%3C%2Fh3%3E&uri1=http%3A%2F%2Fexample.org%2Fitem%2F1"
width="100%"
height="300"
style="border:0;">
</iframe>Embed from another app (fetch + custom rendering)
const params = new URLSearchParams({
format: "json",
config_file: JSON.stringify({
style: "https://example.org/app.css",
script: "https://example.org/app.js",
content: {
block1: {
type: "text",
sparql_endpoint: "http://localhost:3030/chad-kg/sparql",
query: "SELECT ?label WHERE { <<<uri1>>> rdfs:label ?label } LIMIT 1",
content: "<h2>Label: <<<label>>></h2>"
}
}
}),
uri1: "http://example.org/item/1"
});
fetch(`/melody/api?${params.toString()}`)
.then(r => r.json())
.then(console.log);Step #1 - Get the source code
- Download the ZIP
- Use GIT tool in the terminal/powershel/bash to clone the source code
Step #2 - Set up the environment
- Python3 should be installed properly in the workstation. If you are not sure if Python is properly installed, please open a terminal and type python --version.
- Enter the project folder using the terminal/powershel/bash.
- Install modules using a Virtual Environment
#MacOS/Linux
$ cd myproject
$ python3 -m venv venv
$ . venv/bin/activate
#Windows
> cd myproject
> py -3 -m venv venv
> venv\Scripts\activateStep #3 - Install requirements
pip install -r requirements.txt
Step #4 - Run the application
#bash
$ export FLASK_APP=app
$ flask run
* Running on http://127.0.0.1:5000/
#CMD
> set FLASK_APP=app
> flask run
* Running on http://127.0.0.1:5000/
#Powershell
> $env:FLASK_APP = "app"
> flask run
* Running on http://127.0.0.1:5000/MELODY is part of Polifonia H2020 project (described in Deliverable 1.9). Cite this repository as follows:
Renda Giulia, and Marilena Daquino. (2022). MELODY: Beta release (v0.1.1). DOI: 10.5281/zenodo.6637346