// MetaKBdlg.cpp : implementation file // #include "stdafx.h" #include "kbeditors.h" #include "KBEditorsDoc.h" #include "MetaKBdlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMetaKBdlg dialog CMetaKBdlg::CMetaKBdlg(CWnd* pParent /*=NULL*/) : CDialog(CMetaKBdlg::IDD, pParent) { //{{AFX_DATA_INIT(CMetaKBdlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CMetaKBdlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMetaKBdlg) DDX_Control(pDX, IDC_SelectedInferences, m_SelectedInf); DDX_Control(pDX, IDC_INFERENCES, m_InfList); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMetaKBdlg, CDialog) //{{AFX_MSG_MAP(CMetaKBdlg) ON_BN_CLICKED(IDC_ADDInference, OnADDInference) ON_BN_CLICKED(IDC_DELInference, OnDELInference) ON_BN_CLICKED(ID_GenerateMeta, OnGenerateMeta) ON_BN_CLICKED(ID_GenerateMeta2, OnGenerateMetaByValue) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMetaKBdlg message handlers void CMetaKBdlg::SeeDoc(CKBEditorsDoc*Doc) { m_Doc = Doc; } BOOL CMetaKBdlg::OnInitDialog() { CDialog::OnInitDialog(); CenterWindow(GetDesktopWindow()); POSITION pos1 =m_Doc->m_InferenceList.GetStartPosition(); while (pos1) { CInference * Inference; CString str ; m_Doc->m_InferenceList.GetNextAssoc(pos1,str,Inference); m_InfList.AddString(str); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CMetaKBdlg::OnADDInference() { int Sel = m_InfList.GetCurSel(); if (Sel < 0 ) return; CString str; m_InfList.GetText(Sel,str); m_SelectedInf.AddString(str); m_InfList.DeleteString(Sel); } void CMetaKBdlg::OnDELInference() { int Sel = m_SelectedInf.GetCurSel(); if (Sel < 0 ) return; CString str; m_SelectedInf.GetText(Sel,str); m_InfList.AddString(str); m_SelectedInf.DeleteString(Sel); } void CMetaKBdlg::OnGenerateMeta() { CreateMetaKB(); } void CMetaKBdlg::CreateMetaKB() { CString str,DocName; AfxGetApp()->m_pMainWnd->GetWindowText(str); //str.Find(" Version No.",0); str.Replace(".kb",".xml"); DocName = str; CStdioFile OutFile(str,CFile::modeCreate | CFile::modeWrite ); str = ""; OutFile.WriteString(str); //Inference for (int i=0;im_InferenceList.Lookup(str,inf); str = ""; OutFile.WriteString(str); POSITION pos1 = inf->StaticRoleList.GetHeadPosition(); while (pos1 !=NULL) { CString str1; str1 = inf->StaticRoleList.GetAt(pos1); m_Doc->m_ClusterList.Lookup(str1,m_Doc->Cluster); str = ""; OutFile.WriteString(str); POSITION pos2 = m_Doc->Cluster->RuleList.GetStartPosition(); CString InputRole; CString OutputRole; while (pos2 !=NULL) { m_Doc->Cluster->RuleList.GetNextAssoc(pos2,str1,m_Doc->Rule); CString Disorder = GetOutputRoleWithValue(m_Doc->Rule->GetAction()); str1 = ""; OutFile.WriteString(str1); InputRole = AddMetaKBNode(m_Doc->Rule->GetCondition()); OutFile.WriteString(InputRole+""); } OutFile.WriteString(""); inf->StaticRoleList.GetNext(pos1); // OutFile.WriteString(str); } str = ""; OutFile.WriteString(str); } OutFile.WriteString(""); OutFile.Close(); } CString CMetaKBdlg::GetOutputRoleWithValue(CString str) { int x=str.Find("@"); int pos=x+1; CString strCpt; while(str[pos] !='.') { strCpt = strCpt + str[pos++]; } return strCpt; } CString CMetaKBdlg::AddMetaKBNode(CString str) { int x=str.Find("@"); CString OutStr; CString strConc; CString strConc1; while(x>=0) { int pos=x+1; CString strCpt; CString strProp; while(str[pos] !='.') { strCpt = strCpt + str[pos++]; } pos++; while(pos < str.GetLength() && str[pos] != '=' && str[pos] !='>' && str[pos] !='<' && str[pos] !='+' &&str[pos] !='-' && str[pos] !='%' && str[pos] !='&' && str[pos] !='|' &&str[pos] !='*' &&str[pos] !='/' && str[pos] !=')' && str[pos] !='!' ) { strProp = strProp + str[pos++]; } CString strCptPropVal; strCptPropVal = "@"+strCpt + "."+ strProp; strCpt.TrimLeft();strCpt.TrimRight(); strProp.TrimLeft();strProp.TrimRight(); strConc = "@"+strCpt + "."+ strProp; CString strCptProp=strCpt + "-"+ strProp; CConcept * Cpt; CProperty * Prop; m_Doc->m_CptList.Lookup(strCpt,Cpt); Cpt->m_PropList.Lookup(strProp,Prop); CString strType = Prop->Type; while(pos < str.GetLength() && str[pos] ==' ' ) strCptPropVal = strCptPropVal + str[pos++]; if (Prop->Type == "Multi-Value" || Prop->Type == "nominal") { int pos1 = pos; CString strVal1; BOOL LogicalOp = TRUE; while(str[pos1] !='\"') { if (str[pos1] =='!' || str[pos1] =='>' || str[pos1] =='<') LogicalOp = FALSE; strCptPropVal = strCptPropVal + str[pos1++]; } strCptPropVal = strCptPropVal + str[pos1++]; while(str[pos1] !='\"') { strCptPropVal = strCptPropVal + str[pos1]; strVal1 = strVal1+str[pos1++]; } strCptPropVal = strCptPropVal + str[pos1]; if (LogicalOp) OutStr+=""; else OutStr+=""; str.Replace(strCptPropVal ,"1"); } else str.Replace(strConc ,"1"); x=str.Find("@"); if (x==0)break; } return OutStr; } CString CMetaKBdlg::GetOutputRoleValue(CString str) { int x=str.Find("\""); int pos=x+1; CString strVal; while(str[pos] !='"') { strVal = strVal + str[pos++]; } return strVal; } void CMetaKBdlg::OnGenerateMetaByValue() { CString str,DocName; AfxGetApp()->m_pMainWnd->GetWindowText(str); //str.Find(" Version No.",0); str.Replace(".kb",".xml"); DocName = str; CStdioFile OutFile(str,CFile::modeCreate | CFile::modeWrite ); str = ""; OutFile.WriteString(str); //Inference for (int i=0;im_InferenceList.Lookup(str,inf); str = ""; OutFile.WriteString(str); POSITION pos1 = inf->StaticRoleList.GetHeadPosition(); while (pos1 !=NULL) { CString str1; str1 = inf->StaticRoleList.GetAt(pos1); int q = str1.Find("("); str1.Delete(q,str1.GetLength()-q); m_Doc->m_ClusterList.Lookup(str1,m_Doc->Cluster); str = ""; OutFile.WriteString(str); POSITION pos2 = m_Doc->Cluster->RuleList.GetStartPosition(); CString InputRole; CString OutputRole; while (pos2 !=NULL) { m_Doc->Cluster->RuleList.GetNextAssoc(pos2,str1,m_Doc->Rule); CString Disorder = GetOutputRoleWithValue(m_Doc->Rule->GetAction()); CString DisValue = GetOutputRoleValue(m_Doc->Rule->GetAction()); str1 = ""; OutFile.WriteString(str1); InputRole = AddMetaKBNode(m_Doc->Rule->GetCondition()); OutFile.WriteString(InputRole+""); } OutFile.WriteString(""); inf->StaticRoleList.GetNext(pos1); // OutFile.WriteString(str); } str = ""; OutFile.WriteString(str); } OutFile.WriteString(""); OutFile.Close(); } void CMetaKBdlg::OnButton1() { CInference * inf; CString infStr = "predict"; if (!m_Doc->m_InferenceList.Lookup(infStr,inf)) return ; POSITION pos = inf->StaticRoleList.GetHeadPosition(); CString InputRole = ""; while ( pos ) { CString strCluster = inf->StaticRoleList.GetAt(pos); CCluster * Cluster; int q = strCluster.Find("("); strCluster.Delete(q,strCluster.GetLength()-q); if (!m_Doc->m_ClusterList.Lookup( strCluster,Cluster))continue; POSITION pos2 = Cluster->RuleList.GetStartPosition(); while (pos2 !=NULL) { CString str1; CRule * Rule; Cluster->RuleList.GetNextAssoc(pos2,str1,Rule); InputRole = GetInputRoleFromRule(Rule->GetCondition(),InputRole); } inf->StaticRoleList.GetNext(pos); } InputRole += ""; AfxMessageBox( InputRole); } CString CMetaKBdlg::GetInputRoleFromRule(CString str, CString inputRole) { int x=str.Find("@"); while(x>=0) { int pos=x+1; CString strCpt; CString strProp; while(str[pos] !='.') { strCpt = strCpt + str[pos++]; } pos++; while(pos < str.GetLength() && str[pos] != '=' && str[pos] !='>' && str[pos] !='<' && str[pos] !='+' &&str[pos] !='-' && str[pos] !='&' && str[pos] !='|' &&str[pos] !='*' &&str[pos] !='/' && str[pos] !=')' && str[pos] !='!' ) { strProp = strProp + str[pos++]; } CConcept * Cpt; CProperty * Prop; strCpt.TrimLeft();strCpt.TrimRight(); strProp.TrimLeft();strProp.TrimRight(); if (!m_Doc->m_CptList.Lookup(strCpt,Cpt))break; if (!Cpt->m_PropList.Lookup(strProp,Prop))break; CString Source =""; POSITION Spos = Prop->m_SearchOrderList.GetHeadPosition(); if (Spos !=NULL) { Source = Prop->m_SearchOrderList.GetAt(Spos); } CString strCptProp= ""+strCpt + "."+ strProp + ""; CString strConc = "@"+strCpt + "."+ strProp; str.Replace(strConc,"0"); if (inputRole.Find(strCptProp)==-1 ) inputRole += strCptProp; x=str.Find("@"); if (x==0)break; } return inputRole; }