;; ;; MODULE: objgraph.pp ;; ;; DESCRIPTION: this module contains the propagation patterns which ;; traverse obj-cd. ;; ;; PPs: ;; AbstractAdjacency ;; ;; AddAlternative ;; AbstractParts ;; ;; LearnParts ;; LearnRepetition ;; ;; GetNumParts ;; GetLabeledPartBody ;; GetRepetitionParts ;; Repetition ;; LookUpVertex ;; ToBeExtended ;; ;; History: ;; Cristina Lopes, Dec. 92 - created from an old version ;; of cd-learn. ;; ;; ;; AbstractAdjacency (*in* char *name, *in* Cd_graph *cd_out) ;; ;; WHAT : abstract an adjacency from this object ;; INDEP: 1 ;; *interface* void AbstractAdjacency (char *name, Cd_graph *cd_out) *from* Object *to-stop* DNone DTerminal DConstruction DRepetition *primary* DNone (@ cerr <<" Error: objects of class "<< name << " should be described.\n"; exit(4); @) *primary* DTerminal (@ Any_vertex_List *vtxl = new Any_vertex_List(); cd_out->NewConstruction(name, vtxl); cout << ";;Warning: object vertex \" "<< name <<"\" is learned as construction class\n\n"; @) *primary* DConstruction (@ Any_vertex_List *vtxl = 0; // Abstract the part objects this->AbstractParts (vtxl, name); // Insert this learned construction in cd_out cd_out->NewConstruction(name, vtxl); // Recursively learn the part objects this->LearnParts (cd_out); @) *primary* DRepetition (@ int is = 0; char* nname = new (char[strlen(name) + strlen("element") + 2 ]); sprintf(nname, "%s_elements", name); // create an construction adjacency Vertex* iVertex = new Vertex(new Ident(nname)); Term* iTerm = new Normal(); iTerm->set_vertex(iVertex); // Create an alternation adjacency if needed Adjacency* iAdj = 0; cd_out->LookUpAdjacency (nname, iAdj); if (iAdj) { iAdj->Alternation (is); if (is) { cerr << "conflicted type for class " << nname <<"\n"; exit(1); } this->AddAlternative (iAdj); } else { cd_out->GetNumAdjacencies (is); if (is == 0) cout << ";;Warning: the first production in learned cd " << "may not be repetition\n" << ";; production, move any repetition production of the " << "learned cd as\n;; your first production.\n\n"; cd_out->NewRepetition (name, iTerm, parts); Alternat_ns* iAlt = new Alternat_ns(); Term_Bar_list* iAlt_list = new Term_Bar_list(); iAlt->set_alternat_ns(iAlt_list); iAlt->set_construct_ns(new Any_vertex_List()); iAdj = new Adjacency(iVertex, iAlt); cd_out->AppendNewAdjacency (iAdj); if (!this->get_parts()) { cout << "Error: the first appearance of a list must not be empty" << endl; exit(1); } this->AddAlternative (iAdj); } this->LearnRepetition (cd_out); @) ;; ;; AddAlternative (*in* Adjacency *adj) ;; ;; WHAT : get the next alternative of the repetition object and abstract ;; it. ;; INDEP: 1 ;; *interface* void AddAlternative (Adjacency *adj) *from* DRepetition *to-stop* Object *primary* Object (@ Ident *name; this->GetIdentifier (name); adj->AddAlternative (name->get_val()); @) ;; ;; AbstractParts (*out* Any_vertex_List *&vl, *in* char *name) ;; ;; WHAT : abstract the part objects of this construction object. ;; INDEP: 1 ;; *interface* void AbstractParts (Any_vertex_List *&vl, char *cname) *from* DConstruction *to-stop* Labeled_part_List *primary* Labeled_part_List (@ // Get the top level parts Labeled_part_list_iterator next_part(*this); Labeled_part_ part; Ident* name = 0; int label = 0; // Alocate vertex_list here Any_vertex_List* new_vertices = new Any_vertex_List(); while (part = next_part()) { (part->get_label())->GetIdentifier(name); new_vertices->CheckDupLabel(name, label); if (!(label)) { Opt_labeled_term* labeln = new Labeled(name); Term* new_term = new Normal(); (part->get_obj())->GetIdentifier (name); new_term->set_vertex(new Vertex (new Ident(name->get_val()))); labeln->set_vertex(new_term); new_vertices->append(labeln); } else { cerr << "Error: duplicate label name <" <get_val() << "> in the input object.\n"; exit (1); } } vl = new_vertices; @) ;; ;; LearnParts (*in* Cd_graph *cd_out) ;; ;; WHAT : iteratively, learn the part objects of this object. ;; INDEP: 1 ;; *interface* void LearnParts (Cd_graph *cd_out) *from* Object *to-stop* Labeled_part *primary* Labeled_part (@ cd_out->Learn(this->get_obj()); @) ;; ;; LearnRepetition (*in* Cd_graph *cd_out) ;; ;; WHAT : learn the objects in the object repetition list. ;; INDEP: 1 ;; *interface* void LearnRepetition (Cd_graph *cd_out) *from* DRepetition *to-stop* Object *primary* Object (@ cd_out->Learn (this); @) ;; ;; GetNumParts (*out* int &n) ;; ;; WHAT : return the number of parts of this object. ;; INDEP: 1 ;; *interface* void GetNumParts (int &n) *from* Object *to-stop* DConstruction *bypassing* => Obj_description, DRepetition *before* Object (@ n = 0; @) *primary* DConstruction (@ n = parts->list_length(); @) ;; ;; GetLabeledPartBody (*out* Labeled_part_List *&p) ;; ;; WHAT : return the part objects list of this construction object. ;; INDEP: 1 ;; ;; Comment: see the *C* interface at the end of this module. ;; *interface* void v_GetLabeledPartBody (Labeled_part_List *&p) *from* Object *to-stop* DConstruction *primary* DConstruction (@ p = this->get_parts(); @) ;; ;; GetRepetitionParts (*out* Object_Comma_list *&rp) ;; ;; WHAT : get the repetition part of a repetition object. ;; INDEP: 1 ;; *interface* void GetRepetitionParts (Object_Comma_list *&rp) *from* Object *to-stop* DRepetition *bypassing* -> *, *, Object *primary* DRepetition (@ rp = this->get_parts(); @) ;; ;; Repetition (*out* int &is) ;; ;; WHAT : test if it's a repetition object. ;; INDEP: 1 ;; *interface* void Repetition (int &is) *from* Object *to-stop* DRepetition *bypassing* -> *, *, Object *before* Object (@ is = 0; @) *primary* DRepetition (@ is = 1; @) ;; ;; LookUpVertex (*in* char *name, *out* Labeled_part *&part) ;; ;; WHAT : search a labeled part with the given name in the ;; Labeled_part_List. ;; INDEP: 1 ;; *interface* void LookUpVertex (char *name, Labeled_part *&part) *from* Object *to-stop* Labeled_part_List *before* Object (@ part = 0; @) *primary* Labeled_part_List (@ Labeled_part_list_iterator next_label(*this); Ident *nm; while (part = next_label()) { part->GetLabelIdent (nm); if (!(strcmp(name, nm->get_val()))) break; } @) ;; ;; ToBeExtended (*out* int &is) ;; ;; WHAT : extend all objects except DNone ones. ;; INDEP: 1 ;; *interface* void ToBeExtended (int &is) *from* Object *to-stop* DNone *bypassing* -> *, *, Object *before* Object (@ is = 1; @) *primary* DNone (@ is = 0; @) *C* (@ Labeled_part_List *Object::GetLabeledPartBody() { Labeled_part_List *p = 0; this->v_GetLabeledPartBody (p); return (p); } @)