00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00020
00021
00022 #include "link.h"
00023 #include "link_list.h"
00024 #include "concept.h"
00025 #include "find_cfg.h"
00026 #include "debug.h"
00027
00028 bool CSemanticLink::FindPathTo(const SemanticID a_dstID,
00029 CFindPathConfig &a_config)
00030 {
00031 DPRINT("visiting link.\n");
00032
00033 a_config.VisitLink(this);
00034
00035 if (m_dest)
00036 {
00037 if (m_dest->GetID() == a_dstID)
00038 {
00039 DPRINT("adding path to results.\n");
00040
00041 a_config.AddPathToResults();
00042
00043 a_config.LeaveLink();
00044
00045 return true;
00046 }
00047 else if (true == a_config.AllowVisit())
00048 {
00049 DPRINT("queueing path.\n");
00050 a_config.QueuePath();
00051 }
00052 }
00053 else DPRINT("invalid link\n");
00054
00055
00056 a_config.LeaveLink();
00057
00058 return false;
00059 }
00060
00061
00062 CSemanticLink::CSemanticLink()
00063 {
00064 m_source = NULL;
00065 m_dest = NULL;
00066
00067 m_sourceID = 0;
00068 m_destID = 0;
00069
00070 m_linkID = SEMANTIC_ID_NONE;
00071
00072 m_type = RELATION_NONE;
00073 }
00074
00075
00076 void CSemanticLink::SetSource(CSemanticConcept *a_concept)
00077 {
00078 if (a_concept)
00079 {
00080 m_source = a_concept;
00081
00082 m_sourceID = m_source->GetID();
00083 }
00084 }
00085
00086 void CSemanticLink::SetDest(CSemanticConcept *a_concept)
00087 {
00088 if (a_concept)
00089 {
00090 m_dest = a_concept;
00091
00092 m_destID = m_dest->GetID();
00093 }
00094 }
00095
00096 bool CSemanticLink::Load(FILE *a_fp,
00097 CConceptMap &a_conceptMap)
00098 {
00099 if (!a_fp)
00100 {
00101 return false;
00102 }
00103
00104 fread(&m_sourceID, sizeof(SemanticID), 1, a_fp);
00105
00106 fread(&m_destID, sizeof(SemanticID), 1, a_fp);
00107
00108 fread(&m_linkID, sizeof(SemanticID), 1, a_fp);
00109
00110 fread(&m_type, sizeof(RelationType), 1, a_fp);
00111
00112 CSemanticConcept *l_concept = NULL;
00113
00114 l_concept = a_conceptMap.Lookup(m_sourceID);
00115
00116 if (!l_concept)
00117 {
00118 printf("error linking source concept [%d]\n", (int)m_sourceID);
00119
00120 return false;
00121 }
00122
00123 m_source = l_concept;
00124
00125 l_concept = a_conceptMap.Lookup(m_destID);
00126
00127 if (!l_concept)
00128 {
00129 printf("error linking dest concept [%d]\n", (int)m_destID);
00130
00131 return false;
00132 }
00133
00134 m_dest = l_concept;
00135
00136 m_source->AddLink(this, m_type);
00137
00138 m_dest->AddBackwardLink(this, m_type);
00139
00140 return true;
00141 }
00142
00143