Commit abf8c521 authored by Savva Golubitsky's avatar Savva Golubitsky

multiple dummy edges

parent 60033c1e
......@@ -166,6 +166,8 @@ class Parser():
#Props is line "[proFp=smth, ...]"
def _param_from_props(self,props):
parm = Params()
if props =="":
return parm
props = props.replace("]", '')
if '(' in props:
mchs = [m for m in re.finditer(r'\((\w+,)*\w+\)', props)]
......@@ -191,6 +193,13 @@ class Parser():
res = re.split(r"\[", raw, 1)
return res[0], self._param_from_props(res[1])
def _multiple_morphs(self,props, n):
p = self._param_from_props(props)
if p.morphism is None:
return [copy.copy(p) for i in range(n)]
else:
return self._split_multiple(p)
def _topology(self,raw):
spl = re.split(r"\s*(=>|->|\[|\])\s*", raw)
spl = list(filter(lambda x: x!="[" and x!="]" and x!="", spl))
......@@ -202,26 +211,26 @@ class Parser():
for i in range(len(right)):
right[i] = self.fact.name + "_" + right[i]
if (len(left)>1) and (len(right)>1):
raise Exception("ERROR:Ambigious multiple connection in line:\n\t{}".format(raw))
raise Exception("ERROR: Ambigious multiple connection in line:\n\t{}".format(raw))
# many to one conection
elif len(left)>1:
p = self._param_from_props(spl[3])
morphs = self._split_multiple(p)
if len(spl) < 4:
spl.append("")
morphs = self._multiple_morphs(spl[3], len(left))
if len(morphs)!=len(left):
raise Exception("\tERROR:Count of edges do not match to count of states in many to one connection!\n\t\t{}".format(raw))
raise Exception("\tERROR: Count of edges do not match to count of states in many to one connection!\n\t\t{}".format(raw))
self.fact.add_state(right[0])
for i, st in enumerate(left):
self.fact.add_state(st)
self.fact.add_connection(st, right[0], morphs[i].morphism)
# one to many connection, here could be selector
elif len(right)>1:
p = self._param_from_props(spl[3])
if len(spl) < 4:
spl.append("")
morphs = self._multiple_morphs(spl[3], len(right))
self.fact.add_state(left[0])
morphs = self._split_multiple(p)
print(p)
print("MORPH", morphs[0])
if len(morphs)!=len(right):
raise Exception("\tERROR:Count of edges do not match to count of states in one to many connection!\n\t\t{}".format(raw))
raise Exception("\tERROR: Count of edges do not match to count of states in one to many connection!\n\t\t{}".format(raw))
for i, st in enumerate(right):
self.fact.add_state(st)
self.fact.add_connection(left[0], st, morphs[i].morphism, morphs[i].order)
......
......@@ -7,5 +7,5 @@ digraph SIMPLEST {
__BEGIN__ -> ST2
ST2 -> ST3_1, ST3_2 [morphism=(INCR_A, INCR_B)]
ST3_1, ST3_2 -> __END__ [morphism=(INCR_A, INCR_B)]
ST3_1, ST3_2 -> __END__
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment