HomeHanBar™ Lexicon • Expression Server

Brought to you by

Overview

The Hanbar™ Lexicon Expression Server sends you a random expression from the Hanbar database. By following the instructions below, you can show a phrase-a-day on your website, and start practicing your Chinese today.

How it Works

The Expression Server has access to the same database of expressions that Hanbar Lexicon uses. You use it by visiting this page with a few parameters, such as the subject category, and the format you want the Expression Server to present it to you. Some of the categories are:

  • animals
  • cities
  • countries
  • conversation
  • dynasties
  • provinces
  • time

How To (The Basics)

The Expression Server can send you an expression in a variety of ways, but probably the simplest is to ask for a little bit of JavaScript that you include into your webpage, followed by a bit more JavaScript you put directly into your web page. The first bit is the expression the Expression Server has chosen for you, the second bit allows you to decide how to make it look on your page.

Here's one possible way of doing this. You can copy this and paste it into your web page.

You can substitute another category in place of conversation if you'd prefer.

If your sample is producing a random jumble of letters and strange jibberish instead of Chinese characters, it could be because your web page isn't set to use Unicode. This can be fixed by making sure the meta tag shown below appears near the top of your webpage:

If you don't have access to the head section of your web page, or if you already have another charset given there, you'll have to resort to advanced programming techniques.

Anyway, the example above is just does a bare-bones presentation. A bit more HTML, and you can have a rather fancy presentation.

The possibilities are limited only by your imagination. See the "JS Format" section, below, for a full description of the JavaScript object that Expression Server sends to you.

How To (Advanced)

For the techno-geeky, here are all the parameters in their full glory:

  Pick one of these... ... followed by this
cat=categoryname picks a random expression from those belonging to the category you indicate format=response format allows you to pick which of several formats the Expression Server will use when sending you an expresion. You can pick one of formats described below.
pinyin=pinyin syllable(s) picks a random expression from those that contain he given pinyin syllable(s).
expr=character(s) picks a random expression from those that contain the given character(s)
def=definition picks a random expresion from those that contain the given meaning.

The formats available are:

  response format meaning
xml This uses HanBar Expression schema XML to provide you the selected expression. It's the default format, meaning that if you leave off the format= parameter, this is what is used.
xml7 This is similar to the xml option, using only 7-bit ASCII characters. Consequently, (a) Chinese characters are replaced with their Unicode codepoint values, and (b) the pinyin characters use the numeric tone system rather than special accented vowels. This format is to accomodate those environments that don't support wide Unicode characters (you'll have to convert the characters yourself.)
js This uses Java Script object notation (not JSON, see below) to give you an expression that you can easily process using JavaScript.
js7 This is the same as above, but again uses only 7-bit ASCII characters so again, the Chinese characters are replaced with Unicode representation and the pinyin uses numeric tone codes.
json This is true JSON, or Java Script Object Notation (note the capitalization.) This is very similar to the js format above, but follows the JSON syntax rules.
json7 this is just like the JSON, but like the other 7-bit options described above, the Chinese and pinyin accented vowels are presented in plain ASCII text.

Examples:

http://woxuezhongwen.com/hanbar/exprserver.asp?cat=conversation&format=js
This example fetches one of the expressions from the conversation category, sending back the response in JavaScript object notation.
http://woxuezhongwen.com/hanbar/exprserver.asp?pinyin=bu4&format=xml
This example fetches one of the expressions with a character pronounced bu in the 4th tone, returning the response in Hanbar XML.

The Fine Print

Using the Expression Server is free. The only thing we ask is that you attribute us as the provider of the expressions, and put a link to the http://woxuezhongwen.com main site near the provided content. It can be as simple as the following:

That's not too much to ask, is it?

Thanks, and enjoy!

Support MediusRes.com