Search in sources :

Example 1 with HOGMCodeArea

use of com.sri.ai.praise.other.application.praise.app.editor.HOGMCodeArea in project aic-praise by aic-sri-international.

the class QueryController method createParsedModelView.

private HOGMCodeArea createParsedModelView(HOGModel parseModel) {
    HOGMCodeArea result = new HOGMCodeArea();
    StringJoiner sj = new StringJoiner("\n");
    if (parseModel == null) {
        sj.add("// UNABLE TO PARSE");
    } else {
        sj.add("// SORT DECLARATIONS:");
        parseModel.getSortDeclarations().forEach(sd -> {
            sj.add(sd.getSortDeclaration().toString() + ";");
        });
        if (parseModel.getConstatDeclarations().size() > 0) {
            sj.add("// CONSTANT DECLARATIONS:");
            parseModel.getConstatDeclarations().forEach(cd -> {
                sj.add(cd.getConstantDeclaration().toString() + ";");
            });
        }
        sj.add("// RANDOM VARIABLE DECLARATIONS:");
        parseModel.getRandomVariableDeclarations().forEach(rd -> {
            sj.add(rd.getRandomVariableDeclaration().toString() + ";");
        });
        sj.add("// CONDITIONED POTENTIALS:");
        parseModel.getConditionedPotentials().forEach(cp -> {
            sj.add(cp.toString() + ";");
        });
    }
    result.setText(sj.toString());
    result.setEditable(false);
    return result;
}
Also used : HOGMCodeArea(com.sri.ai.praise.other.application.praise.app.editor.HOGMCodeArea) StringJoiner(java.util.StringJoiner)

Example 2 with HOGMCodeArea

use of com.sri.ai.praise.other.application.praise.app.editor.HOGMCodeArea in project aic-praise by aic-sri-international.

the class QueryController method displayQueryAnswer.

private void displayQueryAnswer(String query, Expression result, HOGModel parsedModel, long millisecondsToCompute) {
    String answer = "P(" + query + " | ... ) = " + result;
    String timeTaken = Util.toHoursMinutesAndSecondsString(millisecondsToCompute);
    String title = "Query took " + timeTaken + " to compute '" + answer + "'";
    HOGMCodeArea resultCodeArea = new HOGMCodeArea(false);
    resultCodeArea.setText(answer);
    resultCodeArea.setEditable(false);
    Node resultContent = null;
    if (PRAiSEController.isInDebugMode()) {
        HOGMCodeArea parsedModelArea = createParsedModelView(parsedModel);
        TabPane resultTabs = new TabPane();
        resultTabs.getTabs().add(new Tab("Answer", resultCodeArea));
        resultTabs.getTabs().add(new Tab("Parsed As", parsedModelArea));
        resultContent = resultTabs;
    } else {
        resultContent = resultCodeArea;
    }
    TitledPane resultPane = new TitledPane(title, resultContent);
    FXUtil.setTitledPaneIcon(resultPane, FontAwesomeIcons.CHECK);
    showResultPane(resultPane);
}
Also used : TitledPane(javafx.scene.control.TitledPane) TabPane(javafx.scene.control.TabPane) HOGMCodeArea(com.sri.ai.praise.other.application.praise.app.editor.HOGMCodeArea) Tab(javafx.scene.control.Tab) Node(javafx.scene.Node)

Example 3 with HOGMCodeArea

use of com.sri.ai.praise.other.application.praise.app.editor.HOGMCodeArea in project aic-praise by aic-sri-international.

the class QueryController method displayQueryErrors.

private void displayQueryErrors(String query, List<HOGMProblemError> queryErrors, HOGModel parsedModel, long millisecondsToCompute) {
    String title = "Query '" + query + "' encountered " + queryErrors.size() + " error(s) when attempting to compute answer (took " + Util.toHoursMinutesAndSecondsString(millisecondsToCompute) + ")";
    ListView<HOGMProblemError> errors = new ListView<>(FXCollections.observableList(queryErrors));
    // errors.setFixedCellSize(24);
    errors.setPrefHeight(24 * 5);
    errors.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    errors.getSelectionModel().selectedIndexProperty().addListener((obs, oldValue, newValue) -> {
        if (newValue.intValue() >= 0) {
            HOGMProblemError qError = errors.getItems().get(newValue.intValue());
            if (qError.getContext() == HOGMProblemError.Scope.MODEL) {
                modelPageEditor.highlight(qError.getStartContextIndex(), qError.getEndContextIndex());
            } else if (qError.getContext() == HOGMProblemError.Scope.QUERY) {
                queryComboBox.getEditor().selectAll();
            }
        }
    });
    Node resultContent = null;
    if (PRAiSEController.isInDebugMode()) {
        HOGMCodeArea parsedModelArea = createParsedModelView(parsedModel);
        TabPane resultTabs = new TabPane();
        resultTabs.getTabs().add(new Tab("Errors", errors));
        resultTabs.getTabs().add(new Tab("Parsed As", parsedModelArea));
        resultContent = resultTabs;
    } else {
        resultContent = errors;
    }
    TitledPane resultPane = new TitledPane(title, resultContent);
    FXUtil.setTitledPaneIcon(resultPane, FontAwesomeIcons.TIMES);
    showResultPane(resultPane);
    errors.getSelectionModel().selectFirst();
}
Also used : TitledPane(javafx.scene.control.TitledPane) TabPane(javafx.scene.control.TabPane) HOGMProblemError(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError) ListView(javafx.scene.control.ListView) HOGMCodeArea(com.sri.ai.praise.other.application.praise.app.editor.HOGMCodeArea) Tab(javafx.scene.control.Tab) Node(javafx.scene.Node)

Aggregations

HOGMCodeArea (com.sri.ai.praise.other.application.praise.app.editor.HOGMCodeArea)3 Node (javafx.scene.Node)2 Tab (javafx.scene.control.Tab)2 TabPane (javafx.scene.control.TabPane)2 TitledPane (javafx.scene.control.TitledPane)2 HOGMProblemError (com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError)1 StringJoiner (java.util.StringJoiner)1 ListView (javafx.scene.control.ListView)1