Back to index

texmacs  1.0.7.15
Public Member Functions | Public Attributes | Protected Member Functions
invisible_corrector Struct Reference
Collaboration diagram for invisible_corrector:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 invisible_corrector (tree t, int force2)
tree correct (tree t, string mode)

Public Attributes

int force
hashmap< string, int > times_before
hashmap< string, int > times_after
hashmap< string, int > space_before
hashmap< string, int > space_after

Protected Member Functions

bool is_letter_like (string s)
bool contains_infix (tree t)
bool contains_plus_like (tree t)
void count_invisible (array< tree > a)
void count_invisible (tree t, string mode)
int get_status (tree t, bool left, bool script_flag)
array< treecorrect (array< tree > a)

Detailed Description

Definition at line 346 of file tree_correct.cpp.


Constructor & Destructor Documentation

invisible_corrector::invisible_corrector ( tree  t,
int  force2 
) [inline]

Definition at line 363 of file tree_correct.cpp.

                                                 :
    force (force2), times_before (0), times_after (0), space_after (0) {
      count_invisible (t, "text"); }

Here is the call graph for this function:


Member Function Documentation

bool invisible_corrector::contains_infix ( tree  t) [protected]

Definition at line 377 of file tree_correct.cpp.

                                           {
  array<int> tp= symbol_types (concat_tokenize (t));
  for (int i=0; i<N(tp); i++)
    if (tp[i] == SYMBOL_INFIX)
      return true;
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 386 of file tree_correct.cpp.

                                               {
  array<tree> a= concat_tokenize (t);
  for (int i=1; i<N(a)-1; i++)
    if (a[i] == "+" || a[i] == "-")
      return true;
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

array< tree > invisible_corrector::correct ( array< tree a) [protected]

Definition at line 533 of file tree_correct.cpp.

                                           {
  //cout << "Correct " << a << "\n";
  array<tree> r;
  array<int> tp= symbol_types (a);
  for (int i=0; i<N(a); i++) {
    r << a[i];
    if (a[i] != " " && tp[i] == SYMBOL_BASIC) {
      int j;
      for (j= i+1; j<N(a); j++)
       if (tp[j] != SYMBOL_SKIP && tp[j] != SYMBOL_SCRIPT) break;
       else if (a[j] == " ") break;
      if (j >= N(a) || a[j] == " " || tp[j] != SYMBOL_BASIC)
       continue;
      
      string ins= "";
      int sti= get_status (a[i], true, admits_script (tp, i));
      int stj= get_status (a[j], false, admits_script (tp, j));
      //cout << "Pair (" << a[i] << ", " << a[j] << ")"
      //<< " -> (" << sti << ", " << stj << ")" << LF;
      if (sti == SURE_NOTHING || stj == SURE_NOTHING)
       ins= "";
      else if (sti == SURE_TIMES && stj != SURE_SPACE)
       ins= "*";
      else if (sti == SURE_SPACE && stj != SURE_TIMES)
       ins= " ";
      else if (sti == PROBABLE_TIMES && stj == PROBABLE_TIMES)
       ins= "*";
      else if (sti == PROBABLE_SPACE && stj == PROBABLE_SPACE)
       ins= " ";
      else if (sti == PROBABLE_TIMES && stj == BOTH_WAYS)
       ins= "*";
      else if (sti == PROBABLE_SPACE && stj == BOTH_WAYS)
       ins= " ";
      else if (sti == BOTH_WAYS && stj == PROBABLE_TIMES)
       ins= "*";
      else if (sti == BOTH_WAYS && stj == PROBABLE_SPACE)
       ins= " ";
      else if (sti == BOTH_WAYS && stj == BOTH_WAYS && force == 1 &&
              (is_atomic (a[i]) || is_around (a[i])) &&
              (is_atomic (a[j]) || is_around (a[j])))
       ins= "*";

      if (is_around (a[j]))
       if (ins == " " || (ins == "*" && force == -1))
         ins= "";
      if (a[j] == ".") ins= "";
      while (i+1 < N(a) && (is_func (a[i+1], RSUB, 1) ||
                         is_func (a[i+1], RSUP, 1) ||
                         is_func (a[i+1], RPRIME, 1))) {
       i++;
       r << a[i];
      }
      if (ins != "") r << tree (ins);
    }
  }
  return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 592 of file tree_correct.cpp.

                                                 {
  //cout << "Correct " << t << ", " << mode << "\n";
  tree r= t;
  if (is_compound (t)) {
    int i, n= N(t);
    r= tree (t, n);
    for (i=0; i<n; i++) {
      string smode= get_submode (t, i, mode);
      if (is_func (t, WITH) && i != N(t)-1)
       r[i]= t[i];
      else if (is_correctable_child (t, i))
       r[i]= correct (t[i], smode);
      else r[i]= t[i];
    }
  }
  
  if (mode == "math") {
    array<tree> a= concat_tokenize (r);
    a= correct (a);
    tree ret= concat_recompose (a);
    //if (ret != r)
    //  cout << "<< " << r << " >>" << LF
    //       << ">> " << ret << " <<" << LF;
    return ret;
  }
  else return r;
}

Here is the call graph for this function:

void invisible_corrector::count_invisible ( array< tree a) [protected]

contains_infix (a[j2][1]))

Definition at line 395 of file tree_correct.cpp.

                                                   {
  array<int>  tp= symbol_types (a);
  for (int i=0; i<N(a); i++)
    if (is_atomic (a[i]) && is_letter_like (a[i]->label)) {
      int j1, j2;
      for (j1= i-1; j1>=0; j1--)
       if (tp[j1] != SYMBOL_SKIP && tp[j1] != SYMBOL_SCRIPT) break;
       else if (a[j1] == " ") break;
      for (j2= i+1; j2<N(a); j2++)
       if (tp[j2] != SYMBOL_SKIP && tp[j2] != SYMBOL_SCRIPT) break;
       else if (a[j2] == " ") break;
      string s= a[i]->label;
      if (j1 >= 0) {
       if (a[j1] == "*")
         times_before (s)= times_before[s] + 1;
       if (a[j1] == " ")
         space_before (s)= space_before[s] + 1;
      }
      if (j2 < N(a)) {
       if (a[j2] == "*")
         times_after (s)= times_after[s] + 1;
       if (a[j2] == " ")
         space_after (s)= space_after[s] + 1;
        // NOTE: this heuristic might not be a good idea,
        // because it inhibits the correction of QR -> Q*R,
        // if Q is a polynomial which is applied somewhere Q(1).
        // We might introduce a table 'apply_after'.
       //if (is_around (a[j2]) && a[j2][0] == "(" &&
        //space_after (s)= space_after[s] + 1;
      }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void invisible_corrector::count_invisible ( tree  t,
string  mode 
) [protected]

Definition at line 430 of file tree_correct.cpp.

                                                         {
  if (is_compound (t)) {
    int i, n= N(t);
    for (i=0; i<n; i++) {
      string smode= get_submode (t, i, mode);
      if (is_func (t, WITH) && i != N(t)-1);
      else if (is_correctable_child (t, i))
       count_invisible (t[i], smode);
    }
  }
  if (mode == "math")
    count_invisible (concat_tokenize (t));
}

Here is the call graph for this function:

int invisible_corrector::get_status ( tree  t,
bool  left,
bool  script_flag 
) [protected]

Definition at line 445 of file tree_correct.cpp.

                                                                    {
  if (is_atomic (t)) {
    static language lan= math_language ("std-math");
    string s= t->label;
    string g= lan->get_group (t->label);
    if (is_numeric (s))
      return (left? SURE_TIMES: PROBABLE_TIMES);
    else if (starts (g, "Unary-operator-textual"))
      return (left? SURE_SPACE: BOTH_WAYS);
    else if (starts (g, "Binary-operator"))
      return SURE_SPACE;
    else if (starts (g, "N-ary-operator"))
      return (left? SURE_SPACE: BOTH_WAYS);
    else if (is_letter_like (s)) {
      if (left) {
       if (times_after[s] > 0 && space_after[s] == 0)
         return SURE_TIMES;
       else if (space_after[s] > 0 && times_after[s] == 0)
         return SURE_SPACE;
       else if (times_after[s] > space_after[s])
         return PROBABLE_TIMES;
       else if (space_after[s] > times_after[s])
         return PROBABLE_SPACE;
       else if (N(s)>1 && is_iso_alpha (s))
         return PROBABLE_SPACE;
        else if (script_flag)
          return PROBABLE_TIMES;
       else return BOTH_WAYS;
      }
      else {
       if (times_before[s] > space_before[s])
         return PROBABLE_TIMES;
       else if (times_after[s] > 0 && space_after[s] == 0)
         return PROBABLE_TIMES;
        else if (script_flag && (N(s) == 1 || !is_iso_alpha (s)))
          return PROBABLE_TIMES;
       else return BOTH_WAYS;
      }
    }
    else if (s == "<cdots>" || s == "<ldots>")
      return PROBABLE_TIMES;
    else return ((force > 0)? BOTH_WAYS: SURE_NOTHING);
  }
  else {
    if (is_around (t)) {
      if (left && contains_plus_like (t[1]))
       return ((force > 0)? SURE_TIMES: PROBABLE_TIMES);
      else if (contains_plus_like (t[1]))
       return ((force > 0)? PROBABLE_TIMES: BOTH_WAYS);
      else if (!contains_infix (t[1]))
       return (left? BOTH_WAYS: SURE_SPACE);
      else return BOTH_WAYS;
    }
    else if (is_func (t, FRAC) ||
            is_func (t, SQRT))
      return (left? SURE_TIMES: BOTH_WAYS);
    else if (!left && is_func (t, BIG_AROUND, 2) &&
             (t[0] == "<sum>" || t[0] == "<amalg>" ||
              t[0] == "<oplus>" || t[0] == "<uplus>" ||
              t[0] == "<int>" || t[0] == "<oint>" ||
              t[0] == "<intlim>" || t[0] == "<ointlim>" ||
              t[0] == "<prod>" || t[0] == "<odot>" || t[0] == "<otimes>"))
      return PROBABLE_TIMES;
    else if (is_func (t, WIDE, 2))
      return get_status (t[0], left, script_flag);
    else if (is_func (t, WITH))
      return get_status (t[N(t)-1], left, script_flag);
    else if (N(t) == 0 && L(t) >= START_EXTENSIONS) {
      tree def= the_drd->get_syntax (L(t));
      if (is_func (def, MACRO, 1))
        return get_status (def[0], left, script_flag);
      else return SURE_NOTHING;
    }
    else return SURE_NOTHING;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 370 of file tree_correct.cpp.

                                             {
  static language lan= math_language ("std-math");
  if (s != "" && is_iso_alpha (s)) return true;
  return lan->get_group (s) == "Letter-symbol";
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 347 of file tree_correct.cpp.

Definition at line 351 of file tree_correct.cpp.

Definition at line 350 of file tree_correct.cpp.

Definition at line 349 of file tree_correct.cpp.

Definition at line 348 of file tree_correct.cpp.


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