def doProofreading(self, nDocId, rText, rLocale, nStartOfSentencePos, \
        nSuggestedSentenceEndPos, rProperties):
        aRes = uno.createUnoStruct( "com.sun.star.linguistic2.ProofreadingResult" )
        aRes.aDocumentIdentifier = nDocId
        aRes.aText = rText
        aRes.aLocale = rLocale
        aRes.nStartOfSentencePosition = nStartOfSentencePos
        aRes.nStartOfNextSentencePosition = nSuggestedSentenceEndPos
        aRes.aProperties = ()
        aRes.xProofreader = self
        aRes.aErrors = ()
        # PATCH FOR LO 4
        # Fix for http://nabble.documentfoundation.org/Grammar-checker-Undocumented-change-in-the-API-for-LO-4-td4030639.html
        if nStartOfSentencePos != 0:
            return aRes
        aRes.nStartOfNextSentencePosition = len(rText)
        # END OF PATCH

        if len(rProperties) > 0 and rProperties[0].Name == "Update":
            try:
                import lightproof_compile_${implname}
                try:
                    code = lightproof_compile_${implname}.c(rProperties[0].Value, rLocale.Language, True)
                except Exception as e:
                    aRes.aText, aRes.nStartOfSentencePosition = e
                    return aRes
                path = lightproof_impl_${implname}.get_path()
                f = open(path.replace("_impl", ""), "w")
                f.write("dic = %s" % code["rules"])
                f.close()
                if pkg in lightproof_impl_${implname}.langrule:
                    mo = lightproof_impl_${implname}.langrule[pkg]
                    reload(mo)
                    lightproof_impl_${implname}.compile_rules(mo.dic)
                    lightproof_impl_${implname}.langrule[pkg] = mo
                if "code" in code:
                    f = open(path, "r")
                    ft = f.read()
                    f.close()
                    f = open(path, "w")
                    f.write(ft[:ft.find("# [code]") + 8] + "\n" + code["code"])
                    f.close()
                    try:
                        reload(lightproof_impl_${implname})
                    except Exception as e:
                        aRes.aText = e.args[0]
                        if e.args[1][3] == "": # "expected an indented block" (end of file)
                            aRes.nStartOfSentencePosition = len(rText.split("\n"))
                        else:
                            aRes.nStartOfSentencePosition = rText.split("\n").index(e.args[1][3][:-1]) + 1
                        return aRes
                aRes.aText = ""
                return aRes
            except:
Пример #2
0
 def doProofreading(self, nDocId, rText, rLocale, nStartOfSentencePos, \
     nSuggestedSentenceEndPos, rProperties):
     aRes = uno.createUnoStruct( "com.sun.star.linguistic2.ProofreadingResult" )
     aRes.aDocumentIdentifier = nDocId
     aRes.aText = rText
     aRes.aLocale = rLocale
     aRes.nStartOfSentencePosition = nStartOfSentencePos
     aRes.nStartOfNextSentencePosition = nSuggestedSentenceEndPos
     aRes.aProperties = ()
     aRes.xProofreader = self
     aRes.aErrors = ()
     if len(rProperties) > 0 and rProperties[0].Name == "Update":
         try:
             import lightproof_compile_${implname}
             try:
                 code = lightproof_compile_${implname}.c(rProperties[0].Value, rLocale.Language, True)
             except Exception as e:
                 aRes.aText, aRes.nStartOfSentencePosition = e
                 return aRes
             path = lightproof_impl_${implname}.get_path()
             f = open(path.replace("_impl", ""), "w")
             f.write("dic = %s" % code["rules"])
             f.close()
             if pkg in lightproof_impl_${implname}.langrule:
                 mo = lightproof_impl_${implname}.langrule[pkg]
                 reload(mo)
                 lightproof_impl_${implname}.compile_rules(mo.dic)
                 lightproof_impl_${implname}.langrule[pkg] = mo
             if "code" in code:
                 f = open(path, "r")
                 ft = f.read()
                 f.close()
                 f = open(path, "w")
                 f.write(ft[:ft.find("# [code]") + 8] + "\n" + code["code"])
                 f.close()
                 try:
                     reload(lightproof_impl_${implname})
                 except Exception as e:
                     aRes.aText = e.args[0]
                     if e.args[1][3] == "": # "expected an indented block" (end of file)
                         aRes.nStartOfSentencePosition = len(rText.split("\n"))
                     else:
                         aRes.nStartOfSentencePosition = rText.split("\n").index(e.args[1][3][:-1]) + 1
                     return aRes
             aRes.aText = ""
             return aRes
         except:
Пример #3
0
    def doProofreading(self, nDocId, rText, rLocale, nStartOfSentencePos, \
        nSuggestedSentenceEndPos, rProperties):
        aRes = uno.createUnoStruct( "com.sun.star.linguistic2.ProofreadingResult" )
        aRes.aDocumentIdentifier = nDocId
        aRes.aText = rText
        aRes.aLocale = rLocale
        aRes.nStartOfSentencePosition = nStartOfSentencePos
        aRes.nStartOfNextSentencePosition = nSuggestedSentenceEndPos
        aRes.aProperties = ()
        aRes.xProofreader = self
        aRes.aErrors = ()
        # PATCH FOR LO 4
        # Fix for http://nabble.documentfoundation.org/Grammar-checker-Undocumented-change-in-the-API-for-LO-4-td4030639.html
        if nStartOfSentencePos != 0:
            return aRes
        aRes.nStartOfNextSentencePosition = len(rText)
        # END OF PATCH
        if len(rProperties) > 0 and rProperties[0].Name == "Update":
            try:
                import lightproof_compile_pt_BR
                try:
                    code = lightproof_compile_pt_BR.c(rProperties[0].Value, rLocale.Language, True)
                except Exception as e:
                    aRes.aText, aRes.nStartOfSentencePosition = e
                    return aRes
                path = lightproof_impl_pt_BR.get_path()
                f = open(path.replace("_impl", ""), "w")
                f.write("dic = %s" % code["rules"])
                f.close()
                if pkg in lightproof_impl_pt_BR.langrule:
                    mo = lightproof_impl_pt_BR.langrule[pkg]
                    reload(mo)
                    lightproof_impl_pt_BR.compile_rules(mo.dic)
                    lightproof_impl_pt_BR.langrule[pkg] = mo
                if "code" in code:
                    f = open(path, "r")
                    ft = f.read()
                    f.close()
                    f = open(path, "w")
                    f.write(ft[:ft.find("# [code]") + 8] + "\n" + code["code"])
                    f.close()
                    try:
                        reload(lightproof_impl_pt_BR)
                    except Exception as e:
                        aRes.aText = e.args[0]
                        if e.args[1][3] == "": # "expected an indented block" (end of file)
                            aRes.nStartOfSentencePosition = len(rText.split("\n"))
                        else:
                            aRes.nStartOfSentencePosition = rText.split("\n").index(e.args[1][3][:-1]) + 1
                        return aRes
                aRes.aText = ""
                return aRes
            except:
                if 'PYUNO_LOGLEVEL' in os.environ:
                    print(traceback.format_exc())

        l = rText[aRes.nStartOfNextSentencePosition:aRes.nStartOfNextSentencePosition+1]
        while l == " ":
            aRes.nStartOfNextSentencePosition = aRes.nStartOfNextSentencePosition + 1
            l = rText[aRes.nStartOfNextSentencePosition:aRes.nStartOfNextSentencePosition+1]
        if aRes.nStartOfNextSentencePosition == nSuggestedSentenceEndPos and l!="":
            aRes.nStartOfNextSentencePosition = nSuggestedSentenceEndPos + 1
        aRes.nBehindEndOfSentencePosition = aRes.nStartOfNextSentencePosition

        try:
            aRes.aErrors = lightproof_impl_pt_BR.proofread( nDocId, rText, rLocale, \
                nStartOfSentencePos, aRes.nBehindEndOfSentencePosition, rProperties)
        except Exception as e:
            if len(rProperties) > 0 and rProperties[0].Name == "Debug" and len(e.args) == 2:
                aRes.aText, aRes.nStartOfSentencePosition = e
            else:
                if 'PYUNO_LOGLEVEL' in os.environ:
                    print(traceback.format_exc())
        return aRes
Пример #4
0
    def doProofreading(self, nDocId, rText, rLocale, nStartOfSentencePos, \
        nSuggestedSentenceEndPos, rProperties):
        import lightproof_impl_pt_BR
        currentContext = uno.getComponentContext()
        if lightproof_impl_pt_BR.SMGR == None:
            lightproof_impl_pt_BR.SMGR = currentContext.ServiceManager
            lightproof_impl_pt_BR.spellchecker = \
                lightproof_impl_pt_BR.SMGR.createInstanceWithContext("com.sun.star.linguistic2.SpellChecker", currentContext)
        lightproof_handler_pt_BR.load(currentContext)
        aRes = uno.createUnoStruct(
            "com.sun.star.linguistic2.ProofreadingResult")
        aRes.aDocumentIdentifier = nDocId
        aRes.aText = rText
        aRes.aLocale = rLocale
        aRes.nStartOfSentencePosition = nStartOfSentencePos
        aRes.nStartOfNextSentencePosition = nSuggestedSentenceEndPos
        aRes.aProperties = ()
        aRes.xProofreader = self
        aRes.aErrors = ()
        # PATCH FOR LO 4
        # Fix for http://nabble.documentfoundation.org/Grammar-checker-Undocumented-change-in-the-API-for-LO-4-td4030639.html
        if nStartOfSentencePos != 0:
            return aRes
        aRes.nStartOfNextSentencePosition = len(rText)
        # END OF PATCH
        if len(rProperties) > 0 and rProperties[0].Name == "Update":
            try:
                import lightproof_compile_pt_BR
                try:
                    code = lightproof_compile_pt_BR.c(rProperties[0].Value,
                                                      rLocale.Language, True)
                except Exception as e:
                    aRes.aText, aRes.nStartOfSentencePosition = e
                    return aRes
                path = lightproof_impl_pt_BR.get_path()
                f = open(path.replace("_impl", ""), "w")
                f.write("dic = %s" % code["rules"])
                f.close()
                if pkg in lightproof_impl_pt_BR.langrule:
                    mo = lightproof_impl_pt_BR.langrule[pkg]
                    reload(mo)
                    lightproof_impl_pt_BR.compile_rules(mo.dic)
                    lightproof_impl_pt_BR.langrule[pkg] = mo
                if "code" in code:
                    f = open(path, "r")
                    ft = f.read()
                    f.close()
                    f = open(path, "w")
                    f.write(ft[:ft.find("# [code]") + 8] + "\n" + code["code"])
                    f.close()
                    try:
                        reload(lightproof_impl_pt_BR)
                    except Exception as e:
                        aRes.aText = e.args[0]
                        if e.args[1][
                                3] == "":  # "expected an indented block" (end of file)
                            aRes.nStartOfSentencePosition = len(
                                rText.split("\n"))
                        else:
                            aRes.nStartOfSentencePosition = rText.split(
                                "\n").index(e.args[1][3][:-1]) + 1
                        return aRes
                aRes.aText = ""
                return aRes
            except:
                if 'PYUNO_LOGLEVEL' in os.environ:
                    print(traceback.format_exc())

        l = rText[aRes.nStartOfNextSentencePosition:aRes.
                  nStartOfNextSentencePosition + 1]
        while l == " ":
            aRes.nStartOfNextSentencePosition = aRes.nStartOfNextSentencePosition + 1
            l = rText[aRes.nStartOfNextSentencePosition:aRes.
                      nStartOfNextSentencePosition + 1]
        if aRes.nStartOfNextSentencePosition == nSuggestedSentenceEndPos and l != "":
            aRes.nStartOfNextSentencePosition = nSuggestedSentenceEndPos + 1
        aRes.nBehindEndOfSentencePosition = aRes.nStartOfNextSentencePosition

        try:
            aRes.aErrors = lightproof_impl_pt_BR.proofread( nDocId, rText, rLocale, \
                nStartOfSentencePos, aRes.nBehindEndOfSentencePosition, rProperties)
        except Exception as e:
            if len(rProperties) > 0 and rProperties[0].Name == "Debug" and len(
                    e.args) == 2:
                aRes.aText, aRes.nStartOfSentencePosition = e
            else:
                if 'PYUNO_LOGLEVEL' in os.environ:
                    print(traceback.format_exc())
        return aRes
    def doProofreading(self, nDocId, rText, rLocale, nStartOfSentencePos, \
        nSuggestedSentenceEndPos, rProperties):
        aRes = uno.createUnoStruct(
            "com.sun.star.linguistic2.ProofreadingResult")
        aRes.aDocumentIdentifier = nDocId
        aRes.aText = rText
        aRes.aLocale = rLocale
        aRes.nStartOfSentencePosition = nStartOfSentencePos
        aRes.nStartOfNextSentencePosition = nSuggestedSentenceEndPos
        aRes.aProperties = ()
        aRes.xProofreader = self
        aRes.aErrors = ()
        if len(rProperties) > 0 and rProperties[0].Name == "Update":
            try:
                import lightproof_compile_pt_BR
                try:
                    code = lightproof_compile_pt_BR.c(rProperties[0].Value,
                                                      rLocale.Language, True)
                except Exception as e:
                    aRes.aText, aRes.nStartOfSentencePosition = e
                    return aRes
                path = lightproof_impl_pt_BR.get_path()
                f = open(path.replace("_impl", ""), "w")
                f.write("dic = %s" % code["rules"])
                f.close()
                if pkg in lightproof_impl_pt_BR.langrule:
                    mo = lightproof_impl_pt_BR.langrule[pkg]
                    reload(mo)
                    lightproof_impl_pt_BR.compile_rules(mo.dic)
                    lightproof_impl_pt_BR.langrule[pkg] = mo
                if "code" in code:
                    f = open(path, "r")
                    ft = f.read()
                    f.close()
                    f = open(path, "w")
                    f.write(ft[:ft.find("# [code]") + 8] + "\n" + code["code"])
                    f.close()
                    try:
                        reload(lightproof_impl_pt_BR)
                    except Exception as e:
                        aRes.aText = e.args[0]
                        if e.args[1][
                                3] == "":  # "expected an indented block" (end of file)
                            aRes.nStartOfSentencePosition = len(
                                rText.split("\n"))
                        else:
                            aRes.nStartOfSentencePosition = rText.split(
                                "\n").index(e.args[1][3][:-1]) + 1
                        return aRes
                aRes.aText = ""
                return aRes
            except:
                if 'PYUNO_LOGLEVEL' in os.environ:
                    print(traceback.format_exc())

        l = rText[nSuggestedSentenceEndPos:nSuggestedSentenceEndPos + 1]
        while l == " ":
            aRes.nStartOfNextSentencePosition = aRes.nStartOfNextSentencePosition + 1
            l = rText[aRes.nStartOfNextSentencePosition:aRes.
                      nStartOfNextSentencePosition + 1]
        if aRes.nStartOfNextSentencePosition == nSuggestedSentenceEndPos and l != "":
            aRes.nStartOfNextSentencePosition = nSuggestedSentenceEndPos + 1
        aRes.nBehindEndOfSentencePosition = aRes.nStartOfNextSentencePosition

        try:
            aRes.aErrors = lightproof_impl_pt_BR.proofread( nDocId, rText, rLocale, \
                nStartOfSentencePos, aRes.nBehindEndOfSentencePosition, rProperties)
        except Exception as e:
            if len(rProperties) > 0 and rProperties[0].Name == "Debug" and len(
                    e.args) == 2:
                aRes.aText, aRes.nStartOfSentencePosition = e
            else:
                if 'PYUNO_LOGLEVEL' in os.environ:
                    print(traceback.format_exc())
        return aRes