// DesignDocument.cpp : implementation file
//
#include "stdafx.h"
#include "kbeditors.h"
#include "KBEditorsDoc.h"
#include "DesignDocument.h"
#include "General.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class CConcept;
class CProperty;
class CKBEditorsDoc;
/////////////////////////////////////////////////////////////////////////////
// CDesignDocument dialog
CDesignDocument::CDesignDocument(CWnd* pParent /*=NULL*/)
: CDialog(CDesignDocument::IDD, pParent)
{
//{{AFX_DATA_INIT(CDesignDocument)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDesignDocument::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDesignDocument)
DDX_Control(pDX, IDC_DesignView, m_DesignView);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDesignDocument, CDialog)
//{{AFX_MSG_MAP(CDesignDocument)
ON_BN_CLICKED(ID_GenerateONtoDesign, OnGenerateONtoDesign)
ON_BN_CLICKED(ID_GenerateRelation, OnGenerateRelation)
ON_BN_CLICKED(ID_GenerateInference, OnGenerateInference)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDesignDocument message handlers
BOOL CDesignDocument::OnInitDialog()
{
CDialog::OnInitDialog();
CenterWindow(GetDesktopWindow());
CString str;
AfxGetApp()->m_pMainWnd->GetWindowText(str);
str.Replace(".kb",".htm");
DocName = str;
SetDlgItemText(IDC_EDIT1, str);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDesignDocument::SeeDoc(CKBEditorsDoc*Doc)
{
pDoc = Doc;
}
CString CDesignDocument::GetInputRole(CString str,CString InRole)
{
int x=str.Find("@");
CString strConc;
CString Out;
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++];
}
strConc = "@"+strCpt + "."+ strProp;
CString strCptProp=strCpt + "."+ strProp+"\n";
str.Replace(strConc,strCptProp);
if (Out.Find(strCptProp)==-1 && InRole.Find(strCptProp)==-1)
Out = Out +strCptProp+"
";
x=str.Find("@");
if (x==0)break;
}
return Out;
}
CString CDesignDocument::GetOutputRole(CString str,CString OutRole)
{
int x=str.Find("@");
CString strConc;
CString Out;
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] != ' ' )
{
strProp = strProp + str[pos++];
}
strConc = "@"+strCpt + "."+ strProp;
int y = str.Find(";");
str.Delete(0,y+1);
str.TrimRight();str.TrimLeft();
CString strCptProp = strCpt+"."+strProp;
if (Out.Find(strCptProp)==-1 && OutRole.Find(strCptProp)==-1)
Out = Out + strCptProp+"
";
x=str.Find("@");
if (x==-1)break;
}
return Out;
}
void CDesignDocument::OnGenerateDesign()
{
CString str;
// AfxGetApp()->m_pMainWnd->GetWindowText(str);
// str.Replace(".kb",".htm");
// DocName = str;
/*
CFileDialog cfdlg(FALSE,"*.html","*.html",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"HTML Files (*.html)");
cfdlg.DoModal();
CString str = cfdlg.GetPathName();
*/
CStdioFile OutFile(DocName,CFile::modeCreate | CFile::modeWrite );
// Ontology
str = "
Domain KnowledgeOntology
";
OutFile.WriteString(str);
CConcept * Cpt = new CConcept;
CProperty * Prop = new CProperty;
POSITION pos = pDoc->m_CptList.GetStartPosition();
while (pos !=NULL)
{
pDoc->m_CptList.GetNextAssoc(pos,str,Cpt);
str = ""+str+" " +Cpt->NameA+"
";
OutFile.WriteString(str);
str = " Properties | Facets |
";
OutFile.WriteString(str);
POSITION pos1 = Cpt->m_PropList.GetStartPosition();
while (pos1 !=NULL)
{
CString str1;
CString PV;
Cpt->m_PropList.GetNextAssoc(pos1,str1,Prop);
if (Prop->Type == "real" || Prop->Type == "integer")
{
PV.Format("Between %.0f And %.0f ",Prop->LL ,Prop->UL);
}else
{
POSITION pos11 =Prop->m_LegalValueList.GetStartPosition();
int First=0;
while (pos11 !=NULL)
{
CString st,st1;
Prop->m_LegalValueList.GetNextAssoc(pos11,st,st1);
if (First == 0)
PV = st;
else
PV = PV+", "+st;
First = 1;
}
}
CString SV;
POSITION Spos = Prop->m_SearchOrderList.GetHeadPosition();
while (Spos !=NULL)
{
SV = SV +Prop->m_SearchOrderList.GetAt(Spos) +" ";
Prop->m_SearchOrderList.GetNext(Spos);
}
PV = PV+".";
SV = SV+".";
CString str2,str3,str4,str5,str6,strRws;
int Rws =5;
if (Prop->Type.IsEmpty())
Rws--;
else
str2="Type | "+Prop->Type+" | ";
if (Prop->PromptA.IsEmpty())
Rws--;
else
str3= "Prompt | "+Prop->PromptA+" |
";
if (Prop->Default.IsEmpty())
Rws--;
else
str4= "Default | "+Prop->Default+" |
";
if (PV.GetLength()<2)
Rws--;
else
str5= "PV | "+PV+" |
";
if (SV.GetLength()<2)
Rws--;
else
str6= "SV | "+SV+" |
";
strRws.Format("%d",Rws);
str1= " " +Prop->NameL+" " +Prop->NameA+" | ";
str1 = str1+str2+str3+str4+str5+str6+"
";
OutFile.WriteString(str1);
}
str = "
";
OutFile.WriteString(str);
}
// Rules
pos = pDoc->m_ClusterList.GetStartPosition();
str = "Relations
";
OutFile.WriteString(str);
while (pos !=NULL)
{
pDoc->m_ClusterList.GetNextAssoc(pos,str,pDoc->Cluster);
str = ""+str+"";
OutFile.WriteString(str);
str = "
Rules | Description |
";
OutFile.WriteString(str);
POSITION pos1 = pDoc->Cluster->RuleList.GetStartPosition();
while (pos1 !=NULL)
{
CString str1;
pDoc->Cluster->RuleList.GetNextAssoc(pos1,str1,pDoc->Rule);
str1= " "+pDoc->Rule->RuleID+" | IF "+pDoc->Rule->GetCondition()+
" THEN "+pDoc->Rule->GetAction()+" |
";
OutFile.WriteString(str1);
}
str = "
";
OutFile.WriteString(str);
}
//Inference
pos = pDoc->m_InferenceList.GetStartPosition();
str = "Inference Steps
";
OutFile.WriteString(str);
while (pos !=NULL)
{
//StaticRoleList
CInference * inf;
CString StaticRole;
pDoc->m_InferenceList.GetNextAssoc(pos,str,inf);
str = ""+str+"";
OutFile.WriteString(str);
str = "
Roles | Description |
";
OutFile.WriteString(str);
POSITION pos1 = inf->StaticRoleList.GetHeadPosition();
while (pos1 !=NULL)
{
CString str1;
str1 = inf->StaticRoleList.GetAt(pos1);
pDoc->m_ClusterList.Lookup(str1,pDoc->Cluster);
StaticRole = StaticRole + str1 + "
";
POSITION pos2 = pDoc->Cluster->RuleList.GetStartPosition();
CString InputRole;
CString OutputRole;
while (pos2 !=NULL)
{
pDoc->Cluster->RuleList.GetNextAssoc(pos2,str1,pDoc->Rule);
InputRole =InputRole+ GetInputRole(pDoc->Rule->GetCondition(),InputRole);
OutputRole = OutputRole+GetOutputRole(pDoc->Rule->GetAction(),OutputRole);
}
str1= "Dynamic Input Role | "+InputRole+" |
"+
"Dynamic Output Role | "+OutputRole+" |
";
OutFile.WriteString(str1);
inf->StaticRoleList.GetNext(pos1);
// OutFile.WriteString(str);
}
str = "Static Role | "+StaticRole+" |
";
OutFile.WriteString(str);
}
OutFile.WriteString("");
OutFile.Close();
// CAboutDlg aboutDlg;
// aboutDlg.FName = DocName;
//"D:\\KBEditors\\index.htm";
// aboutDlg.DoModal();
//ShellExecute(GetSafeHwnd(),"open",DocName,NULL,NULL,SW_SHOW);
}
void CDesignDocument::OnGenerateONtoDesign()
{
CString str;
GetDlgItemText(IDC_EDIT1, str);
CStdioFile OutFile(str,CFile::modeCreate | CFile::modeWrite );
// Ontology
str = "Ontology";
OutFile.WriteString(str);
CConcept * Cpt ;
CProperty * Prop ;
POSITION pos = pDoc->m_CptList.GetStartPosition();
while (pos !=NULL)
{
pDoc->m_CptList.GetNextAssoc(pos,str,Cpt);
str = ""+str+" " +Cpt->NameA+"
";
OutFile.WriteString(str);
str = " Properties | Facets |
";
OutFile.WriteString(str);
POSITION pos1 = Cpt->m_PropList.GetStartPosition();
while (pos1 !=NULL)
{
CString str1;
CString PV;
Cpt->m_PropList.GetNextAssoc(pos1,str1,Prop);
if (Prop->Type == "real" || Prop->Type == "integer")
{
PV.Format("Between %.0f And %.0f ",Prop->LL ,Prop->UL);
}else
{
if(Prop->NameL != "disorder_name"){
POSITION pos11 =Prop->m_LegalValueList.GetStartPosition();
int First=0;
while (pos11 !=NULL)
{
CString st,st1;
Prop->m_LegalValueList.GetNextAssoc(pos11,st,st1);
if (First == 0)
PV = ""+ st +" | "+ st1+" |
";
else
PV = PV + ""+ st +" | "+ st1+" |
" ;
First = 1;
}
if(First) PV = PV+"
";
}
}
CString SV;
POSITION Spos = Prop->m_SearchOrderList.GetHeadPosition();
while (Spos !=NULL)
{
SV = SV +Prop->m_SearchOrderList.GetAt(Spos) +" ";
Prop->m_SearchOrderList.GetNext(Spos);
}
SV = SV+".";
CString str2,str3,str4,str5,str6,strRws;
int Rws =5;
if (Prop->Type.IsEmpty())
Rws--;
else
str2="Type | "+Prop->Type+" | ";
if (Prop->PromptA.IsEmpty())
Rws--;
else
str3= "Prompt | "+Prop->PromptA+" |
";
if (Prop->Default.IsEmpty())
Rws--;
else
str4= "Default | "+Prop->Default+" |
";
// if (PV.GetLength()<2)
// Rws--;
// else
str5= "PV | "+PV+" |
";
if (SV.GetLength()<2)
Rws--;
else
str6= "SV | "+SV+" |
";
strRws.Format("%d",Rws);
str1= " " +Prop->NameL+" " +Prop->NameA+" | ";
str1 = str1+str2+str3+str4+str5+str6+"
";
OutFile.WriteString(str1);
}
str = "
";
OutFile.WriteString(str);
}
OutFile.WriteString("");
OutFile.Close();
AfxMessageBox("Ontology generated successfuly");
GetDlgItemText(IDC_EDIT1, str);
m_DesignView.Navigate(str,NULL,NULL,NULL,NULL);
// CAboutDlg aboutDlg;
// aboutDlg.FName = DocName;
//"D:\\KBEditors\\index.htm";
// aboutDlg.DoModal();
// ShellExecute(GetSafeHwnd(),"open",DocName,NULL,NULL,SW_SHOW);
}
void CDesignDocument::OnGenerateRelation()
{
CString str;
GetDlgItemText(IDC_EDIT1, str);
CStdioFile OutFile(str,CFile::modeCreate | CFile::modeWrite );
str = "Relations";
OutFile.WriteString(str);
POSITION pos = pDoc->m_ClusterList.GetStartPosition();
str = "Relations
";
OutFile.WriteString(str);
while (pos !=NULL)
{
pDoc->m_ClusterList.GetNextAssoc(pos,str,pDoc->Cluster);
str = ""+str+"";
OutFile.WriteString(str);
str = "
Rules | Description |
";
OutFile.WriteString(str);
POSITION pos1 = pDoc->Cluster->RuleList.GetStartPosition();
while (pos1 !=NULL)
{
CString str1;
pDoc->Cluster->RuleList.GetNextAssoc(pos1,str1,pDoc->Rule);
str1= " "+pDoc->Rule->RuleID+" | IF "+pDoc->Rule->GetCondition()+
" THEN "+pDoc->Rule->GetAction()+" |
";
OutFile.WriteString(str1);
}
str = "
";
OutFile.WriteString(str);
}
OutFile.WriteString("");
OutFile.Close();
AfxMessageBox("Relation generated successfuly");
GetDlgItemText(IDC_EDIT1, str);
m_DesignView.Navigate(str,NULL,NULL,NULL,NULL);
}
void CDesignDocument::OnGenerateInference()
{
CString str;
GetDlgItemText(IDC_EDIT1, str);
CStdioFile OutFile(str,CFile::modeCreate | CFile::modeWrite );
str = "Relations";
OutFile.WriteString(str);
POSITION pos = pDoc->m_InferenceList.GetStartPosition();
str = "Inference Steps
";
OutFile.WriteString(str);
while (pos !=NULL)
{
//StaticRoleList
CInference * inf;
CString StaticRole;
pDoc->m_InferenceList.GetNextAssoc(pos,str,inf);
str = ""+str+"";
OutFile.WriteString(str);
str = "
Roles | Description |
";
OutFile.WriteString(str);
POSITION pos1 = inf->StaticRoleList.GetHeadPosition();
while (pos1 !=NULL)
{
CString str1;
str1 = inf->StaticRoleList.GetAt(pos1);
pDoc->m_ClusterList.Lookup(str1,pDoc->Cluster);
StaticRole = StaticRole + str1 + "
";
POSITION pos2 = pDoc->Cluster->RuleList.GetStartPosition();
CString InputRole;
CString OutputRole;
while (pos2 !=NULL)
{
pDoc->Cluster->RuleList.GetNextAssoc(pos2,str1,pDoc->Rule);
InputRole =InputRole+ GetInputRole(pDoc->Rule->GetCondition(),InputRole);
OutputRole = OutputRole+GetOutputRole(pDoc->Rule->GetAction(),OutputRole);
}
str1= "Dynamic Input Role | "+InputRole+" |
"+
"Dynamic Output Role | "+OutputRole+" |
";
OutFile.WriteString(str1);
inf->StaticRoleList.GetNext(pos1);
// OutFile.WriteString(str);
}
str = "Static Role | "+StaticRole+" |
";
OutFile.WriteString(str);
}
OutFile.WriteString("");
OutFile.Close();
AfxMessageBox("Infernce generated successfuly");
GetDlgItemText(IDC_EDIT1, str);
m_DesignView.Navigate(str,NULL,NULL,NULL,NULL);
}