(self, data, style)
| 81 | return head.strip() |
| 82 | |
| 83 | def word_exchange (self, data, style): |
| 84 | if not data: |
| 85 | return '' |
| 86 | exchange = data.get('exchange') |
| 87 | exchange = stardict.tools.exchange_loads(exchange) |
| 88 | if not exchange: |
| 89 | return '' |
| 90 | part = [] |
| 91 | last = '' |
| 92 | count = 0 |
| 93 | for k in ('p', 'd', 'i', '3'): |
| 94 | p = exchange.get(k) |
| 95 | if p: |
| 96 | count += 1 |
| 97 | if p != last: |
| 98 | part.append(u'%s'%p) |
| 99 | last = p |
| 100 | if count < 4: |
| 101 | text = '' |
| 102 | else: |
| 103 | text = ', '.join(part) |
| 104 | origin = '' |
| 105 | t = exchange.get('0', '') |
| 106 | if t.lower() == data['word'].lower(): |
| 107 | del exchange['0'] |
| 108 | if '1' in exchange: |
| 109 | del exchange['1'] |
| 110 | if '0' in exchange: |
| 111 | t = exchange['0'] |
| 112 | if t != data['word']: |
| 113 | origin = t |
| 114 | derive = '' |
| 115 | if '1' in exchange: |
| 116 | t = exchange['1'] |
| 117 | p = [] |
| 118 | if 'p' in t and 'd' in t: |
| 119 | derive = u'过去式和过去分词' |
| 120 | elif 's' in t and '3' in t: |
| 121 | derive = u'第三人称单数' |
| 122 | else: |
| 123 | for x in ('i', 'p', 'd', '3', 's', 'r', 't'): |
| 124 | if x in t: |
| 125 | derive = stardict.tools._exchanges[x] |
| 126 | break |
| 127 | if derive: |
| 128 | origin = data['word'] + u' 是 ' + origin + u' 的' + derive |
| 129 | better = '' |
| 130 | if ('r' in exchange) and ('t' in exchange): |
| 131 | better = exchange['r'] + ', ' + exchange['t'] |
| 132 | lines = [] |
| 133 | # if text and (not exchange.get('1', '') in ('p', 'd', 'i', '3', 'pd', 'dp')): |
| 134 | if text: |
| 135 | if style == 0: |
| 136 | lines.append(u'[时态] ' + text) |
| 137 | else: |
| 138 | lines.append(u'时态: ' + text) |
| 139 | if better and (not exchange.get('1', '') in ('r', 't')): |
| 140 | if style == 0: |
no test coverage detected