Use case - connect to dict server:
DictSession session = new DictSession("test.dict.org"); session.setLogAppender(new DictLogAppenderFile("protocol.log")); // optional session.open("test client"); session.close();
Use custom port:
DictSession session = new DictSession("test.dict.org", 1234);
Use caching:
DictSession session = new DictSessionWithCache("test.dict.org", new MemoryCacheProvider(30)); // cache TTL in seconds
Use case - get all available databases from test.dict.org:
DictSession session = new DictSession("test.dict.org"); session.open("test client"); try { List<Database> databases = session.showDatabases(); } finally { session.close(); } foreach (Database database : databases) { System.out.println(database.getName() + ": " + database.getDescription()); }
Use case - get all available search strategies from test.dict.org:
DictSession session = new DictSession("test.dict.org"); session.open("test client"); try { List<Strategy> strategies = session.showStrategies(); } finally { session.close(); } session.close(); foreach (Strategy strategy : strategies) { System.out.println(strategy.getName() + ": " + strategy.getDescription()); }
Use case - find all words with prefix "hel" in all databases
DictSession session = new DictSession("test.dict.org"); session.open("test client"); try { List<DatabaseWord> matches = session.match("hel", "!", "prefix"); // "!" means all databases by rfc } finally { session.close(); }
or if you already have Strategy or Database object from previous calls:
DictSession session = new DictSession("test.dict.org"); session.open("test client"); try { List<DatabaseWord> matches = session.match("hel", database, strategy); } finally { session.close(); }
Use case - get Definition of word "hello" from database wordnet
DictSession session = new DictSession("test.dict.org"); session.open("test client"); try { Definition def = session.define("hello", "wordnet"); } finally { session.close(); } System.out.println(def.getDatabase().getName() + ":"); System.out.println(def.getWord() + " = " + def.getText());
Use case - client authorization:
DictSession session = new DictSession("test.dict.org"); session.open("test client"); try { if (session.auth("username", "secret")) { System.out.println("Access granted"); } } finally { session.close(); }
For further details please see Javadoc API reference documentation