;; Lexicon {ADJ,1} ADJ::ADJ |: ["red"] -> ["roja"] ( (X1::Y1) ((x0 form) = red) ((y0 agr num) = sg) ((y0 agr gen) = fem) ) ;; Grammar {S,1} S::S : [NP VP] -> [NP VP] ( (X1::Y1) (X2::Y2) (x0 = x2) ((y1 case) = nom) ; subj it !-> la/lo ((y1 agr) = (x1 agr)) ; ((y2 agr) = (y1 agr)) ((y2 tense) = (x2 tense)) ) {NP,8} NP::NP : [DET ADJ N] -> [DET N ADJ] ( (X1::Y1) (X2::Y3) (X3::Y2) ((x0 det) = x1) ((x0 mod) = x2) (x0 = x3) (y0 = x0) (y1 == (y0 det)) (y3 == (y0 mod)) (y2 = y0) ) Methods required to manipulate rules: ************************************* (assumes a methods CreateConstraint that takes care of what feature and value goes into the constraint. If delta set is empty, create a new feature name that does not already exist in the current feature set. have a int CreateNewFeature() method, which generates (feat_N = +) * Need to keep track of all the feature names used by the grammar and lexicon * Use a global counter (feat_count), maybe stored at the beginning of the grammar and lexicon, so that the RR module will always know what is the next feature name that is available to the system.) **************************************************************************** InsertValConstraint(Rule*, string Constraint) ;; Lex (y0) and Gra (given index) ;; but it would probably be more useful InsertValConstraint(int Index, string Feat, string/int Equal, string Val); ;; have this as a method of the Rule class, in which case, I don't need ;; to pass a pointer to the Rule (see TrRule.cpp and TestRuleManipulation.cpp) ;; This is necessary when postulating a new feature (feat_1 say). ;; Example: you saw the woman ' viste la mujer ' viste a la mujer ;; (rule operation RR5 / error 2.a.2: add, +Wc(woman), -rule). ;; Context: delta set is empty, adding ((y0 feat_j) = +) to woman. ;; For the grammar rules, before calling this method, variable instantiation ;; needs to happen: ;; given POS of corrected word (WiC) (or just the ParseTree), ;; instantiate it in the RHS of the rule. For example, for the rule above ;; (S::S : [NP VP] -> [NP VP]), we'd need to parse the RHS [NP VP] and ;; determine that NP(Wc) corresponds to y1 and VP(WiC) corresponds to y2 InsertAgrConstraint(Rule*, string Constraint) ;; Gra only InsertAgrConstraint(int Yi, int Yj, string Feat_i, string Feat_j, string/int Equal) ;; Feat_i = Feat_j, when ((Y1 num) = (Y2 num)) ;; Both Feat could be empty (Y1 = Y0) ;; one could have a value while the other is empty: ;; ((X0 DET) = X1) ;; (Y1 == (Y0 DET) ;; be careful with parens!!! no feature, no paren! ;; have a Rule checker! ;; maybe this is already implemented by the ParseTree class string POSforWord(Parse*, string WiC) ;; it returns the POS that corresponds to WiC int VariableInstantiation(Rule*, POS) ;; it return the Y index for POS in RHS of Rule ;; given POS of corrected word (leyo-WiC) or clue word (ella-Wc) ;; instantiate them in the RHS of the rule. For example, for the rule above ;; (S::S : [NP VP] -> [NP VP]), we'd need to parse the RHS [NP VP] and ;; determine that NP(Wc) corresponds to y1 and VP(WiC) corresponds to y2 GetConstraintsForIndex(int Index); ;; to see if there are already any constraints for that index DeleteConstraints(int Index) ; Gra & Lex: deletes all the constraints for Index DeleteValConstraint(Rule*, Constraint) ; Gra (& Lex?) DeleteValConstraint(int Index, Feat, Val) ;; don't care what's the Equal type, I don't think... DeleteAgrConstraint(int Index1, int Index2, Feat) ;; feat could be in both sides, or just in one. ;; harder to detect, system with morphology only. ;; the work here is to know what constraint needs to be deleted ;; need to have a ConstraintDetection which would have to find the index ;; corresponding to the Wi POS and then parse all the constraints to see ;; if there is one for index yN with a feature value (for an example, ;; see task 11) ;; Add LexEntry AddNewLexEntry(SLWord, CTLWord, POS) ;; Lex ;; need to have the ParseTree ;; increment counter for that POS to obtain RefinedRule ID ;; int NextAvailableID(POS) ;; look up morpho features from maco-girat or else have reasonable ;; defaults for each POS ;; Bifurcate ;; general method both for sense and form (Task 8) RefinedEntry AddNewInstance(OriginalRule*, CTLWord) ;; Lex ;; add new sense: ;; need to parse the second line of the rule (ADJ::ADJ |: ["red"] -> ["roja"]) ;; in order to extract TLWord and replace it by TLWord ;; increment counter for that POS to obtain RefinedRule ID ;; int NextAvailableID(POS) ;; add new form: ;; need to parse the second line of the rule (ADJ::ADJ |: ["caer"] -> ["caerse"]) ;; in order to extract TLWord and replace it by TLWord ;; increment counter for that POS to obtain RefinedRule ID ;; int NextAvailableID(POS) RefinedEntry ModifyTLWord(OriginalEntry*, CTLWord) ;;RefinedEntry ModifySLWord(OriginalEntry*, SLWord) ;; RR only touches the y-side AddConstraint(Entry*, Constraint) ;; similat to SetConstraint in TrRule // maybe have a more general method (AddString2RuleRHS) ;; Gra & Lex RefinedRule AddWord2RuleRHS(ParseTree*, string Word, int Position) ;; Ex: ["a" NP] ;; if a Word is added to a gram rule, it's added in quotes, which is not ;; true for a lex entry ;; this can also be for a lexical entry (*[gustaria] -> [me gustaria]) ;; format for LEx and Gra is slightly differnt, probably need to write two ;; spearate methods or have a flag for lexical rules, say. ;; this will also call UpdateIndices(int Position) ;; if (i > Position) i = i+1; ;; updates all the indices after the one where the new Word/POS was inserted RefinedRule AddPOS2RuleRHS(ParseTree*, string POS, int Position) ;; Gra ;; Before I can call this method, need to check that the correction word (WiC) ;; is not aligned to any ;; word in the SLSentence, otherwise, it would be a lexical refinement ;; Need to check in the grammar to make sure that the final POS sequence does ;; not exist. Tricky: first need to find what is the POS of the correction ;; (WiC), and then need to see if there is any rule with a RHS that contains ;; a POS sequence with the WiC POS in the right position ;; If it's not already there, extract the rule that has been applied before ;; (stored in ParseTree) and add "string" to the right position. ;; increment counter for that POS to obtain RefinedRule ID ;; -> Index Rules by RHS POS sequence!!! ;; Careful: this causes the y-indexes to switch and thus this method ;; needs to call a ConstraintChecking method that knows in which positions ;; things used to be and what positions things have moved to in order to ;; adjust the constraints. ;; This probably requires having a vector with the original POS sequence and ;; the refined POS sequence (in the RHS of the rule), and parsing the ;; constraints to find the relevant indexes ;; for this maybe it would help to store constraints by index. ;; vector XConstraints ;; vector YConstriants <- ;; this will also call UpdateIndices(int Position) ;; if (i > Position) i = i+1; ;; updates all the indices after the one where the new Word/POS was inserted ;; Change of Word order MoveConstituent(string Constit, init FinalPosition) ;; Constit2Move can either be a "word" or a POS ;; the initial order is given by the original rule RHS. ;; or I could have that method directly modify the rule (would need to make ;; a copy of the original rule before calling the MoveConstit method ;; first also check that final POS sequence is not already the RHS of any ;; rule (this is tricky since it might not be the RHS of any rule, and still ;; be allowed by the grammar by combining a couple of rules... think about this. ;; if final POS sequence is not in grammar: ;; example N ADJ -> ADJ N ;; if "gran"(ADJ) is moved to position 1 (or 0), then the method call would be ;; RefinedRule ChangePOSOrder(pPT, ADJ, 1) ;; then it would extract the origianl rule ID (NP,8) and find that the ADJ in ;; the RHS is in position 2 (y2), so it would know to move it to position 1 ;; (=final position), namely, before the noun. ;; increment counter for that POS to obtain RefinedRule ID ModifyConstraint? - I don't think this is something the RR module will do NOTE: Most of these methods, require that other adjustments are made to the grammar or the lexicon as well, so I need to have a PropagateRefinement method that maybe needs to become several ones depending on the kind of propagation required. For example: after having added "a" to the VP rule ([VP "a" NP]), then we need to be able to discriminate between the original rule(= -) and the new rule (=c +), so a newfeature needs to be created and added to both rules, as well as to the lexical entry that was the clue word, if any (in this case, woman/mujer (= +)). One kind of propagation is CreateBlockingConstraint, which is of the sort (feat_n = -), and which should instantiate with all the underspecified lexical entries.