Commit b9ab6e0da0c2ed62f400b0b8f63322c5f9c0fc4c
1 parent
8d31a2c7
dodanie możliwości doklejania ">" do wyrażeń nawiasowych
git-svn-id: svn://svn.nlp.ipipan.waw.pl/morfeusz/trunk@336 ff4e3ee1-f430-4e82-ade0-24591c43f1fd
Showing
3 changed files
with
26 additions
and
11 deletions
fsabuilder/morfeuszbuilder/segrules/rules.py
... | ... | @@ -43,6 +43,9 @@ class SegmentRule(object): |
43 | 43 | |
44 | 44 | def getAdditionalAtomicRules4Generator(self): |
45 | 45 | raise NotImplementedError() |
46 | + | |
47 | + def makeShiftOrthRule(self): | |
48 | + pass | |
46 | 49 | |
47 | 50 | def __repr__(self): |
48 | 51 | return str(self) |
... | ... | @@ -83,6 +86,9 @@ class TagRule(SegmentRule): |
83 | 86 | |
84 | 87 | def isShiftOrthRule(self): |
85 | 88 | return self.shiftOrth |
89 | + | |
90 | + def makeShiftOrthRule(self): | |
91 | + self.shiftOrth = True | |
86 | 92 | |
87 | 93 | def getAtomicRules(self): |
88 | 94 | yield self |
... | ... | @@ -101,6 +107,9 @@ class UnaryRule(SegmentRule): |
101 | 107 | |
102 | 108 | def isShiftOrthRule(self): |
103 | 109 | return self.child.isShiftOrthRule() |
110 | + | |
111 | + def makeShiftOrthRule(self): | |
112 | + self.child.makeShiftOrthRule() | |
104 | 113 | |
105 | 114 | def getAtomicRules(self): |
106 | 115 | for leaf in self.child.getAtomicRules(): |
... | ... | @@ -127,6 +136,10 @@ class ComplexRule(SegmentRule): |
127 | 136 | for child in self.children: |
128 | 137 | for leaf in child.getAtomicRules(): |
129 | 138 | yield leaf |
139 | + | |
140 | + def makeShiftOrthRule(self): | |
141 | + for child in self.children: | |
142 | + child.makeShiftOrthRule() | |
130 | 143 | |
131 | 144 | class ConcatRule(ComplexRule): |
132 | 145 | |
... | ... |
fsabuilder/morfeuszbuilder/segrules/rulesParser.py
... | ... | @@ -149,12 +149,17 @@ class RulesParser(object): |
149 | 149 | ], |
150 | 150 | lineNum) |
151 | 151 | |
152 | + def _createNewParenWithShiftOrthRule(self, rule, lineNum, line, segtypesHelper): | |
153 | + rule.makeShiftOrthRule() | |
154 | + return rule | |
155 | + | |
152 | 156 | def _doParseOneLine(self, lineNum, line, segtypesHelper, filename): |
153 | 157 | rule = Forward() |
154 | 158 | tagRule = Word(alphanums+'_') |
155 | 159 | shiftOrthRule = Word(alphanums+'_') + Suppress('>') |
156 | 160 | parenRule = Suppress('(') + rule + Suppress(')') |
157 | - atomicRule = tagRule ^ shiftOrthRule ^ parenRule | |
161 | + parenWithShiftOrthRule = parenRule + Suppress('>') | |
162 | + atomicRule = tagRule ^ shiftOrthRule ^ parenWithShiftOrthRule ^ parenRule | |
158 | 163 | zeroOrMoreRule = atomicRule + Suppress('*') |
159 | 164 | oneOrMoreRule = atomicRule + Suppress('+') |
160 | 165 | optionalRule = atomicRule + Suppress('?') |
... | ... | @@ -169,11 +174,14 @@ class RulesParser(object): |
169 | 174 | # concatRule = OneOrMore(complexRule) |
170 | 175 | # else: |
171 | 176 | # concatRule = ZeroOrMore(shiftOrthRule) + tagRule |
172 | - rule << concatRule + Optional(CaselessLiteral('!weak')) | |
177 | + | |
178 | + rule << concatRule | |
179 | + completeRule = rule + Optional(CaselessLiteral('!weak')) | |
173 | 180 | |
174 | 181 | tagRule.setParseAction(lambda string, loc, toks: self._createNewTagRule(toks[0], False, lineNum, line, segtypesHelper)) |
175 | 182 | shiftOrthRule.setParseAction(lambda string, loc, toks: self._createNewTagRule(toks[0], True, lineNum, line, segtypesHelper)) |
176 | -# parenRule.setParseAction(lambda string, loc, toks: toks[0]) | |
183 | + parenWithShiftOrthRule.setParseAction(lambda string, loc, toks: self._createNewParenWithShiftOrthRule(toks[0], lineNum, line, segtypesHelper)) | |
184 | + parenRule.setParseAction(lambda string, loc, toks: toks[0]) | |
177 | 185 | zeroOrMoreRule.setParseAction(lambda string, loc, toks: rules.ZeroOrMoreRule(toks[0], lineNum)) |
178 | 186 | quantRule1.setParseAction(lambda string, loc, toks: self._createQuantRule1(toks[0], int(toks[1], 10), lineNum, line, segtypesHelper)) |
179 | 187 | quantRule2.setParseAction(lambda string, loc, toks: self._createQuantRule2(toks[0], int(toks[1], 10), int(toks[2], 10), lineNum, line, segtypesHelper)) |
... | ... | @@ -182,8 +190,8 @@ class RulesParser(object): |
182 | 190 | oneOrMoreRule.setParseAction(lambda string, loc, toks: rules.ConcatRule([toks[0], rules.ZeroOrMoreRule(toks[0], lineNum)], lineNum)) |
183 | 191 | oneOfRule.setParseAction(lambda string, loc, toks: rules.OrRule(list(toks), lineNum)) |
184 | 192 | concatRule.setParseAction(lambda string, loc, toks: toks[0] if len(toks) == 1 else rules.ConcatRule(list(toks), lineNum)) |
185 | - rule.setParseAction(lambda string, loc, toks: toks[0].setWeak(len(toks) == 2)) | |
186 | - parsedRule = pyparseString.pyparseString(rule, lineNum, line, filename)[0] | |
193 | + completeRule.setParseAction(lambda string, loc, toks: toks[0].setWeak(len(toks) == 2)) | |
194 | + parsedRule = pyparseString.pyparseString(completeRule, lineNum, line, filename)[0] | |
187 | 195 | # print parsedRule, '-->', parsedRule.transformToGeneratorVersion() |
188 | 196 | return parsedRule |
189 | 197 | |
... | ... |
nbproject/configurations.xml
... | ... | @@ -859,22 +859,16 @@ |
859 | 859 | ex="false" |
860 | 860 | tool="1" |
861 | 861 | flavor2="4"> |
862 | - <ccTool flags="1"> | |
863 | - </ccTool> | |
864 | 862 | </item> |
865 | 863 | <item path="morfeusz/deserialization/morphInterps/InterpretedChunksDecoder4Analyzer.cpp" |
866 | 864 | ex="false" |
867 | 865 | tool="1" |
868 | 866 | flavor2="4"> |
869 | - <ccTool flags="1"> | |
870 | - </ccTool> | |
871 | 867 | </item> |
872 | 868 | <item path="morfeusz/deserialization/morphInterps/InterpretedChunksDecoder4Generator.cpp" |
873 | 869 | ex="false" |
874 | 870 | tool="1" |
875 | 871 | flavor2="4"> |
876 | - <ccTool flags="1"> | |
877 | - </ccTool> | |
878 | 872 | </item> |
879 | 873 | <item path="morfeusz/fsa/const.cpp" ex="false" tool="1" flavor2="4"> |
880 | 874 | </item> |
... | ... |