-
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 instance data from OML model
Signed-off-by: Alex <[email protected]>
- Loading branch information
Showing
11 changed files
with
214 additions
and
91 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
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
57 changes: 57 additions & 0 deletions
57
controller/src/sparql/data-manager/getAllInstanceCategories.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,57 @@ | ||
import * as vscode from "vscode"; | ||
import { TablePanel } from "../../panels/TablePanel"; | ||
import { Commands } from "../../../../commands/src/commands"; | ||
import { SparqlClient } from "../SparqlClient"; | ||
import { getAllInstances } from "../queries/getAllInstances"; | ||
|
||
/** | ||
* This SPARQL query gets all distinct instances from a given OML model and sends them through a controller command. | ||
* | ||
* @remarks | ||
* For more information on OML instances please refer to the official documentation found {@link http://www.opencaesar.io/oml/#Instances-LR | 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 getAllInstanceCategories = async ( | ||
webviewPath: string | ||
): Promise<void> => { | ||
try { | ||
const instance_query = getAllInstances(); | ||
const instance_data = await SparqlClient(instance_query, "query"); | ||
// Get all instance values | ||
const instances: string[] = instance_data.map( | ||
(instance: Record<string, string>) => { | ||
// We only want values because the record will look like verb: instance_value | ||
// We're only grabbing the verb from the key value pair | ||
// If the instance.verb is not undefined then return it else return a blank string | ||
return instance.subject.split("/").pop() ?? ""; | ||
} | ||
); | ||
// Send data to current webview | ||
TablePanel.currentPanels.get(webviewPath)?.sendMessage({ | ||
command: Commands.LOADED_ALL_INSTANCE_CATEGORIES, | ||
payload: { | ||
instances: instances, | ||
}, | ||
}); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
vscode.window.showErrorMessage(`Error: ${error.message}`); | ||
TablePanel.currentPanels.get(webviewPath)?.sendMessage({ | ||
command: Commands.LOADED_ALL_INSTANCE_CATEGORIES, | ||
payload: {}, | ||
errorMessage: `Error: ${error.message}`, | ||
}); | ||
} else { | ||
vscode.window.showErrorMessage(`An unknown error occurred: ${error}`); | ||
TablePanel.currentPanels.get(webviewPath)?.sendMessage({ | ||
command: Commands.LOADED_ALL_INSTANCE_CATEGORIES, | ||
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,21 @@ | ||
/** | ||
* This SPARQL query gets all distinct instances from a given OML model | ||
* | ||
* @remarks | ||
* For more information on OML instances please refer to the official documentation found {@link http://www.opencaesar.io/oml/#Instances-LR | 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 getAllInstances(): string { | ||
return `SELECT DISTINCT ?subject | ||
WHERE { | ||
?subject ?verb ?object . | ||
FILTER regex(str(?subject), "vocabulary", "i") | ||
FILTER regex(str(?object), "Concept", "i") | ||
} | ||
ORDER BY ?subject`; | ||
} |
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
Oops, something went wrong.