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

📄 bifv01.java

📁 java编写的贝叶斯网络分类器(貌似没有模型构建和参数学习过程)
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Generated By:JavaCC: Do not edit this line. BIFv01.java */
/* This parser uses the data structures in the JavaBayes core *
 * engine (package BayesianNetworks); other implementations   *
 * may use different data structures                          */
package Parsers.BIFv01;

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 BIFv01 extends InterchangeFormat implements BIFv01Constants {
  IFBayesNet ifbn;

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

  /* Method responsible for globbing undefined text in an input file */
  void glob_undefined_text() throws ParseException {
        Token t;
        while (true) {
                t = getToken(1);
                if ((t.kind == 0) ||
                    (t.kind == NETWORK) ||
                    (t.kind == VARIABLE) ||
                    (t.kind == PROBABILITY))
                        break;
                else
                        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;
          glob_undefined_text();
    NetworkDeclaration();
          glob_undefined_text();
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case VARIABLE:
      case PROBABILITY:
        ;
        break;
      default:
        jj_la1[0] = jj_gen;
        break label_1;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case VARIABLE:
        pv = VariableDeclaration();
          ifbn.add(pv); glob_undefined_text();
        break;
      case PROBABILITY:
        upf = ProbabilityDeclaration();
          ifbn.add(upf); glob_undefined_text();
        break;
      default:
        jj_la1[1] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
    jj_consume_token(0);
  }

/* ========================================================== */
/* Detect and initialize the network                          */
/* ========================================================== */
  final public void NetworkDeclaration() throws ParseException {
Token t;
Vector properties;
    jj_consume_token(NETWORK);
    t = jj_consume_token(WORD);
    properties = NetworkContent();
          ifbn = new IFBayesNet(t.image, properties);
  }

/* Fill the network list of properties */
  final public Vector NetworkContent() throws ParseException {
Vector properties = new Vector();
String s;
    jj_consume_token(22);
    label_2:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case PROPERTYSTRING:
        ;
        break;
      default:
        jj_la1[2] = jj_gen;
        break label_2;
      }
      s = Property();
          properties.addElement(s);
    }
    jj_consume_token(23);
          {if (true) return(properties);}
    throw new Error("Missing return statement in function");
  }

/* ========================================================== */
/* Detect a variable declaration                              */
/* ========================================================== */
  final public IFProbabilityVariable VariableDeclaration() throws ParseException {
String s;
IFProbabilityVariable pv;
    jj_consume_token(VARIABLE);
    s = ProbabilityVariableName();
    pv = VariableContent(s);
          {if (true) return(pv);}
    throw new Error("Missing return statement in function");
  }

/* Fill a variable list of properties */
  final public IFProbabilityVariable VariableContent(String name) throws ParseException {
String s;
String values[] = null;
Vector properties = new Vector();
IFProbabilityVariable pv = new IFProbabilityVariable();
    jj_consume_token(22);
    label_3:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case VARIABLETYPE:
      case PROPERTYSTRING:
        ;
        break;
      default:
        jj_la1[3] = jj_gen;
        break label_3;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case PROPERTYSTRING:
        s = Property();
          properties.addElement(s);
        break;
      case VARIABLETYPE:
        values = VariableDiscrete();
        break;
      default:
        jj_la1[4] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
    jj_consume_token(23);
          pv.set_name(name);
          pv.set_properties(properties);
          pv.set_values(values);
          {if (true) return(pv);}
    throw new Error("Missing return statement in function");
  }

/* Fill a variable type discrete */
  final public String[] VariableDiscrete() throws ParseException {
String values[] = null;
    jj_consume_token(VARIABLETYPE);
    jj_consume_token(DISCRETE);
    jj_consume_token(24);
    jj_consume_token(NUMBER);
    jj_consume_token(25);
    jj_consume_token(22);
    values = VariableValuesList();
    jj_consume_token(23);
    jj_consume_token(26);
          {if (true) return(values);}
    throw new Error("Missing return statement in function");
  }

/* Get the values of a discrete variable */
  final public String[] VariableValuesList() throws ParseException {
int i;
String value;
String values[] = null;
Vector v = new Vector();
Enumeration e;
    value = ProbabilityVariableValue();
          v.addElement(value);
    label_4:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case WORD:
      case NUMBER:
        ;
        break;
      default:
        jj_la1[5] = jj_gen;
        break label_4;
      }
      value = ProbabilityVariableValue();
          v.addElement(value);
    }
          values = new String[v.size()];
          for (e=v.elements(), i=0; e.hasMoreElements(); i++)
                values[i] = (String)(e.nextElement());
          {if (true) return(values);}
    throw new Error("Missing return statement in function");
  }

/* Pick a single word as a probability variable value */
  final public String ProbabilityVariableValue() throws ParseException {
Token t;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case WORD:
      t = jj_consume_token(WORD);
      break;
    case NUMBER:
      t = jj_consume_token(NUMBER);
      break;
    default:
      jj_la1[6] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
          {if (true) return(t.image);}
    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(PROBABILITY);
    ProbabilityVariablesList(upf);
    ProbabilityContent(upf);
          {if (true) return(upf);}
    throw new Error("Missing return statement in function");
  }

/* Parse the list of Probability variables */
  final public void ProbabilityVariablesList(IFProbabilityFunction upf) throws ParseException {
int i;
Enumeration e;
String variable_name;
int cond = -1;
String vs[];
Vector v_list = new Vector();
    jj_consume_token(27);
    variable_name = ProbabilityVariableName();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 29:
      cond = ConditionalMark(v_list);
      break;
    default:
      jj_la1[7] = jj_gen;
      ;
    }
          v_list.addElement(variable_name);
    label_5:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case WORD:
        ;
        break;
      default:
        jj_la1[8] = jj_gen;
        break label_5;
      }
      variable_name = ProbabilityVariableName();
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case 29:
        cond = ConditionalMark(v_list);
        break;
      default:
        jj_la1[9] = jj_gen;
        ;
      }
          v_list.addElement(variable_name);
    }
    jj_consume_token(28);
          vs = new String[v_list.size()];
          for (e=v_list.elements(), i=0; e.hasMoreElements(); i++)
                vs[i] = (String)(e.nextElement());
          upf.set_variables(vs);
          upf.set_conditional_index(cond);
  }

/* Find the conditional mark */
  final public int ConditionalMark(Vector v) throws ParseException {
    jj_consume_token(29);
      {if (true) return(v.size());}
    throw new Error("Missing return statement in function");
  }

/* Pick a single word as a probability variable name */
  final public String ProbabilityVariableName() throws ParseException {
Token t;

⌨️ 快捷键说明

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