Package org.encog.util

Examples of org.encog.util.SimpleParser


   * @return The parsed values.
   */
  public static Map<String, String> parseParams(final String line) {
    final Map<String, String> result = new HashMap<String, String>();

    final SimpleParser parser = new SimpleParser(line);

    while (!parser.eol()) {
      final String name = ArchitectureParse.parseName(parser)
          .toUpperCase();

      parser.eatWhiteSpace();
      if (!parser.lookAhead("=", false)) {
        throw new EncogError("Missing equals(=) operator.");
      } else {
        parser.advance();
      }

      final String value = ArchitectureParse.parseValue(parser);

      result.put(name.toUpperCase(), value);

      if (!parser.parseThroughComma()) {
        break;
      }
    }

    return result;
View Full Code Here


    }
  }
 
  private List<String> parseSpaceSep(final String line) {
    final List<String> result = new ArrayList<String>();
    SimpleParser parse  = new SimpleParser(line);
   
    while(!parse.eol()) {
      if( parse.peek()=='\"') {
        result.add( parse.readQuotedString() );
      } else {
        result.add( parse.readToWhiteSpace() );
      }
      parse.eatWhiteSpace();
    }
   
    return result;
  }
View Full Code Here

      // special case, we add a left-paren for the shunting yard alg.
      this.name = theSignature;
      this.returnValue = null;
    } else {
      // non-special case, find the name of the function/operator
      final SimpleParser parser = new SimpleParser(theSignature);
      boolean pass = false;

      parser.eatWhiteSpace();
      this.name = parser.readToChars("(").trim();
      parser.advance();

      boolean done = false;
      while (!done) {
        if (parser.peek() == ')') {
          parser.advance();
          done = true;
        } else if (parser.peek() == ':') {
          parser.advance();
          pass = true;
        } else if (parser.peek() == '{') {
          final ParamTemplate temp = readParam(parser);
          temp.setPassThrough(pass);
          pass = false;
          this.params.add(temp);
        } else {
          parser.advance();
          if( parser.eol() ) {
            throw new EncogError("Invalid opcode template.");
          }
        }
      }

      // get the return type
      parser.eatWhiteSpace();
      if (!parser.lookAhead(":")) {
        throw new EACompileError("Return type not specified.");
      }
      parser.advance();
      parser.eatWhiteSpace();
      this.returnValue = readParam(parser);
    }
  }
View Full Code Here

   */
  public ParsedProbability parse(String line) {
   
    ParsedProbability result = new ParsedProbability();

    SimpleParser parser = new SimpleParser(line);
    parser.eatWhiteSpace();
    if (!parser.lookAhead("P(", true)) {
      throw new EncogError("Bayes table lines must start with P(");
    }
    parser.advance(2);

    // handle base
    addEvents(parser, result.getBaseEvents(), "|,)=[]");

    // handle conditions
    if (parser.peek() == '|') {
      parser.advance();
      addEvents(parser, result.getGivenEvents(), ",)=[]");

    }

    if (parser.peek() != ')') {
      throw new BayesianError("Probability not properly terminated.");
    }

    return result;
 
View Full Code Here

   * @return The parsed values.
   */
  public static Map<String, String> parseParams(final String line) {
    final Map<String, String> result = new HashMap<String, String>();

    final SimpleParser parser = new SimpleParser(line);

    while (!parser.eol()) {
      final String name = ArchitectureParse.parseName(parser)
          .toUpperCase();

      parser.eatWhiteSpace();
      if (!parser.lookAhead("=", false)) {
        throw new EncogError("Missing equals(=) operator.");
      } else {
        parser.advance();
      }

      final String value = ArchitectureParse.parseValue(parser);

      result.put(name.toUpperCase(), value);

      if (!parser.parseThroughComma()) {
        break;
      }
    }

    return result;
View Full Code Here

    // misplaced or parentheses were mismatched.

  }

  public ProgramNode parse(final String expression) {
    this.parser = new SimpleParser(expression);
    this.unary = true;

    while (!parser.eol()) {
      parser.eatWhiteSpace();
      char ch = parser.peek();
View Full Code Here

  public ParseEPL(final EncogProgram theHolder) {
    this.holder = theHolder;
  }
 
  public ProgramNode parse(final String expression) {
    this.parser = new SimpleParser(expression);
   
    while(!this.parser.eol()) {
      this.parser.eatWhiteSpace();
     
      // read in the command
View Full Code Here

    }
  }
 
  private List<String> parseSpaceSep(final String line) {
    final List<String> result = new ArrayList<String>();
    SimpleParser parse  = new SimpleParser(line);
   
    while(!parse.eol()) {
      if( parse.peek()=='\"') {
        result.add( parse.readQuotedString() );
      } else {
        result.add( parse.readToWhiteSpace() );
      }
      parse.eatWhiteSpace();
    }
   
    return result;
  }
View Full Code Here

TOP

Related Classes of org.encog.util.SimpleParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.