📄 thesaurus.java
字号:
/* -*- mode:java; indent-tabs-mode:nil; c-basic-offset:2 -*- * $RCSFile$ $Revision: 1.8 $ $Date: 2006/02/01 00:20:28 $ * Copyright (c) 2003 Autonomy Corp. All Rights Reserved. */import java.io.*;import java.util.*;import com.ultraseek.xpa.server.*;/** * Thesaurus Suggestion sample application. * <p> * This application demonstrates how to use Ultraseek to * suggest additional terms based on the Ultraseek * thesaurus. * <p> * The suggestions can vary based on the <code>Locale</code> * in use for the query. * <p> * To use this application, edit the file "Sample.properties" * to point to your Ultraseek server. * <p> * Also edit the array <code>locales</code> to set the locales * to use for the demo. * * @since XPA2.1 * @see UltraseekServer#thesaurusExpand * @requires Ultraseek 5.1.1 */public class Thesaurus { /* Locales to use for this demo of thesarus suggestions */ static Locale[] locales = { Locale.getDefault(), Locale.ENGLISH, Locale.FRENCH, Locale.GERMAN, new Locale("es","") // Spanish }; /** * Loads parameters from the file Sample.properties */ static String getString(String key, String def) { try { String resourceName = System.getProperty("Sample"); if (resourceName==null) resourceName = "Sample"; ResourceBundle settings = ResourceBundle.getBundle( resourceName ); return settings.getString(key); } catch (MissingResourceException e) { return def; } catch (Exception e) { System.out.println( "Property file problem: " + e ); return def; } } static final String serverName = getString("UltraseekServer.host", "software-demo.ultraseek.com"); static final int serverPort = Integer.valueOf(getString("UltraseekServer.port", "80")).intValue(); static final String serverProto = getString("UltraseekServer.protocol", "http"); static UltraseekServer server = new UltraseekServer(serverName, serverPort, serverProto); /** * Creates a thesaurus suggestion for a query, using the specified * <code>Locale</code>. */ static void demoThesarus(String msg, String query, Locale locale) { long start = System.currentTimeMillis(); // Fetch a thesaurus suggestion String suggestions[]; try { suggestions = server.thesaurusExpand(query,locale); } catch (IOException e) { // In a real application you would handle an IOException by // ignoring it, and not displaying any thesaurus suggestion. // In this demo, we will report the problem. suggestions = new String[] {"Problem fetching suggestions: " + e}; } long end = System.currentTimeMillis(); StringBuffer sb = new StringBuffer(80); sb.append(msg); String part2 = " " + (end-start) + "ms"; for (int i = sb.length() + part2.length(); i < 21; i++) sb.append( " " ); sb.append(part2); sb.append( " --> " ); for (int i = 0; i < suggestions.length; i++) { String suggestion = suggestions[i]; if (i!=0) sb.append(", "); sb.append( suggestion ); } System.out.println( sb.toString() ); } /** * Create thesaurus suggestions for a query using different Locales. */ static void demoLocales(String query) { System.out.println("\nLocale Demo - Query: " + query); for (int i = 0; i < locales.length; i++) { demoThesarus(locales[i].toString(), query, locales[i]); } } static public void main(String args[]) throws IOException { System.out.println("Thesaurus Demo"); System.out.println("Using Ultraseek at " + server ); System.out.println(" (version " + server.getVersionString() +")" ); if (!server.versionAtLeast(5,1,1)) { System.out.println("Ultraseek version 5.1.1 (or newer) is required for this demo." ); return; } System.out.println( "" ); demoLocales("Ultraseek C++ blueberry"); InputStreamReader inputStreamReader = new InputStreamReader(System.in); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); while (true) { System.out.print("\nEnter a query (EOF to end): "); String line = bufferedReader.readLine(); if (line==null) break; demoLocales( line ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -