當前位置: 首頁>>代碼示例>>Java>>正文


Java WAQuery.setInput方法代碼示例

本文整理匯總了Java中com.wolfram.alpha.WAQuery.setInput方法的典型用法代碼示例。如果您正苦於以下問題:Java WAQuery.setInput方法的具體用法?Java WAQuery.setInput怎麽用?Java WAQuery.setInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.wolfram.alpha.WAQuery的用法示例。


在下文中一共展示了WAQuery.setInput方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getQueryResult

import com.wolfram.alpha.WAQuery; //導入方法依賴的package包/類
public WAQueryResult getQueryResult(String query) {
	String url;
	try {
		url = "http://www.wolframalpha.com/input/?i=" + URLEncoder.encode(query, "UTF-8");
	} catch (UnsupportedEncodingException e1) {
	}
	// openUrl(url);
	// The WAEngine is a factory for creating WAQuery objects,
	// and it also used to perform those queries. You can set properties of
	// the WAEngine (such as the desired API output format types) that will
	// be inherited by all WAQuery objects created from it. Most
	// applications
	// will only need to crete one WAEngine object, which is used throughout
	// the life of the application.
	WAEngine engine = new WAEngine();

	// These properties will be set in all the WAQuery objects created from
	// this WAEngine.
	engine.setAppID(AppID);
	engine.addFormat("plaintext");
	engine.addFormat("image");

	// Create the query.
	WAQuery waquery = engine.createQuery();

	// Set properties of the query.
	waquery.setInput(query);

	try {
		// For educational purposes, print out the URL we are about to send:
		// System.out.println("Query URL:");
		// System.out.println(engine.toURL(waquery));
		// System.out.println("");

		// This sends the URL to the Wolfram|Alpha server, gets the XML
		// result
		// and parses it into an object hierarchy held by the WAQueryResult
		// object.
		return engine.performQuery(waquery);
	} catch (Exception e) {
	}
	return null;
}
 
開發者ID:glaudiston,項目名稱:project-bianca,代碼行數:44,代碼來源:WolframAlpha.java

示例2: getQueryResult

import com.wolfram.alpha.WAQuery; //導入方法依賴的package包/類
public WAQueryResult getQueryResult(String query) {
  // String url;
  // try {
  // url = "http://www.wolframalpha.com/input/?i=" + URLEncoder.encode(query,
  // "UTF-8");
  // } catch (UnsupportedEncodingException e1) {
  // }
  // openUrl(url);
  // The WAEngine is a factory for creating WAQuery objects,
  // and it also used to perform those queries. You can set properties of
  // the WAEngine (such as the desired API output format types) that will
  // be inherited by all WAQuery objects created from it. Most
  // applications
  // will only need to crete one WAEngine object, which is used throughout
  // the life of the application.
  WAEngine engine = new WAEngine();

  // These properties will be set in all the WAQuery objects created from
  // this WAEngine.
  engine.setAppID(AppID);
  engine.addFormat("plaintext");
  engine.addFormat("image");

  // Create the query.
  WAQuery waquery = engine.createQuery();

  // Set properties of the query.
  waquery.setInput(query);

  try {
    // For educational purposes, print out the URL we are about to send:
    // System.out.println("Query URL:");
    // System.out.println(engine.toURL(waquery));
    // System.out.println("");

    // This sends the URL to the Wolfram|Alpha server, gets the XML
    // result
    // and parses it into an object hierarchy held by the WAQueryResult
    // object.
    return engine.performQuery(waquery);
  } catch (Exception e) {
  }
  return null;
}
 
開發者ID:MyRobotLab,項目名稱:myrobotlab,代碼行數:45,代碼來源:WolframAlpha.java


注:本文中的com.wolfram.alpha.WAQuery.setInput方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。