Spaces:
Running
Running
José Eliel Camargo Molina
commited on
Commit
·
43e1e77
1
Parent(s):
89d8d42
tokenization new
Browse files
app.py
CHANGED
@@ -84,7 +84,7 @@ def derobj_to_tex(obj,lor_index,pos):
|
|
84 |
return outtex
|
85 |
|
86 |
def gamobj_to_tex(obj,lor_index,pos):
|
87 |
-
outtex = "\
|
88 |
return outtex
|
89 |
|
90 |
def obj_to_tex(obj,lor_index="\mu",pos="^"):
|
@@ -97,15 +97,15 @@ def obj_to_tex(obj,lor_index="\mu",pos="^"):
|
|
97 |
return "\quad\quad-"
|
98 |
if obj[0] == "i" :
|
99 |
return "i"
|
100 |
-
if obj[0] == "
|
101 |
return fieldobj_to_tex(obj,lor_index,pos)
|
102 |
-
if obj[0] == "
|
103 |
return derobj_to_tex(obj,lor_index,pos)
|
104 |
-
if obj[0] == "
|
105 |
return gamobj_to_tex(obj,lor_index,pos)
|
106 |
-
if obj[0] == "
|
107 |
return "[ "+derobj_to_tex(obj,lor_index,pos)
|
108 |
-
if obj[0] == "
|
109 |
return ", "+derobj_to_tex(obj,lor_index,pos)+' ]'
|
110 |
|
111 |
def split_with_delimiter_preserved(string, delimiters,ignore_dots=False):
|
@@ -151,7 +151,7 @@ def get_obj_dict(inlist):
|
|
151 |
id = [i for i in iitem.split() if "ID" in i]
|
152 |
if len(id) == 1:
|
153 |
idict["ID"] = id[0]
|
154 |
-
if "
|
155 |
idict["LATEX"] = obj_to_tex(iitem,"\\mu","^")
|
156 |
if iitem == "+" or iitem == "-" or iitem == "i":
|
157 |
idict["LATEX"] = obj_to_tex(iitem )
|
@@ -163,7 +163,7 @@ def get_con_dict(inlist):
|
|
163 |
for iitem in inlist:
|
164 |
iitem = iitem.split()
|
165 |
iitem = [i for i in iitem if i != ""]
|
166 |
-
sym = [i for i in iitem if ("SU" in i or "
|
167 |
assert len(sym) == 1, "More than one symmetry in contraction"
|
168 |
ids = [i for i in iitem if ("SU" not in i and "LZ" not in i)]
|
169 |
if sym[0] not in outdict.keys():
|
@@ -174,9 +174,9 @@ def get_con_dict(inlist):
|
|
174 |
|
175 |
def term_to_tex(term,verbose=False):
|
176 |
# Clean term
|
177 |
-
term = term.replace(".","").replace(" = ", "=").replace(" =- ", "=-").replace(" / ", "/").replace("
|
178 |
-
term = split_with_delimiter_preserved(term,["
|
179 |
-
term = clean_split(term, ["
|
180 |
|
181 |
if verbose: print(term)
|
182 |
|
@@ -184,7 +184,7 @@ def term_to_tex(term,verbose=False):
|
|
184 |
return term[0]
|
185 |
|
186 |
# Get Dictionary of objects
|
187 |
-
objdict = get_obj_dict([i for i in term if "
|
188 |
|
189 |
if verbose:
|
190 |
for i,j in objdict.items():
|
@@ -192,14 +192,14 @@ def term_to_tex(term,verbose=False):
|
|
192 |
|
193 |
|
194 |
# Do contractions
|
195 |
-
contractions = [i for i in term if "
|
196 |
assert len(contractions) < 2, "More than one contraction in term"
|
197 |
-
if (len(contractions) == 1) and contractions != ["
|
198 |
|
199 |
contractions = contractions[0]
|
200 |
-
contractions = split_with_delimiter_preserved(contractions,["
|
201 |
-
contractions = clean_split(contractions, ["
|
202 |
-
contractions = [i for i in contractions if i != "
|
203 |
condict = get_con_dict(contractions)
|
204 |
if verbose: print(condict)
|
205 |
if "LZ" in condict.keys():
|
@@ -220,7 +220,7 @@ def term_to_tex(term,verbose=False):
|
|
220 |
cma = False
|
221 |
firstlz = True
|
222 |
|
223 |
-
outstr = " ".join([objdict[i]["LATEX"] for i in term if "
|
224 |
|
225 |
return outstr
|
226 |
def display_in_latex(instring,verbose=False):
|
@@ -250,8 +250,8 @@ def str_tex(instr,num=0):
|
|
250 |
if i ==0:
|
251 |
outstr += " \mathcal{L}= \quad \\\\ & "
|
252 |
else:
|
253 |
-
nqf = iterm.count("
|
254 |
-
nD = iterm.count("
|
255 |
if nqf != 0 and nqf != 2 and nD == 0:
|
256 |
coup += 1
|
257 |
outstr += " \lambda_{"+str(coup)+"} \,"
|
|
|
84 |
return outtex
|
85 |
|
86 |
def gamobj_to_tex(obj,lor_index,pos):
|
87 |
+
outtex = "\sigma"+pos+lor_index
|
88 |
return outtex
|
89 |
|
90 |
def obj_to_tex(obj,lor_index="\mu",pos="^"):
|
|
|
97 |
return "\quad\quad-"
|
98 |
if obj[0] == "i" :
|
99 |
return "i"
|
100 |
+
if obj[0] == "FIELD" :
|
101 |
return fieldobj_to_tex(obj,lor_index,pos)
|
102 |
+
if obj[0] == "DERIVATIVE":
|
103 |
return derobj_to_tex(obj,lor_index,pos)
|
104 |
+
if obj[0] == "SIGMA":
|
105 |
return gamobj_to_tex(obj,lor_index,pos)
|
106 |
+
if obj[0] == "COMMUTATOR_A":
|
107 |
return "[ "+derobj_to_tex(obj,lor_index,pos)
|
108 |
+
if obj[0] == "COMMUTATOR_B":
|
109 |
return ", "+derobj_to_tex(obj,lor_index,pos)+' ]'
|
110 |
|
111 |
def split_with_delimiter_preserved(string, delimiters,ignore_dots=False):
|
|
|
151 |
id = [i for i in iitem.split() if "ID" in i]
|
152 |
if len(id) == 1:
|
153 |
idict["ID"] = id[0]
|
154 |
+
if "FIELD" in iitem:
|
155 |
idict["LATEX"] = obj_to_tex(iitem,"\\mu","^")
|
156 |
if iitem == "+" or iitem == "-" or iitem == "i":
|
157 |
idict["LATEX"] = obj_to_tex(iitem )
|
|
|
163 |
for iitem in inlist:
|
164 |
iitem = iitem.split()
|
165 |
iitem = [i for i in iitem if i != ""]
|
166 |
+
sym = [i for i in iitem if ("SU" in i or "LORENTZ" in i)]
|
167 |
assert len(sym) == 1, "More than one symmetry in contraction"
|
168 |
ids = [i for i in iitem if ("SU" not in i and "LZ" not in i)]
|
169 |
if sym[0] not in outdict.keys():
|
|
|
174 |
|
175 |
def term_to_tex(term,verbose=False):
|
176 |
# Clean term
|
177 |
+
term = term.replace(".","").replace(" = ", "=").replace(" =- ", "=-").replace(" / ", "/").replace("COMMUTATOR_A DERIVATIVE", "COMMUTATOR_ADERIVATIVE").replace("COMMUTATOR_B DERIVATIVE", "COMMUTATOR_BDERIVATIVE")
|
178 |
+
term = split_with_delimiter_preserved(term,[" FIELD "," DERIVATIVE "," SIGMA "," COMMUTATOR_A "," COMMUTATOR_B "," CONTRACTIONS "])
|
179 |
+
term = clean_split(term, [" FIELD "," DERIVATIVE "," SIGMA "," COMMUTATOR_ADERIVATIVE "," COMMUTATOR_BDERIVATIVE "," CONTRACTIONS "])
|
180 |
|
181 |
if verbose: print(term)
|
182 |
|
|
|
184 |
return term[0]
|
185 |
|
186 |
# Get Dictionary of objects
|
187 |
+
objdict = get_obj_dict([i for i in term if " CONTRACTIONS " not in i])
|
188 |
|
189 |
if verbose:
|
190 |
for i,j in objdict.items():
|
|
|
192 |
|
193 |
|
194 |
# Do contractions
|
195 |
+
contractions = [i for i in term if " CONTRACTIONS " in i]
|
196 |
assert len(contractions) < 2, "More than one contraction in term"
|
197 |
+
if (len(contractions) == 1) and contractions != [" CONTRACTIONS "]:
|
198 |
|
199 |
contractions = contractions[0]
|
200 |
+
contractions = split_with_delimiter_preserved(contractions,[" LORENTZ "," SU2 "," SU3 "])
|
201 |
+
contractions = clean_split(contractions, [" LORENTZ "," SU2 "," SU3 "])
|
202 |
+
contractions = [i for i in contractions if i != " CONTRACTIONS"]
|
203 |
condict = get_con_dict(contractions)
|
204 |
if verbose: print(condict)
|
205 |
if "LZ" in condict.keys():
|
|
|
220 |
cma = False
|
221 |
firstlz = True
|
222 |
|
223 |
+
outstr = " ".join([objdict[i]["LATEX"] for i in term if " CONTRACTIONS " not in i])
|
224 |
|
225 |
return outstr
|
226 |
def display_in_latex(instring,verbose=False):
|
|
|
250 |
if i ==0:
|
251 |
outstr += " \mathcal{L}= \quad \\\\ & "
|
252 |
else:
|
253 |
+
nqf = iterm.count("FIELD SPIN = 0")
|
254 |
+
nD = iterm.count(" DERIVATIVE ")
|
255 |
if nqf != 0 and nqf != 2 and nD == 0:
|
256 |
coup += 1
|
257 |
outstr += " \lambda_{"+str(coup)+"} \,"
|