File size: 1,791 Bytes
437883c
 
 
 
49dd4ec
437883c
 
 
 
 
 
 
 
 
 
 
 
 
3ba89e1
437883c
3ba89e1
 
 
 
437883c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import streamlit as st

import jnius_config
if not jnius_config.vm_running:
    jnius_config.set_classpath("./CognitiveReasonerLite.jar")
from jnius import autoclass                 # For running Java. See https://pyjnius.readthedocs.io/en/latest/ for documentation.


CRL_PACKAGE = "com.optum.cogtech.crl."

def make_agent(config_name="agent_demo"):
    # Start the CRL engine
    st.session_state["agent"] = st.session_state.Java_Agent()
    # Configure the decision making
    decConfig = st.session_state.Java_DecisionConfig(config_name)
    decConfig.selectAll()
    st.session_state.agent.addSettings(decConfig)
    # Configure debug printing
    st.session_state.agent.logger.disable()
    st.session_state.agent.logger.setWriteToFile(False)
    # st.session_state.agent.logger.setEnableLogCycles(True)
    # st.session_state.agent.logger.setEnableLogContexts(True)
    # st.session_state.agent.logger.setEnableLogOperators(True)
    # st.session_state.agent.logger.setEnableLogActivation(True)
    return decConfig

def init():
    # Define the Java<->Python interface needed to run the CRL jar
    st.session_state["Java_ArrayList"] = autoclass('java.util.ArrayList')
    st.session_state["Java_Agent"] = autoclass(CRL_PACKAGE+"Agent")
    st.session_state["Java_DecisionConfig"] = autoclass(CRL_PACKAGE+"DecisionConfig")
    st.session_state["Java_Concept"] = autoclass(CRL_PACKAGE+"Concept")
    st.session_state["Java_ActionReportActiveConcept"] = autoclass(CRL_PACKAGE+"ActionReportActiveConcept")

    make_agent()

def ReportActiveConceptActionInList(outputAttribute, attributeForReportValue):
    collection = st.session_state.Java_ArrayList()
    collection.add(st.session_state.Java_ActionReportActiveConcept(outputAttribute, attributeForReportValue))
    return collection