00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00020 #ifndef _PRED_DECODER
00021
00022 #define _PRED_DECODER
00023
00024 #include <string>
00025
00026 #include "qstring.h"
00027 #include "qregexp.h"
00028
00029 #include "concept.h"
00030 #include "concept_map.h"
00031 #include "textid_map.h"
00032 #include "id_generator.h"
00033 #include "relation_type.h"
00034 #include "link_map.h"
00035 #include "debug.h"
00036
00037
00039 class CPredicateDecoder
00040 {
00041 public:
00043 void DecodePredicateText(const std::string &a_string,
00044 CTextIDMap &a_idMap,
00045 CSemanticIDGenerator &a_idGen,
00046 CConceptMap &a_conceptMap,
00047 CLinkMap &a_linkMap)
00048 {
00049 QRegExp l_regex("\\((\\w+)\\s+\\\"(.+)\\\"\\s+\\\"(.+)\\\"");
00050
00051 if (l_regex.search(a_string) >= 0)
00052 {
00053 QString l_relationship;
00054 QString l_source;
00055 QString l_destination;
00056
00057 l_relationship = l_regex.cap(1);
00058 l_source = l_regex.cap(2);
00059 l_destination = l_regex.cap(3);
00060
00061 RelationType l_relationType;
00062
00063 l_relationType = m_relationLookup.Lookup(
00064 l_relationship);
00065
00066 SemanticID l_sourceID;
00067
00068 l_sourceID = a_idMap.Lookup(l_source);
00069
00070 CSemanticConcept *l_srcConcept = NULL;
00071
00072 if (SEMANTIC_ID_NONE == l_sourceID)
00073 {
00074 l_srcConcept = new CSemanticConcept(
00075 l_source,
00076 &a_idGen,
00077 &a_idMap);
00078
00079 a_conceptMap.Store(l_srcConcept);
00080
00081 DPRINT("storing %s %d.\n",
00082 l_source.ascii(),
00083 l_relationType);
00084
00085 l_sourceID = l_srcConcept->GetID();
00086 }
00087 else
00088 {
00089 l_srcConcept =
00090 a_conceptMap.Lookup(l_sourceID);
00091 }
00092
00093 SemanticID l_destinationID;
00094
00095 l_destinationID = a_idMap.Lookup(l_destination);
00096
00097 CSemanticConcept *l_dstConcept = NULL;
00098
00099 if (SEMANTIC_ID_NONE == l_destinationID)
00100 {
00101 l_dstConcept = new CSemanticConcept(
00102 l_destination,
00103 &a_idGen,
00104 &a_idMap);
00105
00106 a_conceptMap.Store(l_dstConcept);
00107
00108 DPRINT("storing %s %d.\n",
00109 l_destination.ascii(),
00110 l_relationType);
00111
00112 l_destinationID = l_dstConcept->GetID();
00113 }
00114 else
00115 {
00116 l_dstConcept =
00117 a_conceptMap.Lookup(l_destinationID);
00118 }
00119
00120 CSemanticLink *l_link = NULL;
00121
00122 DPRINT("storing link\n");
00123
00124 l_link = new CSemanticLink();
00125
00126 l_link->SetSource(l_srcConcept);
00127 l_link->SetDest(l_dstConcept);
00128
00129 l_link->SetType(l_relationType);
00130
00131 l_link->SetID(a_idGen.Get());
00132
00133 a_linkMap.Store(l_link);
00134
00135 DPRINT("storing forward lnk\n");
00136
00137 l_srcConcept->AddLink(l_link,
00138 l_relationType);
00139
00140 DPRINT("storing bckward lnk\n");
00141
00142 l_dstConcept->AddBackwardLink(
00143 l_link, l_relationType);
00144 }
00145 }
00146
00148 CPredicateDecoder() {}
00149
00151 ~CPredicateDecoder() {}
00152
00153 private:
00155 CRelationTypeLookup m_relationLookup;
00156 };
00157
00158 #endif
00159