Skip to content

Commit

Permalink
add insert panel component with instance data from OML model
Browse files Browse the repository at this point in the history
Signed-off-by: Alex <[email protected]>
  • Loading branch information
aematei committed Jun 5, 2024
1 parent 5b02395 commit 44a6052
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 91 deletions.
92 changes: 51 additions & 41 deletions commands/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ export enum Commands {
INFORM = "inform",

// Table Panel Commands
CREATE_TABLE = 'createTable',
ROW_CLICKED = 'rowClicked',
HIDE_PROPERTIES = 'hideProperties',
ASK_FOR_VIEWPOINTS = 'askForViewpoints',
ASK_FOR_COMMANDS = 'askForCommands',
GENERATE_TABLE_DATA = 'generateTableData',
UPDATE_CM_STATE = 'updateCmState',
REFRESH_TABLE_DATA = 'refreshTableData',
GET_ELEMENT_RELATIONS = 'getElementRelations',
CREATE_TABLE = "createTable",
ROW_CLICKED = "rowClicked",
HIDE_PROPERTIES = "hideProperties",
ASK_FOR_VIEWPOINTS = "askForViewpoints",
ASK_FOR_COMMANDS = "askForCommands",
GENERATE_TABLE_DATA = "generateTableData",
UPDATE_CM_STATE = "updateCmState",
REFRESH_TABLE_DATA = "refreshTableData",
GET_ELEMENT_RELATIONS = "getElementRelations",
// This differs to the GET_ELEMENT_RELATIONS because it grabs the predicate/verb and object instead of the subject of the selected element
GET_ELEMENT_RELATIONS_TOTAL = 'getElementRelationsTotal',
GET_ELEMENT_RELATIONS_TOTAL = "getElementRelationsTotal",
// This differs from GET_ELEMENT_RELANTIONS_TOTAL because it gets all relations in OML Model not just a selected element
GET_ALL_ELEMENT_RELATIONS = 'getAllElementRelations',
EXECUTE_CREATE_ELEMENTS = 'executeCreateElements',
EXECUTE_DELETE_ELEMENTS = 'executeDeleteElements',
CREATE_FCR = 'createFCR',
GET_ALL_ELEMENT_RELATIONS = "getAllElementRelations",
GET_ALL_INSTANCE_CATEGORIES = "getAllInstanceCategories",
EXECUTE_CREATE_ELEMENTS = "executeCreateElements",
EXECUTE_DELETE_ELEMENTS = "executeDeleteElements",
CREATE_FCR = "createFCR",

// Property Panel Commands
ASK_FOR_PROPERTIES = "askForProperties",
Expand All @@ -41,29 +42,29 @@ export enum Commands {
PING_TRIPLESTORE_TASK = "pingTriplestoreTask",

// Extension To Table Panel Commands
UPDATE_LOCAL_VALUE = 'updateLocalValue',
SEND_VIEWPOINTS = 'sendViewpoints',
SEND_COMMANDS = 'sendCommands',
OPEN_WIZARD = 'openWizard',
CREATE_FILTERED_DIAGRAM = 'createFilteredDiagram',
LOADED_PROPERTY_SHEET = 'loadedPropertySheet',
LOADED_TABLE_DATA = 'loadedTableData',
LOADED_ELEMENT_RELATIONS = 'loadedElementRelations',
UPDATE_LOCAL_VALUE = "updateLocalValue",
SEND_VIEWPOINTS = "sendViewpoints",
SEND_COMMANDS = "sendCommands",
OPEN_WIZARD = "openWizard",
CREATE_FILTERED_DIAGRAM = "createFilteredDiagram",
LOADED_PROPERTY_SHEET = "loadedPropertySheet",
LOADED_TABLE_DATA = "loadedTableData",
LOADED_ELEMENT_RELATIONS = "loadedElementRelations",
// This differs to the LOADED_ELEMENT_RELATIONS because it loads the predicate/verb and object instead of the subject of the selected element
LOADED_ELEMENT_RELATIONS_TOTAL = 'loadedElementRelationsTotal',
LOADED_ELEMENT_RELATIONS_TOTAL = "loadedElementRelationsTotal",
// This differs from LOADED_ELEMENT_RELATIONS_TOTAL because it loads all relations in OML Model not just a selected element
LOADED_ALL_ELEMENT_RELATIONS = 'loadedAllElementRelations',
DELETED_ELEMENTS = 'deletedElements',
CREATED_ELEMENT = 'createdElement',
CLONED_ELEMENTS = 'clonedElements',
SHOW_PROPERTIES = 'showProperties',
LOADED_ALL_ELEMENT_RELATIONS = "loadedAllElementRelations",
LOADED_ALL_INSTANCE_CATEGORIES = "loadedAllInstanceCategories",
DELETED_ELEMENTS = "deletedElements",
CREATED_ELEMENT = "createdElement",
CLONED_ELEMENTS = "clonedElements",
SHOW_PROPERTIES = "showProperties",

// Context Menu to Triplestore. All crud commands
CREATE_QUERY = 'createQuery',
READ_QUERY = 'readQuery',
UPDATE_QUERY = 'updateQuery',
DELETE_QUERY = 'deleteQuery',

CREATE_QUERY = "createQuery",
READ_QUERY = "readQuery",
UPDATE_QUERY = "updateQuery",
DELETE_QUERY = "deleteQuery",
}

export type CommandStructures = {
Expand Down Expand Up @@ -101,6 +102,9 @@ export type CommandStructures = {
[Commands.GET_ALL_ELEMENT_RELATIONS]: {
payload: { webviewPath: string };
};
[Commands.GET_ALL_INSTANCE_CATEGORIES]: {
payload: { webviewPath: string };
};
[Commands.EXECUTE_DELETE_ELEMENTS]: {
payload: { webviewPath: string; IRIsToDelete: ITableData[] };
wizardId?: string;
Expand Down Expand Up @@ -147,10 +151,10 @@ export type CommandStructures = {
};
[Commands.UPDATE_LOCAL_VALUE]: {};
[Commands.SEND_VIEWPOINTS]: {
payload: { [filename: string]: Record<string, string> | any[] }
payload: { [filename: string]: Record<string, string> | any[] };
};
[Commands.SEND_COMMANDS]: {
payload: { [filename: string]: Record<string, string> | any[] }
payload: { [filename: string]: Record<string, string> | any[] };
};
[Commands.OPEN_WIZARD]: {
payload: {
Expand Down Expand Up @@ -193,6 +197,12 @@ export type CommandStructures = {
relations?: string[];
};
};
[Commands.LOADED_ALL_INSTANCE_CATEGORIES]: {
errorMessage?: string;
payload: {
instances?: string[];
};
};
[Commands.DELETED_ELEMENTS]: {
errorMessage?: string;
wizardId: string;
Expand All @@ -218,21 +228,21 @@ export type CommandStructures = {
};
[Commands.CREATE_QUERY]: {
query: string;
selectedElements?: string[]
selectedElements?: string[];
};
[Commands.READ_QUERY]: {
query: string;
selectedElements?: string[]
selectedElements?: string[];
};
[Commands.UPDATE_QUERY]: {
query: string;
selectedElements?: string[]
before_parameters?: Object
after_parameters?: Object
selectedElements?: string[];
before_parameters?: Object;
after_parameters?: Object;
};
[Commands.DELETE_QUERY]: {
query: string;
selectedElements?: string[]
selectedElements?: string[];
};
};

Expand Down
26 changes: 18 additions & 8 deletions commands/src/tablePanelMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getElementRelations } from "../../controller/src/sparql/data-manager/ge
import { executeDeleteElements } from "../../controller/src/sparql/data-manager/executeDeleteElements";
import { getElementRelationsTotal } from "../../controller/src/sparql/data-manager/getElementRelationsTotal";
import { getAllElementRelations } from "../../controller/src/sparql/data-manager/getAllElementRelations";
import { getAllInstanceCategories } from "../../controller/src/sparql/data-manager/getAllInstanceCategories";

/**
* Handles commands that are sent to a Editor (Table, Tree, or Diagram)
Expand Down Expand Up @@ -102,7 +103,7 @@ export function handleTablePanelMessage(
specificMessage.payload.labelArray
);
break;

case Commands.GET_ELEMENT_RELATIONS_TOTAL:
specificMessage =
message as CommandStructures[Commands.GET_ELEMENT_RELATIONS_TOTAL];
Expand All @@ -122,21 +123,30 @@ export function handleTablePanelMessage(
const { webviewPath: delWebviewPath, IRIsToDelete = [] } =
specificMessage.payload;

// Refer to the CommandStructures[Commands.EXECUTE_DELETE_ELEMENTS] to see how the parameters are structured
executeDeleteElements(
specificMessage.payload.webviewPath,
specificMessage.wizardId,
specificMessage.payload.IRIsToDelete,
)
// Refer to the CommandStructures[Commands.EXECUTE_DELETE_ELEMENTS] to see how the parameters are structured
executeDeleteElements(
specificMessage.payload.webviewPath,
specificMessage.wizardId,
specificMessage.payload.IRIsToDelete
);
break;

case Commands.GET_ALL_ELEMENT_RELATIONS:
specificMessage = message as CommandStructures[Commands.GET_ALL_ELEMENT_RELATIONS];
specificMessage =
message as CommandStructures[Commands.GET_ALL_ELEMENT_RELATIONS];
const { webviewPath: relationWebviewPath } = specificMessage.payload;

// Refer to the CommandStructures[Commands.GET_ALL_ELEMENT_RELATIONS] to see how the parameters are structured
getAllElementRelations(specificMessage.payload.webviewPath);

case Commands.GET_ALL_INSTANCE_CATEGORIES:
specificMessage =
message as CommandStructures[Commands.GET_ALL_INSTANCE_CATEGORIES];
const { webviewPath: instanceWebviewPath } = specificMessage.payload;

// Refer to the CommandStructures[Commands.GET_ALL_ELEMENT_RELATIONS] to see how the parameters are structured
getAllInstanceCategories(specificMessage.payload.webviewPath);

case Commands.CREATE_FCR:
specificMessage = message as CommandStructures[Commands.CREATE_FCR];
const fcrPayload = specificMessage.payload;
Expand Down
2 changes: 0 additions & 2 deletions controller/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,5 +514,3 @@ export function activate(context: vscode.ExtensionContext) {
function cloneSelectedRows(context: Record<string, any>) {
throw new Error("Function not implemented.");
}


20 changes: 10 additions & 10 deletions controller/src/sparql/data-manager/getAllElementRelations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ import { getAllRelations } from "../queries/getAllRelations";
*
*/
export const getAllElementRelations = async (
webviewPath: string
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() ?? "";
}
(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,
Expand All @@ -56,4 +56,4 @@ export const getAllElementRelations = async (
});
}
}
};
};
57 changes: 57 additions & 0 deletions controller/src/sparql/data-manager/getAllInstanceCategories.ts
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}`,
});
}
}
};
21 changes: 21 additions & 0 deletions controller/src/sparql/queries/getAllInstances.ts
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`;
}
7 changes: 3 additions & 4 deletions controller/src/sparql/queries/getAllRelations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
*
* @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
return `SELECT DISTINCT ?verb
WHERE {
?subject ?verb ?object .
FILTER regex(str(?subject), "description", "i")
FILTER regex(str(?verb), "vocabulary", "i")
}
ORDER BY ?verb`;
}

}
6 changes: 3 additions & 3 deletions controller/src/sparql/queries/getIriRelations.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* This SPARQL query gets all relations for a given IRI which is a owl:NamedIndividual
* This SPARQL query gets all relations for a given IRI which is a owl:NamedIndividual
*
* @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}
*
* @param IRI of the element. To learn more about IRIs go to this {@link https://www.oxfordsemantic.tech/faqs/what-is-an-iri-what-does-iri-mean | doc}
*
*
* @returns SPARQL select query string
*
*/
Expand Down
7 changes: 6 additions & 1 deletion view/src/components/Diagram/Diagram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,12 @@ function Diagram({
</InsertPane>
<InsertPane label="Relation">
{relations.map((relation: string) => {
return <RelationInsertItem label={relation} icon={DefaultRelationIcon}/>;
return (
<RelationInsertItem
label={relation}
icon={DefaultRelationIcon}
/>
);
})}
</InsertPane>
</InsertPanel>
Expand Down
Loading

0 comments on commit 44a6052

Please sign in to comment.