⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlbifv03.java

📁 java编写的贝叶斯网络分类器(貌似没有模型构建和参数学习过程)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Generated By:JavaCC: Do not edit this line. XMLBIFv03.java */
package Parsers.XMLBIFv03;

import InterchangeFormat.*;

import java.util.Vector;
import java.util.Enumeration;

/*
 * Definition of the Interchange Format class and its
 * variables. The IFBayesNet ifbn contains the
 * parsed Bayesian network.
 */

public class XMLBIFv03 extends InterchangeFormat implements XMLBIFv03Constants {
  IFBayesNet ifbn;

  static final int NATURE_DEFINE = 1;
  static final int DECISION_DEFINE = 2;
  static final int UTILITY_DEFINE = 3;

  public IFBayesNet get_ifbn() { return(ifbn); }

  public void invert_probability_tables() {
       ifbn.invert_probability_tables();
  }

  String pcdata() throws ParseException {
      StringBuffer p = new StringBuffer("");
      Token t;
      while (true) {
                t = getToken(1);
                if ((t.kind == 0) || (t.kind == SOT) || (t.kind == CT) || (t.kind == EOT) ) break;
            else { p.append(t.image); getNextToken(); }
      }
      return(p.toString());
  }

  void glob_heading() throws ParseException {
      Token t;
      while (true) {
                t = getToken(1);
                if (t.kind == 0) break;
                else {
                    if (t.kind == SOT) {
                        getNextToken(); t = getToken(1);
                        if (t.kind == BIF) {
                            getNextToken(); break;
                        }
                        else { getNextToken(); }
                    }
                    else { getNextToken(); }
                }
                getNextToken();
          }
  }

/*
 * THE INTERCHANGE FORMAT GRAMMAR STARTS HERE.
 */

/*
 * Basic parsing function. First looks for a Network Declaration,
 * then looks for an arbitrary number of VariableDeclaration or
 * ProbabilityDeclaration non-terminals. The objects are
 * in the vectors ifbn.pvs and ifbn.upfs.
 */
  final public void CompilationUnit() throws ParseException {
IFProbabilityVariable pv;
IFProbabilityFunction upf;
    OpenTag();
    glob_heading();
    NetworkDeclaration();
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case SOT:
        ;
        break;
      default:
        jj_la1[0] = jj_gen;
        break label_1;
      }
      jj_consume_token(SOT);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case VARIABLE:
        pv = VariableDeclaration();
                                 ifbn.add(pv);
        break;
      case DEFINITION:
        upf = ProbabilityDeclaration();
                                     ifbn.add(upf);
        break;
      default:
        jj_la1[1] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
    jj_consume_token(EOT);
    jj_consume_token(NETWORK);
    jj_consume_token(CT);
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case EOT:
      jj_consume_token(EOT);
      jj_consume_token(BIF);
      jj_consume_token(CT);
      break;
    case 0:
      jj_consume_token(0);
      break;
    default:
      jj_la1[2] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  final public void OpenTag() throws ParseException {
    jj_consume_token(OPENTAG);
  }

/*
 * Detect and initialize the network.
 */
  final public void NetworkDeclaration() throws ParseException {
String s, ss;
Vector properties = new Vector();
double version;
    version = VersionDeclaration();
                                 pcdata();
    jj_consume_token(CT);
    jj_consume_token(SOT);
    jj_consume_token(NETWORK);
    jj_consume_token(CT);
    jj_consume_token(SOT);
    jj_consume_token(NAME);
    s = getIdentifier();
    jj_consume_token(EOT);
    jj_consume_token(NAME);
    jj_consume_token(CT);
    label_2:
    while (true) {
      if (jj_2_1(2)) {
        ;
      } else {
        break label_2;
      }
      ss = Property();
                  properties.addElement(ss);
    }
          ifbn = new IFBayesNet(s, properties);
  }

/*
 * Get the format version.
 */
  final public double VersionDeclaration() throws ParseException {
Token t;
double version = 0;
    jj_consume_token(VERSION);
    jj_consume_token(EQUAL);
    t = jj_consume_token(ATTRIBUTE_STRING);
     version = (Double.valueOf( (t.image).substring(1,t.image.length()-1) )).doubleValue();
     {if (true) return(version);}
    throw new Error("Missing return statement in function");
  }

/*
 * Detect a variable declaration.
 */
  final public IFProbabilityVariable VariableDeclaration() throws ParseException {
String s;
IFProbabilityVariable pv;
int type = NATURE_DEFINE;
    jj_consume_token(VARIABLE);
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case TYPE:
      type = TypeDeclaration();
      break;
    default:
      jj_la1[3] = jj_gen;
      ;
    }
    jj_consume_token(CT);
    s = ProbabilityVariableName();
    pv = VariableContent(s);
    jj_consume_token(EOT);
    jj_consume_token(VARIABLE);
    jj_consume_token(CT);
          {if (true) return(pv);}
    throw new Error("Missing return statement in function");
  }

  final public String ProbabilityVariableName() throws ParseException {
String s;
    jj_consume_token(SOT);
    jj_consume_token(NAME);
    s = getIdentifier();
    jj_consume_token(EOT);
    jj_consume_token(NAME);
    jj_consume_token(CT);
          {if (true) return(s);}
    throw new Error("Missing return statement in function");
  }

  final public int TypeDeclaration() throws ParseException {
int type;
    jj_consume_token(TYPE);
    jj_consume_token(EQUAL);
    type = ProbabilityVariableType();
      {if (true) return(type);}
    throw new Error("Missing return statement in function");
  }

  final public int ProbabilityVariableType() throws ParseException {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case NATURE:
      jj_consume_token(NATURE);
               {if (true) return(NATURE_DEFINE);}
      break;
    case DECISION:
      jj_consume_token(DECISION);
                 {if (true) return(DECISION_DEFINE);}
      break;
    case UTILITY:
      jj_consume_token(UTILITY);
                 {if (true) return(UTILITY_DEFINE);}
      break;
    default:
      jj_la1[4] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    throw new Error("Missing return statement in function");
  }

  final public IFProbabilityVariable VariableContent(String name) throws ParseException {
int i;
String s, v, svalues[];
Vector properties = new Vector();
Vector values = new Vector();
Enumeration e;
IFProbabilityVariable pv = new IFProbabilityVariable();
    label_3:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case SOT:
        ;
        break;
      default:
        jj_la1[5] = jj_gen;
        break label_3;
      }
      if (jj_2_2(2)) {
        s = Property();
                   properties.addElement(s);
      } else {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case SOT:
          v = VariableOutcome();
                          values.addElement(v);
          break;
        default:
          jj_la1[6] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
      }
    }
          pv.set_name(name);
          pv.set_properties(properties);
          svalues = new String[ values.size() ];
          for (e = values.elements(), i = 0; e.hasMoreElements(); i++)
            svalues[i] = (String)(e.nextElement());
          pv.set_values(svalues);
          {if (true) return(pv);}
    throw new Error("Missing return statement in function");
  }

  final public String VariableOutcome() throws ParseException {
String s;
    jj_consume_token(SOT);
    jj_consume_token(OUTCOME);
    s = getIdentifier();
    jj_consume_token(EOT);
    jj_consume_token(OUTCOME);
    jj_consume_token(CT);
          {if (true) return(s);}
    throw new Error("Missing return statement in function");
  }

/*
 * Detect a probability declaration.
 */
  final public IFProbabilityFunction ProbabilityDeclaration() throws ParseException {
String vs[];
IFProbabilityFunction upf = new IFProbabilityFunction();
    jj_consume_token(DEFINITION);
    jj_consume_token(CT);
    ProbabilityContent(upf);
    jj_consume_token(EOT);
    jj_consume_token(DEFINITION);
    jj_consume_token(CT);
          {if (true) return(upf);}
    throw new Error("Missing return statement in function");
  }

  final public void ProbabilityContent(IFProbabilityFunction upf) throws ParseException {
int i, j;
double def[] = null;
double tab[] = null;
String s, vs[];
IFProbabilityEntry entry = null;
Enumeration e;

Vector fors = new Vector();
Vector givens = new Vector();
Vector properties = new Vector();
Vector entries = new Vector();
Vector defaults = new Vector();
Vector tables = new Vector();
    label_4:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case SOT:
        ;
        break;
      default:
        jj_la1[7] = jj_gen;
        break label_4;
      }
      jj_consume_token(SOT);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case FOR:
        s = ProbabilityFor();
                         fors.addElement(s);
        break;
      case GIVEN:
        s = ProbabilityGiven();
                           givens.addElement(s);
        break;
      case SOT:
        s = Property();
                   properties.addElement(s);
        break;
      case TABLE:
        tab = ProbabilityTable();
                             tables.addElement(tab);
        break;
      default:
        jj_la1[8] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
          upf.set_properties(properties);
          upf.set_defaults(defaults);
          upf.set_entries(entries);
          upf.set_tables(tables);
          upf.set_conditional_index(fors.size());
          vs = new String[ fors.size() + givens.size() ];
      for (e = fors.elements(), i = 0; e.hasMoreElements(); i++)
        vs[i] = (String)(e.nextElement());
      for (e = givens.elements(), j = i; e.hasMoreElements(); j++)
        vs[j] = (String)(e.nextElement());
          upf.set_variables(vs);
  }

  final public String ProbabilityFor() throws ParseException {
String s;
    jj_consume_token(FOR);
    s = getIdentifier();
    jj_consume_token(EOT);
    jj_consume_token(FOR);
    jj_consume_token(CT);
          {if (true) return(s);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -