756{
757 _expanded = "";
758
759
760 if (_terms.size() > 1) {
761 for (unsigned i = 0; i < _terms.size(); i++) {
762 _terms[i].expand();
763 if (i)
764 _expanded += " | ";
765 _expanded += _terms[i].expanded();
766 }
767 return;
768 }
769
770
771 _expanded = _sentence;
772 while (1) {
773 unsigned a = 0;
774 unsigned b = 0;
775 for (unsigned i = 0; i < _expanded.size(); i++) {
776 char c = _expanded[i];
777 if (c == '(') {
778 a = i;
779 } else if (c == ')') {
780 b = i;
781 break;
782 }
783 }
784
785
786 if (a == b) return;
787
788
789 string s0 = _expanded.substr(0, a - 1);
790 if (a == 0) s0 = "";
791 string p = _expanded.substr(a + 1, b - a - 1);
792 string s1 = _expanded.substr(b + 1);
793
794
795
796
797
798
799
800 unsigned a1 = 0;
801 for (unsigned i = 0; i < p.size(); i++) {
802 char c = p[i];
803 if (c == '|') {
804 a1 = i;
805 break;
806 }
807 }
808 if (a1) {
809 string p0 = p.substr(0, a1 - 1);
810 string p1 = p.substr(a1 + 1);
811 _expanded = s0 + p0 + s1 + " | " + s0 + " (" + p1 + ") " + s1;
812
814 tmp.expand();
815 _expanded = tmp.expanded();
816 } else {
817 _expanded = s0 + p + s1;
818 }
819
820
821
822
823 }
824}