diff options
author | Olivier R <dicollecte@free.fr> | 2012-02-14 17:45:58 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2012-02-14 17:45:58 +0100 |
commit | 43086af5853a5d1a64ca79395bec8a027755e4d2 (patch) | |
tree | d372c54e7311da188449de3cfdd80c3f9a0c0cc5 | |
parent | 1e9fce20ad8656e0b8f3d776da7ec4f1c73364a6 (diff) |
back references, no suggestion, and misc.
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | doc/syntax.txt | 12 | ||||
-rw-r--r-- | pythonpath/lightproof_compile___implname__.py | 4 | ||||
-rw-r--r-- | pythonpath/lightproof_impl___implname__.py | 22 |
5 files changed, 37 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cebebd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*.oxt
\ No newline at end of file @@ -1,3 +1,9 @@ +2012-02-12 Olivier Ronez <dicollecte.org>: + - back references in explanations, eg. # \1 should be... + - display message without suggestion, eg. # foo -> _ # Message + - function word() returns '' instead of None + - add .gitignore + 2012-02-04 László Németh <nemeth@numbertext.org>: - fix multiple suggestions, the problem reported by Yakov Reztsov @@ -5,7 +11,7 @@ - Lightproof editor (rule development extension for LibreOffice) - use template and config system, based on the work of Olivier Ronez, author of French - grammar checker Dicollecte. + grammar checker Grammalecte. - code cleanups - move user code to different module to speed up its load (submodules use Python pyc format) diff --git a/doc/syntax.txt b/doc/syntax.txt index 12da666..afd122c 100644 --- a/doc/syntax.txt +++ b/doc/syntax.txt @@ -90,12 +90,24 @@ foo\w+ -> = '"' + \0.upper() + '"' # With uppercase letters and quoation marks All words beginning with "foo" will be recognized, and the suggestion is the uppercase form of the string with ASCII quoation marks: eg. foom -> "FOOM". +== No suggestion == + +You can display message without making suggestions. For this purpose, use a single character _ in the replacement field. + +Example: + +foobar -> _ # Message + == Longer explanations == Warning messages can contain optional URLs for longer explanations separated by "\n": (your|her|our|their)['’]s -> \1s # Possessive pronoun: \n http://en.wikipedia.org/wiki/Possessive_pronoun +== Back references in explanations == + +(fooo) bar -> foo bar # “\1” should be: + == Default variables == LOCALE diff --git a/pythonpath/lightproof_compile___implname__.py b/pythonpath/lightproof_compile___implname__.py index 7c37bf4..376f040 100644 --- a/pythonpath/lightproof_compile___implname__.py +++ b/pythonpath/lightproof_compile___implname__.py @@ -44,7 +44,9 @@ def mysplit(s, line, oldline, debug): c = c.start(c.lastindex - 1) except: c = c.start() - com = prepare_for_eval(s[c+2:].strip()) + com = s[c+2:].strip() + if com[0:1] == "=": + com = prepare_for_eval(com) s = s[:c] m1 = re.search("<-", s) m2 = re.search("->", s) diff --git a/pythonpath/lightproof_impl___implname__.py b/pythonpath/lightproof_impl___implname__.py index e18d9dd..6e572d6 100644 --- a/pythonpath/lightproof_impl___implname__.py +++ b/pythonpath/lightproof_impl___implname__.py @@ -46,7 +46,7 @@ def onlymorph(st): # return the last matched substring def _morph(rLoc, word, pattern, all, onlyaffix): global analyses - if word == None: + if not word: return None if word not in analyses: x = spellchecker.spell(u"<?xml?><query type='analyze'><word>" + word + "</word></query>", rLoc, ()) @@ -55,8 +55,8 @@ def _morph(rLoc, word, pattern, all, onlyaffix): t = x.getAlternatives() if not t: t = [""] - analyses[word] = t[0] - a = analyses[word].split("</a>")[:-1] + analyses[word] = t[0].split("</a>")[:-1] + a = analyses[word] result = None p = re.compile(pattern) for i in a: @@ -78,14 +78,14 @@ def affix(rLoc, word, pattern, all=True): return _morph(rLoc, word, pattern, all, True) def spell(rLoc, word): - if word == None: + if not word: return None return spellchecker.isValid(word, rLoc, ()) # get the tuple of the stem of the word or an empty array def stem(rLoc, word): global stems - if word == None: + if not word: return [] if not word in stems: x = spellchecker.spell(u"<?xml?><query type='stem'><word>" + word + "</word></query>", rLoc, ()) @@ -99,7 +99,7 @@ def stem(rLoc, word): # get the tuple of the morphological generation of a word or an empty array def generate(rLoc, word, example): - if word == None: + if not word: return [] x = spellchecker.spell(u"<?xml?><query type='generate'><word>" + word + "</word><word>" + example + "</word></query>", rLoc, ()) if not x: @@ -112,7 +112,7 @@ def generate(rLoc, word, example): # get suggestions def suggest(rLoc, word): global suggestions - if word == None: + if not word: return word if word not in suggestions: x = spellchecker.spell("_" + word, rLoc, ()) @@ -126,14 +126,14 @@ def suggest(rLoc, word): def word(s, n): a = re.match("(?u)( [-.\w%%]+){" + str(n-1) + "}( [-.\w%%]+)", s) if not a: - return None + return '' return a.group(2)[1:] # get the (-)nth word of the input string or None def wordmin(s, n): a = re.search("(?u)([-.\w%%]+ )([-.\w%%]+ ){" + str(n-1) + "}$", s) if not a: - return None + return '' return a.group(1)[:-1] def calc(funcname, par): @@ -162,11 +162,15 @@ def proofread( nDocId, TEXT, LOCALE, nStartOfSentencePos, nSuggestedSentenceEndP iscap = (i[-1] and m.group(0)[0:1].isupper()) if i[1][0:1] == "=": aErr.aSuggestions = tuple(cap(eval(i[1][1:]).split("\n"), iscap, LOCALE)) + elif i[1] == "_": + aErr.aSuggestions = () else: aErr.aSuggestions = tuple(cap(m.expand(i[1]).split("\n"), iscap, LOCALE)) comment = i[2] if comment[0:1] == "=": comment = eval(comment[1:]) + else: + comment = m.expand(comment) aErr.aShortComment = comment.split("\\n")[0].strip() aErr.aFullComment = comment.split("\\n")[-1].strip() if "://" in aErr.aFullComment: |