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

📄 postorder.java

📁 自己写的search engine, 有 boolean search, fuzzy search
💻 JAVA
字号:
package searchingEngine.booleanModel;

import java.util.List;
import java.util.LinkedList;
import java.util.Stack;

public class PostOrder extends LinkedList<String>{
	private String input[];
	//private List input;
	private Stack<String> theStack;
	/*
	public PostOrder(List input) {
		  super();
		  this.input=input;
		  theStack = new Stack<String>();
		  doTrans();
	}
	
	private void doTrans() {
	    for (int j = 0; j < input.size(); j++) {
	      String ch = input[j];
	      
	      if (ch.equals("and") || ch.equals("or") || ch.equals("not"))
	      	gotOper(ch);
	      else if (ch.equals("(")) theStack.push(ch);
	      else if (ch.equals(")")) gotParen(ch);
	      else add(ch);
	    }
	    
	    while (!theStack.isEmpty()) {
	    	add(theStack.pop());
	    }
	    theStack = null;
	  }
	*/


  public PostOrder(String[] input) {
	  super();
	  this.input=input;
	  theStack = new Stack<String>();
	  doTrans();
  }
  

  private void doTrans() {
    for (int j = 0; j < input.length; j++) {
      String ch = input[j];
      
      if (ch.equalsIgnoreCase("and") || ch.equals("&") || ch.equalsIgnoreCase("or") || ch.equals("|") ||ch.equalsIgnoreCase("not") || ch.equals("!"))
      	gotOper(ch);
      else if (ch.equals("(")) theStack.push(ch);
      else if (ch.equals(")")) gotParen(ch);
      else add(ch);
    }
    
    while (!theStack.isEmpty()) {
    	add(theStack.pop());
    }
    theStack = null;
  }

  private void gotOper(String opThis) {
    while (!theStack.isEmpty()) {
      String opTop = theStack.pop();
      if (opTop.equals("(")) {
        theStack.push(opTop);
        break;
      }// it's an operator
      if (opTop.equalsIgnoreCase("and") || opTop.equals("&") || opTop.equalsIgnoreCase("or") || opTop.equals("|") || opTop.equalsIgnoreCase("not") || opTop.equals("!"))
    	  add(opTop); 
    }
    theStack.push(opThis);
  }

  private void gotParen(String ch){ 
    while (!theStack.isEmpty()) {
      String chx = theStack.pop();
      if (chx.equals("("))// == '(') 
        break; 
      else
    	  add(chx);// = output + chx; 
    }

  }

  public String[] getInput(){
	  return input;
  }
  
  public static void main(String[] args) {
    String input = new String("vsm  and ( example or tf ) and idf");
    System.out.println(input);
    
    String inputS[] = input.split(" ");
  
    PostOrder theTrans = new PostOrder(inputS);
    System.out.println(theTrans);

  }

}

⌨️ 快捷键说明

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