Belle II Software development
Term Class Reference

Public Member Functions

 Term (const string &)
 
string sentence (void) const
 
void expand (void)
 
string expanded (void)
 

Private Attributes

string _sentence
 
vector< string > _words
 
vector< Term_terms
 
string _expanded
 

Detailed Description

Definition at line 47 of file FTDConverter.cc.

Constructor & Destructor Documentation

◆ Term()

Term ( const string &  a)
explicit

Definition at line 685 of file FTDConverter.cc.

686 : _sentence(a)
687{
688 char b[800];
689 strcpy(b, _sentence.c_str());
690
691 char w[800];
692 while (1) {
693 chopWord(b, w);
694 if (w[0] == 0) break;
695 _words.push_back(string(w));
696 }
697
698 //...Create term candidates...
699 unsigned inP = 0;
700 vector<string> termCandidates;
701 string t;
702 for (unsigned i = 0; i < _sentence.size(); i++) {
703 char c = _sentence[i];
704
705 if (c == '(') {
706 t += c;
707 ++inP;
708 continue;
709 } else if (c == ')') {
710 t += c;
711 --inP;
712 continue;
713 }
714
715 if (inP) {
716 t += c;
717 continue;
718 }
719
720 if (c == '|') {
721 termCandidates.push_back(t);
722 t = "";
723 continue;
724 }
725
726 t += c;
727 }
728 termCandidates.push_back(t);
729
730 //...Check term candidates...
731 if (termCandidates.size() > 1) {
732 for (unsigned i = 0; i < termCandidates.size(); i++) {
733 Term x(termCandidates[i]);
734 _terms.push_back(x);
735 }
736
737// cout << "Term list:#=" << _terms.size() << endl;
738// for (unsigned i = 0; i < _terms.size(); i++) {
739// cout << i << ":" << _terms[i].sentence() << endl;
740// }
741 }
742}

◆ ~Term()

~Term ( )
virtual

Definition at line 744 of file FTDConverter.cc.

745{
746}

Member Function Documentation

◆ expand()

void expand ( void  )

Definition at line 755 of file FTDConverter.cc.

756{
757 _expanded = "";
758
759 //...Have sub-terms...
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 //...Expand...
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 //...No ()...
786 if (a == b) return;
787
788 //...necessary to expand...
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// cout << "a,b=" << a << "," << b << endl;
795// cout << " s0=" << s0 << endl;
796// cout << " p =" << p << endl;
797// cout << " s1=" << s1 << endl;
798
799 //...divide p into two...
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
813 Term tmp(_expanded);
814 tmp.expand();
815 _expanded = tmp.expanded();
816 } else {
817 _expanded = s0 + p + s1;
818 }
819
820 // cout << "--->" << endl;
821 // cout << _expanded << endl;
822 // cout << "<---" << endl;
823 }
824}

◆ expanded()

string expanded ( void  )

Definition at line 827 of file FTDConverter.cc.

828{
829 return _expanded;
830}

◆ sentence()

string sentence ( void  ) const

Definition at line 749 of file FTDConverter.cc.

750{
751 return _sentence;
752}

Member Data Documentation

◆ _expanded

string _expanded
private

Definition at line 62 of file FTDConverter.cc.

◆ _sentence

string _sentence
private

Definition at line 59 of file FTDConverter.cc.

◆ _terms

vector<Term> _terms
private

Definition at line 61 of file FTDConverter.cc.

◆ _words

vector<string> _words
private

Definition at line 60 of file FTDConverter.cc.


The documentation for this class was generated from the following file: