Grouping list elements according to a condition
Select[Length @ # > 1 &] @ SequenceSplit[data, p : {{_, 0} ..., {_, 1} ..} :> p]
{{{"Call", 0}, {"Call 2", 0}, {"Response", 1}}, {{"Call 3", 0}, {"Response", 1}, {"Response 2", 1}}}
SequenceSplit[data, {p1 : {_, 0} ..., p2 : {_, 1} ..} :> {p1} -> {p2}]
{{{"Call", 0}, {"Call 2", 0}} -> {{"Response", 1}}, {{"Call 3", 0}} -> {{"Response", 1}, {"Response 2", 1}}}
SequenceSplit[data, {p1 : {_, 0} ..., p2 : {_, 1} ..} :> {p1}[[All, 1]] -> {p2}[[All, 1]]]
{{"Call", "Call 2"} -> {"Response"}, {"Call 3"} -> {"Response", "Response 2"}}
Update: An alternative approach using Split
and SplitBy
:
Rule @@@ Map[SplitBy[#, Last][[All, All, 1]] &]@
Select[Length @ # > 1 &] @ Split[data, {#[[2]], #2[[2]]} != {1, 0} &]
{{"Call", "Call 2"} -> {"Response"}, {"Call 3"} -> {"Response", "Response 2"}}
crl={{"Call",0},{"Call 2",0},{"Response",1},{"Call 3",0},{"Response",1},{"Response 2",1}};
SequenceCases[crl,{c:{_,0}..,r:{_,1}..}:>First/@{c}->First/@{r}]
{{Call,Call 2}->{Response}, {Call 3}->{Response,Response 2}}
crl1={{"Bad Response",1},{"Call",0},{"Call 2",0},{"Response",1},{"Call 3",0},{"Response",1},{"Response 2",1},{"Bad Call",0}};
SequenceCases[crl1,{c:{_,0}..,r:{_,1}..}:>First/@{c}->First/@{r}]
Same as above.