-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add insert panel component with relations data from OML model
Signed-off-by: Alex <[email protected]>
- Loading branch information
Showing
7 changed files
with
127 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
controller/src/sparql/data-manager/getAllElementRelations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as vscode from "vscode"; | ||
import { TablePanel } from "../../panels/TablePanel"; | ||
import { Commands } from "../../../../commands/src/commands"; | ||
import { SparqlClient } from "../SparqlClient"; | ||
import { getAllRelations } from "../queries/getAllRelations"; | ||
|
||
/** | ||
* This SPARQL query gets all distinct relations from a given OML model and sends them through a controller command. | ||
* | ||
* @remarks | ||
* For more information on OML relations please refer to the official documentation found {@link http://www.opencaesar.io/oml/#Relations | here} | ||
* | ||
* For more information on the postMessage controller command please refer to the official documentation found {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage | here} | ||
* | ||
* @returns | ||
* | ||
*/ | ||
export const getAllElementRelations = async ( | ||
webviewPath: string | ||
): Promise<void> => { | ||
try { | ||
const relations_query = getAllRelations(); | ||
const relations_data = await SparqlClient(relations_query, "query"); | ||
|
||
// Get all relation values | ||
const relations: string[] = relations_data.map( | ||
(relation: Record<string, string>) => { | ||
// We only want values because the record will look like verb: relation_value | ||
// We're only grabbing the verb from the key value pair | ||
// If the relation.verb is not undefined then return it else return a blank string | ||
return relation.verb.split('/').pop() ?? ""; | ||
} | ||
); | ||
|
||
// Send data to current webview | ||
TablePanel.currentPanels.get(webviewPath)?.sendMessage({ | ||
command: Commands.LOADED_ALL_ELEMENT_RELATIONS, | ||
payload: { | ||
relations: relations, | ||
}, | ||
}); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
vscode.window.showErrorMessage(`Error: ${error.message}`); | ||
TablePanel.currentPanels.get(webviewPath)?.sendMessage({ | ||
command: Commands.LOADED_ALL_ELEMENT_RELATIONS, | ||
payload: {}, | ||
errorMessage: `Error: ${error.message}`, | ||
}); | ||
} else { | ||
vscode.window.showErrorMessage(`An unknown error occurred: ${error}`); | ||
TablePanel.currentPanels.get(webviewPath)?.sendMessage({ | ||
command: Commands.LOADED_ALL_ELEMENT_RELATIONS, | ||
payload: {}, | ||
errorMessage: `An unknown error occurred: ${error}`, | ||
}); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* This SPARQL query gets all relations from a given OML model | ||
* | ||
* @remarks | ||
* For more information on OML relations please refer to the official documentation found {@link http://www.opencaesar.io/oml/#Relations | here} | ||
* | ||
* For more information on SPARQL query `regex` and `str` please refer to the official documentation found {@link https://www.w3.org/TR/sparql11-query/ | here} | ||
* | ||
* @returns SPARQL select query string | ||
* | ||
*/ | ||
|
||
export function getAllRelations(): string { | ||
return `SELECT DISTINCT ?verb | ||
WHERE { | ||
?subject ?verb ?object . | ||
FILTER regex(str(?subject), "description", "i") | ||
FILTER regex(str(?verb), "vocabulary", "i") | ||
} | ||
ORDER BY ?verb`; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters