// CptPage.cpp : implementation file
//
#include "stdafx.h"
#include "KBEditors.h"
#include "KBEditorsDoc.h"
#include "CptPage.h"
#include "XMLRPC.h"
#include "xmlutils.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCptPage property page
IMPLEMENT_DYNCREATE(CCptPage, CPropertyPage)
CCptPage::CCptPage() : CPropertyPage(CCptPage::IDD)
{
//{{AFX_DATA_INIT(CCptPage)
m_NameA = _T("");
m_Desc = _T("");
//}}AFX_DATA_INIT
}
CCptPage::~CCptPage()
{
}
CTreeItem::CTreeItem(HTREEITEM TreeItem)
{
this->TreeItem = TreeItem;
}
void CCptPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCptPage)
DDX_Control(pDX, IDC_OntoTREE, m_OntoTree);
DDX_Control(pDX, IDC_CPTTREE, m_CptTree);
DDX_Text(pDX, IDC_CPTNAMEA, m_NameA);
DDX_Text(pDX, IDC_CPTDESCRIPTION, m_Desc);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCptPage, CPropertyPage)
//{{AFX_MSG_MAP(CCptPage)
ON_NOTIFY(NM_RCLICK, IDC_CPTTREE, OnRclickCpttree)
ON_NOTIFY(TVN_ENDLABELEDIT, IDC_CPTTREE, OnEndlabeleditCpttree)
ON_NOTIFY(TVN_BEGINLABELEDIT, IDC_CPTTREE, OnBeginlabelEditCptTree)
ON_EN_SETFOCUS(IDC_CPTNAMEA, OnSetfocusCptnamea)
ON_BN_CLICKED(IDC_ADDCONCEPT, OnAddconcept)
ON_BN_CLICKED(IDC_DSELECT, OnDselect)
ON_BN_CLICKED(IDC_DELCONCEPT, OnDelconcept)
ON_BN_CLICKED(IDC_IMPORT, OnImport)
ON_BN_CLICKED(IDC_EXPORT, OnExport)
ON_EN_SETFOCUS(IDC_CPTDESCRIPTION, OnSetfocusCptdescription)
ON_BN_CLICKED(IDC_FIND, OnFind)
ON_BN_CLICKED(IDC_LOOP, OnLoop)
ON_BN_CLICKED(IDC_EXPORT_XML, OnExportXml)
ON_BN_CLICKED(IDC_ADDFromOnto, OnADDFromOnto)
ON_BN_CLICKED(IDC_DELFromOnto, OnDELFromOnto)
ON_NOTIFY(TVN_SELCHANGED, IDC_OntoTREE, OnSelchangedOntoTREE)
ON_NOTIFY(TVN_SELCHANGED, IDC_CPTTREE, OnSelchangedCpttree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCptPage message handlers
void CCptPage::OnRclickCpttree(NMHDR* pNMHDR, LRESULT* pResult)
{
HTREEITEM TreeItem = m_CptTree.GetSelectedItem();
//m_CptTree.SelectItem(TreeItem);
// m_CptTree.Select(TreeItem,TVGN_CARET);
*pResult = 0;
}
BOOL CCptPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
StatusAdd = FALSE;
SetEditFocus = FALSE;
SetDescFocus = FALSE;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCptPage::OnEndlabeleditCpttree(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
CEdit*Edit;
CConcept * CptP = new CConcept;
Edit= new CEdit;
HTREEITEM TreeItem = m_CptTree.GetSelectedItem();
Edit =(CEdit*) m_CptTree.GetEditControl();
CString str ;
Edit->GetWindowText(str);
m_CptTree.SetItemText(TreeItem,str);
// CConcept * Cpt = new CConcept;
if (!m_Doc->m_CptList.Lookup(str,m_Doc->Cpt))
{
if (StatusAdd ) /* comes from add button */
{
m_Doc->Cpt = new CConcept;
m_Doc->Cpt->NameL=str;
m_Doc->Cpt->nID = m_Doc->MaxConceptID;
/* gets the parent id */
HTREEITEM ParentTreeItem = m_CptTree.GetParentItem(TreeItem);
if (ParentTreeItem != NULL)
{
CString PStr = m_CptTree.GetItemText(ParentTreeItem);
m_Doc->m_CptList.Lookup(PStr,CptP);
m_Doc->Cpt->SupperNID = CptP->nID;
//Helly 15_3_10 to add properties to child
//if(CptP->m_PropList.GetCount() >0){
// CProperty* PrChild = new CProperty;
// PrChild->
//}
//End Helly not copmleted yet
}else
{
m_Doc->Cpt->SupperNID = -1;
}
/* add */
m_Doc->m_CptList.SetAt(str,m_Doc->Cpt);
}else
{
m_Doc->m_CptList.RemoveKey(OldStr);
m_Doc->Cpt->NameL=str;
m_Doc->m_CptList.SetAt(str,m_Doc->Cpt);
}
}else
{
if (str != OldStr)
{
AfxMessageBox (str + " Already Exist ..");
m_CptTree.SetItemText(TreeItem,OldStr);
}
}
StatusAdd = FALSE;
*pResult = 0;
}
BEGIN_EVENTSINK_MAP(CCptPage, CPropertyPage)
//{{AFX_EVENTSINK_MAP(CCptPage)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CCptPage::OnBeginlabelEditCptTree(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
OldStr = pTVDispInfo->item.pszText;
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CCptPage::SeeDoc(CKBEditorsDoc*Doc)
{
m_Doc = Doc;
}
void CCptPage::DeleteTreeItems(HTREEITEM TreeItem)
{
if (!m_CptTree.ItemHasChildren(TreeItem))
{
CString str;
str = m_CptTree.GetItemText(TreeItem);
m_CptTree.DeleteItem(TreeItem);
BOOL x = m_Doc->m_CptList.Lookup(str,m_Doc->Cpt);
m_Doc->m_CptList.RemoveKey(str);
}else
{
HTREEITEM ChildTreeItem = m_CptTree.GetChildItem(TreeItem);
while (ChildTreeItem != NULL)
{
HTREEITEM ChildTreeItem1 = m_CptTree.GetNextSiblingItem(ChildTreeItem);
DeleteTreeItems(ChildTreeItem);
ChildTreeItem = ChildTreeItem1;
}
m_CptTree.DeleteItem(TreeItem);
}
}
void CCptPage::DrawCptTree()
{
/* CImageList *pImageList;
CBitmap bitmap;
int iItem;
UINT nID;
TV_INSERTSTRUCT curTreeItem;
pImageList = new CImageList();
BOOL x = pImageList->Create(32, 16, ILC_MASK, 6, 4);
x = bitmap.LoadBitmap(IDB_CLOSEDBMP);
int y = pImageList->Add(&bitmap, (COLORREF)0xFFFFFF);
bitmap.DeleteObject();
bitmap.LoadBitmap(IDB_OPENEDBMP);
y = pImageList->Add(&bitmap, (COLORREF)0xFFFFFF);
bitmap.DeleteObject();
m_CptTree.SetImageList(pImageList, TVSIL_NORMAL);
*/
m_CptTree.DeleteAllItems();
CString str ;
POSITION pos = m_Doc->m_CptList.GetStartPosition();
while (pos !=NULL)
{
CConcept * Cpt;
m_Doc->m_CptList.GetNextAssoc(pos,str,Cpt);
if (Cpt->SupperNID == -1)
{
HTREEITEM TreeItem = m_CptTree.InsertItem(str,TVI_ROOT,TVI_SORT);
AddChildInTree(TreeItem,Cpt->nID);
}
}
/* HTREEITEM TreeItem1 = m_OntoTree.InsertItem("Thing",TVI_ROOT,TVI_SORT);
CTreeItem * TreeItemObj1 = new CTreeItem(TreeItem1);
MapStrToTreeItemOnto.SetAt("Thing",TreeItemObj1);
if (m_CptTree.GetCount() > 0 ) return;
HTREEITEM TreeItem2 = m_CptTree.InsertItem("Thing",TVI_ROOT,TVI_SORT);
CTreeItem * TreeItemObj2 = new CTreeItem(TreeItem2);
MapStrToTreeItemKB.SetAt("Thing",TreeItemObj2);
CConcept * cpt = new CConcept;
cpt->NameL = "Thing";
cpt->nID = m_Doc->MaxConceptID = 0;
cpt->SupperNID = -1;
m_Doc->m_CptList.SetAt("Thing",cpt);
*/
}
void CCptPage::AddChildInTree(HTREEITEM TreeItem, long ID)
{
CString str ;
POSITION pos = m_Doc->m_CptList.GetStartPosition();
while (pos !=NULL)
{
CConcept * Cpt;
m_Doc->m_CptList.GetNextAssoc(pos,str,Cpt);
if (Cpt->SupperNID == ID)
{
HTREEITEM TreeItem1 = m_CptTree.InsertItem(str,TreeItem,TVI_SORT);
AddChildInTree(TreeItem1,Cpt->nID);
}
}
}
void CCptPage::OnSelchangedCpttree(NMHDR* pNMHDR, LRESULT* pResult)
{
if(SetEditFocus)
{
SetEditFocus = FALSE;
if (!m_Doc->m_CptList.Lookup(str1,m_Doc->Cpt))
return;
else
{
UpdateData();
m_Doc->Cpt->NameA = m_NameA;
}
OnSelchangedCpttree( pNMHDR, pResult);
if(!SetDescFocus)
return;
}
if(SetDescFocus)
{
SetDescFocus = FALSE;
if (!m_Doc->m_CptList.Lookup(str1,m_Doc->Cpt))
return;
else
{
UpdateData();
m_Doc->Cpt->DescriptionA = m_Desc;
}
OnSelchangedCpttree( pNMHDR, pResult);
return;
}
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
HTREEITEM TreeItem = m_CptTree.GetSelectedItem();
if (TreeItem == NULL) return;
CString str = m_CptTree.GetItemText(TreeItem);
if (!m_Doc->m_CptList.Lookup(str,m_Doc->Cpt))
return;
else
{
m_NameA = m_Doc->Cpt->NameA ;
m_Desc = m_Doc->Cpt->DescriptionA ;
UpdateData(FALSE);
}
// see the id's of both concept and its parent
CString str111;
str111.Format("%d--%d",m_Doc->Cpt->nID,m_Doc->Cpt->SupperNID);
SetDlgItemText(IDC_LOOP,str111);
// end
// if (!m_CptTree.ItemHasChildren(TreeItem)) return;
/* CString childListStr = m_Doc->RPC->Call("GetCptKBChildren",(LPCSTR)str,NULL);
MSXML::IXMLDOMDocument *pDoc;
pDoc = CXmlUtils::CreateDoc();
char* err ;
CXmlUtils::loadXMLCStr(pDoc, childListStr, &err);
MSXML::IXMLDOMNodeList * childList;
pDoc->selectNodes(_bstr_t(_T("CPT_LIST/C")), &childList);
long len;
childList->get_length(&len);
for(int i=0; i < len; i++){
CString name = CXmlUtils::GetNodeTextByIndex(childList,i);
CTreeItem * TreeItemObj = new CTreeItem(TreeItem);
if (!MapStrToTreeItemKB.Lookup(name,TreeItemObj)){
HTREEITEM TreeItem1 = m_CptTree.InsertItem(name,TreeItem,TVI_SORT);
CTreeItem * TreeItemObj = new CTreeItem(TreeItem1);
MapStrToTreeItemKB.SetAt(name,TreeItemObj);
CConcept * cpt= new CConcept;
cpt->NameL = name;
m_Doc->m_CptList.SetAt(name,cpt);
}
}
*/
*pResult = 0;
}
void CCptPage::OnSetfocusCptnamea()
{
HTREEITEM TreeItem = m_CptTree.GetSelectedItem();
if (TreeItem == NULL) return;
str1 = m_CptTree.GetItemText(TreeItem);
SetEditFocus = TRUE;
}
void CCptPage::OnAddconcept()
{
// CXMLRPC * Rpc = new CXMLRPC("http://localhost/mfc/rpc.asp");
// AfxMessageBox(x.Send("Hi"));
// AfxMessageBox(x.Send("Hi"));
// AfxMessageBox(x.Send("Hi"));
// AfxMessageBox(Rpc->Call("test", NULL));
// AfxMessageBox(Rpc.Call("addConcepts", "\"Disorder\"", "\"Thing\"", NULL));
/*
HRESULT hr;
MSXML::IXMLHttpRequest *pIXMLHttpRequest = NULL;
hr = CoCreateInstance(MSXML::CLSID_XMLHTTPRequest, NULL, CLSCTX_INPROC_SERVER,
MSXML::IID_IXMLHttpRequest, (void**)&pIXMLHttpRequest);
if(SUCCEEDED(hr))
::MessageBox(NULL, _T("init Success !"), _T(""), MB_OK);
// Create XMLHttpRequest object and initialize pIXMLHttpRequest.
hr = pIXMLHttpRequest->open(_bstr_t(_T("OPEN")),
_bstr_t(_T("http://localhost/mfc/hi.asp")),
_variant_t(VARIANT_FALSE), _variant_t(""), _variant_t(""));
pIXMLHttpRequest->send(_variant_t("dkjfhfg dfkgjd"));
BSTR ss;
pIXMLHttpRequest->get_responseText(&ss);
CString result = ss;
AfxMessageBox(result);
if(SUCCEEDED(hr))
::MessageBox(NULL, _T("Success !"), _T(""), MB_OK);
MSXML::IXMLHttpRequest * p ;
p->open(_bstr_t(_T("POST")), _bstr_t(_T("http://localhost/mfc/addq.asp")));
VARIANT vMsg;
VariantInit(&vMsg);
vMsg.vt = VT_BSTR;
V_BSTR(&vMsg) = _bstr_t(_T("dldldl"));
p->send(vMsg);
BSTR ss;
p->get_responseText(&ss);
CString result = ss;
AfxMessageBox(result);
*/
StatusAdd = TRUE;
HTREEITEM TreeItem = m_CptTree.GetSelectedItem();
CString str("New Concept");
CString str1;
str1.Format("%d",++(m_Doc->MaxConceptID));
str = str + " " + str1;
HTREEITEM ChildTreeItem = m_CptTree.InsertItem(str,TreeItem,TVI_SORT);
m_CptTree.SelectItem(ChildTreeItem);
m_CptTree.EditLabel(ChildTreeItem);
m_CptTree.SelectItem(ChildTreeItem);
m_NameA = "" ;
UpdateData(FALSE);
}
void CCptPage::OnDselect()
{
m_CptTree.SelectItem(NULL);
m_NameA = "" ;
UpdateData(FALSE);
}
void CCptPage::OnDelconcept()
{
HTREEITEM TreeItem = m_CptTree.GetSelectedItem();
if(TreeItem)
DeleteTreeItems(TreeItem);
}
void CCptPage::OnImport()
{
CFileDialog cfdlg(TRUE,"*.pl","*.pl",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Prolog Files (*.pl)");
cfdlg.DoModal();
CString str = cfdlg.GetPathName();
CStdioFile inFile(str,CFile::modeRead );
while (inFile.ReadString(str))
{
if(str.Find("::")>0)
{
m_Doc->Cpt = GetConcept(str);
}
if(str.Find("attributes")>0)
{
CString str1;
while (inFile.ReadString(str1))
{
if (str1.Find("&")>0) break;
str1 = AdjustProperty(str1);
CProperty * Prop = new CProperty;
Prop->NameL = str1;
m_Doc->Cpt->m_PropList.SetAt(str1,Prop);
}
}
if(str.Find("type(") > 0)
{
CString ssProp, ssType;
AdjustType(str, ssProp, ssType);
m_Doc->Cpt->m_PropList.Lookup(ssProp,m_Doc->Prop);
m_Doc->Prop->Type = ssType;
}
if(str.Find("prompt(") > 0)
{
CString ssProp, ssPrompt;
AdjustPrompt(str, ssProp, ssPrompt);
m_Doc->Cpt->m_PropList.Lookup(ssProp,m_Doc->Prop);
m_Doc->Prop->PromptL = ssPrompt;
}
if(str.Find("legal(") > 0)
{
if(str.Find("])") > 0)
{
CString ssProp, ssLegal;
AdjustLegal(str, ssProp, ssLegal);
m_Doc->Cpt->m_PropList.Lookup(ssProp,m_Doc->Prop);
AddLegal(ssLegal, m_Doc->Prop) ;
}
else
{
CString str2,ssLegal,ssProp;
while (inFile.ReadString(str2))
{
if (str2.Find("])")>0) break;
str2.TrimLeft();str2.TrimRight();
ssLegal = ssLegal + str2;
}
GetProp(str, ssProp);
m_Doc->Cpt->m_PropList.Lookup(ssProp,m_Doc->Prop);
AddLegal(ssLegal, m_Doc->Prop) ;
}
}
if(str.Find("super(")>0)
{
m_Doc->Cpt->SupperNID = GetSuperID(str);
m_Doc->m_CptList.SetAt(m_Doc->Cpt->NameL,m_Doc->Cpt);
}
}
DrawCptTree();
}
long CCptPage::GetSuperID(CString str)
{
if(str.Find("domain_class")>0)
{
return -1;
}else
{
CString ss =str;
ss.TrimLeft();ss.TrimRight();
ss = ss.Mid(6,ss.GetLength()-7);
ss.TrimLeft();ss.TrimRight();
CConcept * Cpt1 = new CConcept;
m_Doc->m_CptList.Lookup(ss,Cpt1);
return Cpt1->nID;
}
}
CConcept * CCptPage::GetConcept(CString str)
{
CConcept * Cpt = new CConcept;
CString ss = str.SpanExcluding("::");
ss.TrimLeft();ss.TrimRight();
Cpt->NameL = ss;
Cpt->nID = ++m_Doc->MaxConceptID;
return Cpt;
}
CString CCptPage::AdjustProperty(CString str)
{
CString Temp ;
Temp = str.SpanExcluding(",");
Temp = Temp.SpanExcluding("([])");
Temp.TrimLeft();
Temp.TrimRight();
return Temp;
}
void CCptPage::AdjustType(CString str, CString &ssProp, CString &ssType)
{
ssProp = str.SpanExcluding("/1");
ssProp.TrimLeft();ssProp.TrimRight();
ssProp = ssProp.Mid(5,ssProp.GetLength()-5);
ssProp.TrimLeft();ssProp.TrimRight();
ssType = str;
ssType.MakeReverse();
ssType = ssType.SpanExcluding(",");
ssType.MakeReverse();
ssType = ssType.SpanExcluding(")");
ssType.TrimLeft();ssType.TrimRight();
}
void CCptPage::AdjustPrompt(CString str, CString &ssProp, CString &ssPrompt)
{
ssProp = str.SpanExcluding("/1");
ssProp.TrimLeft();ssProp.TrimRight();
ssProp = ssProp.Mid(7,ssProp.GetLength()-7);
ssProp.TrimLeft();ssProp.TrimRight();
ssPrompt = str;
ssPrompt.MakeReverse();
ssPrompt = ssPrompt.SpanExcluding("1/");
ssPrompt.TrimLeft();ssPrompt.TrimRight();
ssPrompt.MakeReverse();
ssPrompt = ssPrompt.SpanExcluding("&");
ssPrompt.TrimLeft();ssPrompt.TrimRight();
ssPrompt = ssPrompt.SpanExcluding(")");
ssPrompt = ssPrompt.SpanExcluding("[]");
ssPrompt.TrimLeft();ssPrompt.TrimRight();
ssPrompt = ssPrompt.Mid(1,ssPrompt.GetLength()-1);
ssPrompt.TrimLeft();ssPrompt.TrimRight();
ssPrompt = ssPrompt.SpanExcluding(",");
ssPrompt = ssPrompt.Mid(1,ssPrompt.GetLength()-1);
ssPrompt.TrimLeft();ssPrompt.TrimRight();
ssPrompt = ssPrompt.SpanExcluding("'");
ssPrompt.TrimLeft();ssPrompt.TrimRight();
ssPrompt = ssPrompt.SpanExcluding("?");
ssPrompt = ssPrompt + " ?";
}
void CCptPage::GetProp(CString str, CString &ssProp)
{
ssProp = str.SpanExcluding("/1");
ssProp.TrimLeft();ssProp.TrimRight();
ssProp = ssProp.Mid(6,ssProp.GetLength()-6);
ssProp.TrimLeft();ssProp.TrimRight();
}
void CCptPage::AdjustLegal(CString str, CString &ssProp, CString &ssLegal)
{
ssProp = str.SpanExcluding("/1");
ssProp.TrimLeft();ssProp.TrimRight();
ssProp = ssProp.Mid(6,ssProp.GetLength()-6);
ssProp.TrimLeft();ssProp.TrimRight();
ssLegal = str;
ssLegal.MakeReverse();
ssLegal = ssLegal.SpanExcluding("1/");
ssLegal.TrimLeft();ssLegal.TrimRight();
ssLegal.MakeReverse();
ssLegal = ssLegal.SpanExcluding("&");
ssLegal.TrimLeft();ssLegal.TrimRight();
ssLegal = ssLegal.SpanExcluding(")");
ssLegal = ssLegal.SpanExcluding("]");
ssLegal.TrimLeft();ssLegal.TrimRight();
ssLegal = ssLegal.Mid(1,ssLegal.GetLength()-1);
ssLegal.TrimLeft();ssLegal.TrimRight();
ssLegal = ssLegal.Mid(1,ssLegal.GetLength()-1);
ssLegal.TrimLeft();ssLegal.TrimRight();
}
void CCptPage:: AddLegal(CString ssLegal, CProperty* Prop)
{
CString Temp;
do
{
Temp = ssLegal;
ssLegal.Delete(0,Temp.Find(',')+1);
Temp = Temp.Left(Temp.Find(','));
Temp.TrimLeft();Temp.TrimRight();
Prop->m_LegalValueList.SetAt(Temp,"");
}
while(ssLegal.Find(',') != -1);
Prop->m_LegalValueList.SetAt(ssLegal,"");
}
void CCptPage::OnExport()
{
CConcept * Cpt;
// CProperty * Prop ;
POSITION pos = m_Doc->m_CptList.GetStartPosition();
CString str;
while (pos !=NULL)
{
m_Doc->m_CptList.GetNextAssoc(pos,str,Cpt);
if(Cpt->nID ==41 )Cpt->SupperNID = 53;
if(Cpt->nID ==38 )Cpt->SupperNID = 53;
if(Cpt->nID ==40 )Cpt->SupperNID = 53;
if(Cpt->nID ==39 )Cpt->SupperNID = 53;
}
/*CFileDialog cfdlg(FALSE,"*.html","*.html",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"HTML Files (*.html)");
cfdlg.DoModal();
CString str = cfdlg.GetPathName();
CStdioFile OutFile(str,CFile::modeCreate | CFile::modeWrite );
// Ontology
str = "
Domain KnowledgeOntology
";
OutFile.WriteString(str);
CConcept * Cpt = new CConcept;
CProperty * Prop = new CProperty;
POSITION pos = m_Doc->m_CptList.GetStartPosition();
while (pos !=NULL)
{
m_Doc->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 %f And %f ",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;
}
}
PV = PV+".";
str1= " "+Prop->NameL+" "+Prop->NameA+" | Type | "+Prop->Type+" |
"+
"Prompt | "+Prop->PromptA+" |
"+
"Default | "+Prop->Default+" |
"+
"PV | "+PV+" |
";
OutFile.WriteString(str1);
}
str = "
";
OutFile.WriteString(str);
}
// Rules
pos = m_Doc->m_ClusterList.GetStartPosition();
str = "Relations
";
OutFile.WriteString(str);
while (pos !=NULL)
{
m_Doc->m_ClusterList.GetNextAssoc(pos,str,m_Doc->Cluster);
str = ""+str+"";
OutFile.WriteString(str);
str = "
Rules | Description |
";
OutFile.WriteString(str);
POSITION pos1 = m_Doc->Cluster->RuleList.GetStartPosition();
while (pos1 !=NULL)
{
CString str1;
m_Doc->Cluster->RuleList.GetNextAssoc(pos1,str1,m_Doc->Rule);
str1= " "+m_Doc->Rule->RuleID+" | IF "+m_Doc->Rule->GetCondition()+
" THEN "+m_Doc->Rule->GetAction()+" |
";
OutFile.WriteString(str1);
}
str = "
";
OutFile.WriteString(str);
}
//Inference
pos = m_Doc->m_InferenceList.GetStartPosition();
str = "Inference Steps
";
OutFile.WriteString(str);
while (pos !=NULL)
{
//StaticRoleList
CInference * inf;
CString StaticRole;
m_Doc->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);
m_Doc->m_ClusterList.Lookup(str1,m_Doc->Cluster);
StaticRole = StaticRole + str1 + "
";
POSITION pos2 = m_Doc->Cluster->RuleList.GetStartPosition();
CString InputRole;
CString OutputRole;
while (pos2 !=NULL)
{
m_Doc->Cluster->RuleList.GetNextAssoc(pos2,str1,m_Doc->Rule);
InputRole =InputRole+ GetInputRole(m_Doc->Rule->GetCondition(),InputRole);
OutputRole = OutputRole+GetOutputRole(m_Doc->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();
*/
}
CString CCptPage::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 CCptPage::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 CCptPage::OnSetfocusCptdescription()
{
HTREEITEM TreeItem = m_CptTree.GetSelectedItem();
if (TreeItem == NULL) return;
str1 = m_CptTree.GetItemText(TreeItem);
SetDescFocus = TRUE;
}
void CCptPage::OnFind()
{
CString strCpt;
GetDlgItemText(IDC_FIND_CPT,strCpt);
if(strCpt.IsEmpty()) return;
if (!m_CptTree.GetSelectedItem())
{
AfxMessageBox(" Select the start searching point ");
return;
}
HTREEITEM TreeItem = Search(m_CptTree.GetSelectedItem(), strCpt);
if(TreeItem != NULL)
{
m_CptTree.SetFocus();
m_CptTree.Expand(m_CptTree.GetParentItem(TreeItem),TVE_EXPAND);
m_CptTree.Select(TreeItem,TVGN_CARET);
}
else
{
AfxMessageBox(strCpt + " Is Not Found in "+m_CptTree.GetItemText(m_CptTree.GetSelectedItem()));
}
}
HTREEITEM CCptPage::Search(HTREEITEM TreeItem, CString str)
{
if (m_CptTree.GetItemText(TreeItem)==str)
return TreeItem;
HTREEITEM TreeItem1 = m_CptTree.GetChildItem(TreeItem);
if (TreeItem1 == NULL) return NULL;
while (TreeItem1 != NULL)
{
HTREEITEM TreeItem2 = Search(TreeItem1,str);
if (TreeItem2 != NULL) return TreeItem2;
TreeItem1=m_CptTree.GetNextSiblingItem(TreeItem1);
}
return NULL;
}
BOOL CCptPage::OnSetActive()
{
// DrawCptTree();
return CPropertyPage::OnSetActive();
}
void CCptPage::OnLoop()
{
CString str ;
POSITION pos = m_Doc->m_CptList.GetStartPosition();
while (pos !=NULL)
{
CConcept * Cpt;
m_Doc->m_CptList.GetNextAssoc(pos,str,Cpt);
// if (Cpt->SupperNID == 19) Cpt->SupperNID = 69;
CString ss;
ss.Format("%d",Cpt->SupperNID);
AfxMessageBox (str + " .." + ss);
}
}
#define CHECKHR(x) {hr = x; if (FAILED(hr)) goto CleanUp;}
#define SAFERELEASE(p) {if (p) {(p)->Release(); p = NULL;}}
////////////////////////////////////////////////////////////////////////////
// Helper Function: Convert ascii string to BSTR
////////////////////////////////////////////////////////////////////////////
BSTR CCptPage ::AsciiToBSTR(const char* pszFName)
{
WCHAR wszURL[MAX_PATH];
::MultiByteToWideChar(CP_ACP, 0, pszFName, -1, wszURL, MAX_PATH);
return SysAllocString(wszURL);
}
////////////////////////////////////////////////////////////////////////////
// Helper function: Create an IDOMNode of the given type
////////////////////////////////////////////////////////////////////////////
MSXML::IXMLDOMNode * CCptPage :: CreateDOMNodeFromItem(MSXML::IXMLDOMDocument* pDoc,
int type, HTREEITEM hItem, const char * tagName)
{
HRESULT hr = S_OK;
BSTR bstrName, bstrTagName;
MSXML::IXMLDOMNode * node, *ptNode;
VARIANT vtype;
CString strCpt;
strCpt = m_CptTree.GetItemText(hItem);
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><
// Creating the Node
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><
bstrName = AsciiToBSTR((char *)(LPCTSTR)strCpt);
bstrTagName = AsciiToBSTR(tagName);
vtype.vt = VT_I4;
V_I4(&vtype) = (int)type;
CHECKHR(pDoc->createNode(vtype, bstrTagName , NULL, &node));
CHECKHR(node->put_text(bstrName));
SysFreeString(bstrName);
SysFreeString(bstrTagName);
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><
// Creating the properties
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><
CConcept *cpt ;
CProperty *prop;
m_Doc->m_CptList.Lookup(strCpt,cpt);
if(!cpt->m_PropList.IsEmpty())
{
POSITION pos = cpt->m_PropList.GetStartPosition();
while(pos)
{
CString strProp;
cpt->m_PropList.GetNextAssoc(pos,strProp,prop);
ptNode= CreateDOMNodeFromString(pDoc,MSXML::NODE_ELEMENT,
(char*)(LPCTSTR)strProp,
"PROPERTY");
CHECKHR(node->appendChild(ptNode,NULL));
}
}
//<><><><><><><><><><><><><><><><><><><><><><><><><><><><
SysFreeString(bstrName);
SysFreeString(bstrTagName);
return node;
CleanUp:
SysFreeString(bstrName);
SysFreeString(bstrTagName);
SAFERELEASE(node);
return NULL;
}
MSXML::IXMLDOMNode * CCptPage :: CreateDOMNodeFromString(MSXML::IXMLDOMDocument* pDoc,
int type, const char *s, const char * tagName)
{
HRESULT hr = S_OK;
BSTR bstrName, bstrTagName;
MSXML::IXMLDOMNode * node;
VARIANT vtype;
bstrName = AsciiToBSTR(s);
bstrTagName = AsciiToBSTR(tagName);
vtype.vt = VT_I4;
V_I4(&vtype) = (int)type;
CHECKHR(pDoc->createNode(vtype, bstrTagName, NULL, &node));
CHECKHR(node->put_text(bstrName));
SysFreeString(bstrName);
SysFreeString(bstrTagName);
return node;
CleanUp:
SysFreeString(bstrName);
SysFreeString(bstrTagName);
SAFERELEASE(node);
return NULL;
}
////////////////////////////////////////////////////////////////////////////
// Function: Save document out to specified local file.
////////////////////////////////////////////////////////////////////////////
HRESULT CCptPage :: SaveDocument(MSXML::IXMLDOMDocument *pDoc, BSTR pBFName)
{
HRESULT hr = S_OK;
VARIANT vName;
vName.vt = VT_BSTR;
V_BSTR(&vName) = pBFName;
CHECKHR(pDoc->save(vName));
CleanUp:
return hr;
}
void CCptPage :: PrintChild(HTREEITEM hItem, MSXML::IXMLDOMNode* parent, MSXML::IXMLDOMDocument *pDoc)
{
HTREEITEM hItemChild = m_CptTree.GetChildItem(hItem);
MSXML::IXMLDOMNode* pNode = NULL;
BSTR nodeName = NULL;
HRESULT hr = S_OK;
BSTR bDocName;
bDocName = AsciiToBSTR("batata.xml");
while (hItemChild != NULL)
{
//AfxMessageBox(m_CptTree.GetItemText(hItemChild));
//allocate comcept name in a unicode string
//nodeName = ::SysAllocString((unsigned short *)(char *)(LPCTSTR)m_CptTree.GetItemText(hItemChild));
//nodeName = AsciiToBSTR((char *)(LPCTSTR)m_CptTree.GetItemText(hItemChild));
//create an XML node
pNode = CreateDOMNodeFromItem(pDoc, MSXML::NODE_ELEMENT, hItemChild, "CONCEPT");
if(!pNode) goto CleanUp;
//realease the allocated unicode string
//SysFreeString(nodeName);
//add the created node to the dom
CHECKHR(parent->appendChild(pNode, NULL));
SaveDocument(pDoc, bDocName);
PrintChild(hItemChild, pNode, pDoc);
hItemChild = m_CptTree.GetNextSiblingItem(hItemChild);
}
SysFreeString(bDocName);
CleanUp:
SAFERELEASE(pNode);
SAFERELEASE(parent);
SysFreeString(bDocName);
}
void CCptPage::OnExportXml()
{
HRESULT hr = S_OK;
MSXML::IXMLDOMDocument *pDoc = NULL;
MSXML::IXMLDOMNode* pNode = NULL, *pRoot =NULL;
BSTR nodeName = NULL;
BSTR bDocName;
bDocName = AsciiToBSTR("batata.xml");
//get the first element on the root level
HTREEITEM hItemChild = m_CptTree.GetRootItem();
//Initialize COM
CoInitialize(NULL);
// Create an empty XML document
CHECKHR(CoCreateInstance(MSXML::CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
MSXML::IID_IXMLDOMDocument, (void**)&pDoc));
//create an XML node
pRoot = CreateDOMNodeFromString(pDoc, MSXML::NODE_ELEMENT, "BEANS", "ONTOLOGY");
if(!pRoot) goto CleanUp;
CHECKHR(pDoc->appendChild(pRoot, NULL));
while (hItemChild != NULL)
{
//AfxMessageBox(m_CptTree.GetItemText(hItemChild));
//create an XML node
pNode = CreateDOMNodeFromItem(pDoc, MSXML::NODE_ELEMENT, hItemChild, "CONCEPT");
if(!pNode) goto CleanUp;
//add the created node to the dom
CHECKHR(pRoot->appendChild(pNode, NULL));
//SaveDocument(pDoc,bDocName);
PrintChild(hItemChild, pNode, pDoc);
hItemChild = m_CptTree.GetNextSiblingItem(hItemChild);
}
//save the document
SaveDocument(pDoc, bDocName);
SysFreeString(bDocName);
AfxMessageBox("Done exporting to XML");
CleanUp:
SAFERELEASE(pDoc);
SAFERELEASE(pNode);
SAFERELEASE(pRoot);
SysFreeString(bDocName);
}
BOOL CCptPage::OnKillActive()
{
m_Doc->OnSaveDocument(m_Doc->AppName);
return CPropertyPage::OnKillActive();
}
void CCptPage::OnADDFromOnto()
{
HTREEITEM TreeItem = m_OntoTree.GetSelectedItem();
if (TreeItem == NULL) return;
CString ConceptName = m_CptTree.GetItemText(TreeItem);
AddCptToKB(ConceptName);
}
void CCptPage::AddCptToKB(CString ConceptName)
{
CTreeItem * OntoNode;
CTreeItem * DummyParent;
if(!MapStrToTreeItemKB.Lookup(ConceptName,DummyParent)){
BOOL x = MapStrToTreeItemOnto.Lookup(ConceptName,OntoNode);
HTREEITEM ParentTreeItem = m_OntoTree.GetParentItem(OntoNode->TreeItem);
CString ParentName = m_OntoTree.GetItemText(ParentTreeItem);
if(!MapStrToTreeItemKB.Lookup(ParentName,DummyParent))
AddCptToKB(ParentName);
CTreeItem * KBParent;
MapStrToTreeItemKB.Lookup(ParentName,KBParent);
HTREEITEM TreeItemH = m_CptTree.InsertItem(ConceptName,KBParent->TreeItem,TVI_SORT);
CTreeItem * TreeItemObj = new CTreeItem(TreeItemH);
MapStrToTreeItemKB.SetAt(ConceptName,TreeItemObj);
CString Str = m_Doc->RPC->Call("addCptToKB",(LPCSTR)ConceptName,(LPCSTR)ParentName,NULL);
if (Str != "OK")
AfxMessageBox(Str);
CConcept * parentCpt;
m_Doc->m_CptList.Lookup(ParentName,parentCpt);
CConcept * cpt = new CConcept;
cpt->NameL = ConceptName;
cpt->nID = ++m_Doc->MaxConceptID;
cpt->SupperNID = parentCpt->nID;
m_Doc->m_CptList.SetAt(ConceptName,cpt);
}
}
void CCptPage::OnDELFromOnto()
{
// TODO: Add your control notification handler code here
}
void CCptPage::OnSelchangedOntoTREE(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
HTREEITEM TreeItem = m_OntoTree.GetSelectedItem();
if (TreeItem == NULL) return;
if (m_OntoTree.ItemHasChildren(TreeItem))
return;
CString str = m_CptTree.GetItemText(TreeItem);
//theApp.Rpc.Call("GetCptChildren",str,NULL);
CString childListStr = m_Doc->RPC->Call("GetCptChildren",(LPCSTR)str,NULL);
MSXML::IXMLDOMDocument *pDoc;
pDoc = CXmlUtils::CreateDoc();
char* err ;
CXmlUtils::loadXMLCStr(pDoc, childListStr, &err);
MSXML::IXMLDOMNodeList * childList;
pDoc->selectNodes(_bstr_t(_T("CPT_LIST/C")), &childList);
long len;
childList->get_length(&len);
for(int i=0; i < len; i++){
CString name = CXmlUtils::GetNodeTextByIndex(childList,i);
HTREEITEM TreeItem1 = m_OntoTree.InsertItem(name,TreeItem,TVI_SORT);
CTreeItem * TreeItemObj = new CTreeItem(TreeItem1);
MapStrToTreeItemOnto.SetAt(name,TreeItemObj);
}
*pResult = 0;
}
/*void CCptPage::OnSelchangedCpttree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}*/