Grammalecte  Check-in [e83552ea6d]

Overview
Comment:[build][core] multiple tokens and groups
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | build | rg
Files: files | file ages | folders
SHA3-256: e83552ea6d150fde0212534c1af05c6baa0e975bbdcbd1dfdb72b98d9826eb41
User & Date: olr on 2018-05-25 10:07:17
Other Links: branch diff | manifest | tags
Context
2018-05-25
12:14
[build][core] tests check-in: ac09d7cc19 user: olr tags: core, build, rg
10:07
[build][core] multiple tokens and groups check-in: e83552ea6d user: olr tags: core, build, rg
2018-05-24
11:14
[build][core] rules graph: definitions and multiple tokens check-in: da8c5de7df user: olr tags: core, build, rg
Changes

Modified compile_rules_graph.py from [b56c5bc314] to [c9ddced2f8].

39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56


57
58
59
60
61
62
63

64


65


66
67
68
69
70
71
72
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77







-
+









-
+
+






-
+

+
+

+
+







    s = re.sub(r"\bspell *[(]", '_oSpellChecker.isValid(', s)
    s = re.sub(r"[\\](\d+)", 'lToken[\\1]', s)
    return s


def changeReferenceToken (s, dPos):
    for i in range(len(dPos), 0, -1):
        s = s.replace("\\"+str(i), "\\"+dPos[i])
        s = s.replace("\\"+str(i), "\\"+str(dPos[i]))
    return s


def genTokenRules (sTokenLine):
    lToken = sTokenLine.split()
    lTokenRules = None
    for i, sToken in enumerate(lToken):
        if sToken.startswith("{") and sToken.endswith("}") and sToken in dDEF:
            lToken[i] = dDEF[sToken]
        if sToken.startswith("[") and sToken.endswith("]"):
        if ( (sToken.startswith("[") and sToken.endswith("]")) or (sToken.startswith("([") and sToken.endswith("])")) ):
            bSelectedGroup = sToken.startswith("(") and sToken.endswith(")")
            # multiple token
            if not lTokenRules:
                lTokenRules = [ sToken[1:-1].split("|") ]
            else:
                lNewTemp = []
                for aRule in lTokenRules:
                    lElem = sToken[1:-1].split("|")
                    lElem = sToken[1:-1].split("|")  if not bSelectedGroup  else sToken[2:-2].split("|")
                    sElem1 = lElem.pop(0)
                    if bSelectedGroup:
                        sElem1 = "(" + sElem1 + ")"
                    for sElem in lElem:
                        if bSelectedGroup:
                            sElem = "(" + sElem + ")"
                        aNew = list(aRule)
                        aNew.append(sElem)
                        lNewTemp.append(aNew)
                    aRule.append(sElem1)
                lTokenRules.extend(lNewTemp)
        else:
            # simple token
122
123
124
125
126
127
128

129
130




131
132
133
134
135
136
137
127
128
129
130
131
132
133
134


135
136
137
138
139
140
141
142
143
144
145







+
-
-
+
+
+
+







    # Action
    cAction = m.group(1)
    sAction = sAction[m.end():].strip()
    sAction = changeReferenceToken(sAction, dPos)
    iStartAction = int(m.group(2))  if m.group(2)  else 0
    iEndAction = int(m.group(3)[1:])  if m.group(3)  else iStartAction
    if nGroup:
        try:
        iStartAction = dPos[iStartAction]
        iEndAction = dPos[iEndAction]
            iStartAction = dPos[iStartAction]
            iEndAction = dPos[iEndAction]
        except:
            print("# Error. Wrong groups in: " + sIdAction)

    if cAction == "-":
        ## error
        iMsg = sAction.find(" # ")
        if iMsg == -1:
            sMsg = "# Error. Error message not found."
            sURL = ""

Modified gc_lang/fr/rules_graph.grx from [25632727ec] to [18deb74635].

48
49
50
51
52
53
54
55

56
57

58
48
49
50
51
52
53
54

55
56

57
58







-
+

-
+

__rule2__
    ci important que soi
    ci vraiment il y a
    ci pour ça
        <<- morph(\2, ":[WAR]", False) -1>> si   # Message1|http://test.grammalecte.net

__rule3__
    contre [nature|pétrie|action]
    contre ([nature|pétrie|action]) par ([ennui|sélection])
        <<- morph(\1, "xxxx") -1:2>> =\1+\2     # Message2|http://test.grammalecte.org
        <<-  ~>> hyper|fonction
        <<-  ~1>> hyper|fonction