Search in sources :

Example 1 with UAI_to_HOGMv1_Using_Equalities_Translator

use of com.sri.ai.praise.core.representation.translation.ciaranframework.core.uai.UAI_to_HOGMv1_Using_Equalities_Translator in project aic-praise by aic-sri-international.

the class PRAiSEController method importUAIModel.

private void importUAIModel(ActionEvent ae) {
    File uaiModelFile = uaiFileChooser.showOpenDialog(mainStage);
    if (uaiModelFile != null) {
        File uaiEvidenceFile = new File(uaiModelFile.getParent(), uaiModelFile.getName() + ".evid");
        StringWriter hogmWriter = new StringWriter();
        try (BufferedReader uaiModelReader = new BufferedReader(new FileReader(uaiModelFile));
            BufferedReader uaiEvidenceReader = new BufferedReader(new FileReader(uaiEvidenceFile));
            PrintWriter hogmPrintWriter = new PrintWriter(hogmWriter)) {
            UAI_to_HOGMv1_Using_Equalities_Translator translator = new UAI_to_HOGMv1_Using_Equalities_Translator();
            translator.translate(uaiModelFile.getName(), new Reader[] { uaiModelReader, uaiEvidenceReader }, new PrintWriter[] { hogmPrintWriter }, new TranslatorOptions());
            String hogmModel = hogmWriter.toString();
            // For convenience, pull out all possible queries
            HOGMParserWrapper parser = new HOGMParserWrapper();
            HOGModel parsedModel = parser.parseModel(hogmModel);
            ExpressionBasedModel factorsAndTypes = new HOGMExpressionBasedModel(parsedModel);
            List<String> queries = new ArrayList<>(factorsAndTypes.getMapFromRandomVariableNameToTypeName().keySet());
            newModel(hogmModel, queries);
        } catch (Throwable th) {
            FXUtil.exception(th);
        }
    }
}
Also used : HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel) ExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedModel) ArrayList(java.util.ArrayList) TranslatorOptions(com.sri.ai.praise.core.representation.translation.ciaranframework.api.TranslatorOptions) HOGMParserWrapper(com.sri.ai.praise.core.representation.classbased.hogm.parsing.HOGMParserWrapper) HOGModel(com.sri.ai.praise.core.representation.classbased.hogm.HOGModel) StringWriter(java.io.StringWriter) BufferedReader(java.io.BufferedReader) HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel) FileReader(java.io.FileReader) File(java.io.File) PrintWriter(java.io.PrintWriter) UAI_to_HOGMv1_Using_Equalities_Translator(com.sri.ai.praise.core.representation.translation.ciaranframework.core.uai.UAI_to_HOGMv1_Using_Equalities_Translator)

Aggregations

ExpressionBasedModel (com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedModel)1 HOGModel (com.sri.ai.praise.core.representation.classbased.hogm.HOGModel)1 HOGMExpressionBasedModel (com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel)1 HOGMParserWrapper (com.sri.ai.praise.core.representation.classbased.hogm.parsing.HOGMParserWrapper)1 TranslatorOptions (com.sri.ai.praise.core.representation.translation.ciaranframework.api.TranslatorOptions)1 UAI_to_HOGMv1_Using_Equalities_Translator (com.sri.ai.praise.core.representation.translation.ciaranframework.core.uai.UAI_to_HOGMv1_Using_Equalities_Translator)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1