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