Grammalecte  Check-in [82a84a50e8]

Overview
Comment:[core][revert] gc engine: don’t remove merged tokens
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | rg
Files: files | file ages | folders
SHA3-256: 82a84a50e8fea3af66c4483c4bdbc5d28f064057ab78a145e2a52fc194885326
User & Date: olr on 2018-06-27 18:58:45
Other Links: branch diff | manifest | tags
Context
2018-06-27
20:18
[core] gc engine: merge error creation functions (code clarification) check-in: 6f2fcade8d user: olr tags: core, rg
18:58
[core][revert] gc engine: don’t remove merged tokens check-in: 82a84a50e8 user: olr tags: core, rg
18:52
[fr] conversion: regex rules -> graph rules check-in: 84f047b454 user: olr tags: fr, rg
Changes

Modified gc_core/py/lang_core/gc_engine.py from [3d9d459362] to [7a8dc9f99f].

949
950
951
952
953
954
955
956

957
958
959
960
961
962
963
964
965
966
967
968

969
970
971
972
973
974
975
976

977
978
979
980



981
982
983
984
985
986
987
949
950
951
952
953
954
955

956
957
958
959
960
961
962
963
964
965
966
967

968
969
970
971
972
973
974


975
976
977
978

979
980
981
982
983
984
985
986
987
988







-
+











-
+






-
-
+



-
+
+
+







        "rewrite the sentence, modify tokens, purge the token list"
        if bDebug:
            print("REWRITE")
        lNewToken = []
        nMergeUntil = 0
        dTokenMerger = None
        for dToken in self.lToken:
            bRemoveToken = False
            bKeepToken = True
            if "bImmune" in dToken:
                nErrorStart = self.nOffsetWithinParagraph + dToken["nStart"]
                if nErrorStart in self.dError:
                    if bDebug:
                        print("immunity -> error removed:", self.dError[nErrorStart])
                    del self.dError[nErrorStart]
            if nMergeUntil and dToken["i"] <= nMergeUntil:
                dTokenMerger["sValue"] += " " * (dToken["nStart"] - dTokenMerger["nEnd"]) + dToken["sValue"]
                dTokenMerger["nEnd"] = dToken["nEnd"]
                if bDebug:
                    print("  MERGED TOKEN:", dTokenMerger["sValue"])
                bRemoveToken = True
                bKeepToken = False
            if "nMergeUntil" in dToken:
                if dToken["i"] > nMergeUntil: # this token is not already merged with a previous token
                    dTokenMerger = dToken
                if dToken["nMergeUntil"] > nMergeUntil:
                    nMergeUntil = dToken["nMergeUntil"]
                del dToken["nMergeUntil"]
            #
            if bRemoveToken or "bToRemove" in dToken:
            elif "bToRemove" in dToken:
                if bDebug:
                    print("  REMOVED:", dToken["sValue"])
                self.sSentence = self.sSentence[:dToken["nStart"]] + " " * (dToken["nEnd"] - dToken["nStart"]) + self.sSentence[dToken["nEnd"]:]
            else:
                bKeepToken = False
            #
            if bKeepToken:
                lNewToken.append(dToken)
                if "sNewValue" in dToken:
                    # rewrite token and sentence
                    if bDebug:
                        print(dToken["sValue"], "->", dToken["sNewValue"])
                    dToken["sRealValue"] = dToken["sValue"]
                    dToken["sValue"] = dToken["sNewValue"]