Tjones has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/291939

Change subject: Create initial version of TextCat Demo
......................................................................

Create initial version of TextCat Demo

Create a simple demo page in labs that allows people to interact
with TextCat, to try it out, provide feedback, and consider
using it themselves.

BUG: T134427
Change-Id: I159b4318fa5e1ce36b902b1a19dfb84b1409758e
---
A LICENSE
A README.md
A add.png
A blank.html
A close.png
A external.png
A index.html
A info.png
A textcatdemo.css
A textcatdemo.js
A textcatdemo.php
11 files changed, 1,468 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/textcat-demo 
refs/changes/39/291939/1

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..5f2dd7f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,505 @@
+                  GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+(This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.)
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard.  To achieve this, non-free programs must be
+allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+                  GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+  6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+  You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License.  You must supply a copy of this License.  If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License.  Also, you must do one
+of these things:
+
+    a) Accompany the work with the complete corresponding
+    machine-readable source code for the Library including whatever
+    changes were used in the work (which must be distributed under
+    Sections 1 and 2 above); and, if the work is an executable linked
+    with the Library, with the complete machine-readable "work that
+    uses the Library", as object code and/or source code, so that the
+    user can modify the Library and then relink to produce a modified
+    executable containing the modified Library.  (It is understood
+    that the user who changes the contents of definitions files in the
+    Library will not necessarily be able to recompile the application
+    to use the modified definitions.)
+
+    b) Use a suitable shared library mechanism for linking with the
+    Library.  A suitable mechanism is one that (1) uses at run time a
+    copy of the library already present on the user's computer system,
+    rather than copying library functions into the executable, and (2)
+    will operate properly with a modified version of the library, if
+    the user installs one, as long as the modified version is
+    interface-compatible with the version that the work was made with.
+
+    c) Accompany the work with a written offer, valid for at
+    least three years, to give the same user the materials
+    specified in Subsection 6a, above, for a charge no more
+    than the cost of performing this distribution.
+
+    d) If distribution of the work is made by offering access to copy
+    from a designated place, offer equivalent access to copy the above
+    specified materials from the same place.
+
+    e) Verify that the user has already received a copy of these
+    materials or that you have already sent this user a copy.
+
+  For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it.  However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+  It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system.  Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+  7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+    a) Accompany the combined library with a copy of the same work
+    based on the Library, uncombined with any other library
+    facilities.  This must be distributed under the terms of the
+    Sections above.
+
+    b) Give prominent notice with the combined library of the fact
+    that part of it is a work based on the Library, and explaining
+    where to find the accompanying uncombined form of the same work.
+
+  8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License.  Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License.  However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+  9. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Library or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+  10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+  11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded.  In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+  13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation.  If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+  14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission.  For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this.  Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+                            NO WARRANTY
+
+  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+           How to Apply These Terms to Your New Libraries
+
+  If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change.  You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+  To apply these terms, attach the following notices to the library.  It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+    {description}
+    Copyright (C) {year} {fullname}
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
+    USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the
+  library `Frob' (a library for tweaking knobs) written by James Random
+  Hacker.
+
+  {signature of Ty Coon}, 1 April 1990
+  Ty Coon, President of Vice
+
+That's all there is to it!
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f14370a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,21 @@
+# TextCat Demo
+
+This is a lightweight web-based demo of 
[TextCat](https://www.mediawiki.org/wiki/TextCat), the n-gram–based language 
identification utility.
+
+You will also need the [PHP-based version of 
TextCat](https://github.com/wikimedia/wikimedia-textcat) to run the demo.
+
+## Contents
+
+The package contains the HTML, CSS, JavaScript, and PNG files need to run the 
demo on top of an installation of the PHP-based version of TextCat.
+
+## Installation
+
+In the same directory as the TextCat Demo files in this repository, clone a 
copy of the PHP-based version of TextCat:
+
+    git clone https://github.com/wikimedia/wikimedia-textcat textcat
+
+The file `index.html` is the entry point into the demo.
+
+## Demo Walkthroughs
+
+There are a number of walkthroughs that show some of the features and 
limitations of TextCat in the dropdown list, "Pick a TextCat Demo!"
diff --git a/add.png b/add.png
new file mode 100644
index 0000000..b4ce217
--- /dev/null
+++ b/add.png
Binary files differ
diff --git a/blank.html b/blank.html
new file mode 100644
index 0000000..9cf90b4
--- /dev/null
+++ b/blank.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+<body bgcolor=#fff>
+<span style="color:#ccc; font-family:sans-serif">Wikipedia search 
results...</span>
+</body>
+</html>
\ No newline at end of file
diff --git a/close.png b/close.png
new file mode 100644
index 0000000..b5ed167
--- /dev/null
+++ b/close.png
Binary files differ
diff --git a/external.png b/external.png
new file mode 100644
index 0000000..d979922
--- /dev/null
+++ b/external.png
Binary files differ
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..1695b05
--- /dev/null
+++ b/index.html
@@ -0,0 +1,189 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>WMF Discovery—TextCat Demo</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="description" content="Live demo of modernized TextCat libraries 
for language detection, from the Wikimedia Foundation Discovery team." />
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<link rel="stylesheet" type="text/css" href="textcatdemo.css">
+<script src="textcatdemo.js"></script>
+
+<!--
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+http://www.gnu.org/copyleft/gpl.html
+-->
+
+</head>
+<body style="background-color:#f9f9f9; margin:0; font-family:sans-serif">
+
+<div class="container" style="background-color:#fff">
+
+<div id="demoDiv" style="position:fixed; top:2em; right:2em; left:2em; border: 
3px solid #dd9; background-color: #ffd; font-size:90%; display:none; 
line-height:140%; max-height:50%; overflow: scroll">
+       <div style="float:right; margin:0.25em 0.25em 0 0.1em;" class="dismiss" 
onclick="hideDemo(1)"><img src="close.png" style='height:1em' alt="Close demo." 
title="Close Demo."></div>
+       <div style="margin:1em">
+               <div id="demoTitle" style="font-weight:bold">
+               Demo Title
+               </div>
+               <div id="demoText">
+               Demo info.
+               </div>
+               <br class='clearIt'>
+               <div class="demoContinue" id="demoContinue" 
onclick="demoNext();">Continue&nbsp;➤</div>
+               <div class="details" style="margin-bottom:-0.5rem; 
margin-top:0.4rem">Use “Continue” or the right arrow key to move through the 
demo.</div>
+               <br class='clearIt'>
+       </div>
+</div>
+
+<div id="infoPop" style="position:fixed; top:2em; right:2em; left:2em;  
border:3px solid #a3b0bf; background-color: #cedff2; font-size:90%; 
display:none; line-height:140%; max-height:80%; overflow: scroll">
+       <div style="float:right; margin:0.25em 0.25em 0 0.1em;" class="dismiss" 
onclick="closeInfo()"><img src="close.png" style='height:1em' alt="Close info 
box." title="Close info box."></div>
+       <div id="infoPopText" style="margin:1em;">
+       <span class="dimText">Additional Information...</span>
+       </div>
+</div>
+
+<div id="TextCatHeaderContainer" class="subContainer" 
style="background-color:#f9f9f9; border:1px solid #ccc">
+       <div id="TextCatHeader" style="float:left;">
+               <h1 style="padding:0; margin:0; 
font-variant:small-caps;">TextCat Demo<span class=info 
onclick="showInfo(0)"><img src='info.png' style='height:1em' alt="Get more 
info." title="Get more info."></span></h1>
+       </div>
+
+       <div class="pickADemo" style="float:right;">
+               <select id="demoPicker" onchange="startDemo(this.value);">
+                       <option value="-1" selected>Pick a TextCat 
Demo!</option>
+                       <option value="0">Europanto</option>
+                       <option value="1">Names are Weird</option>
+                       <option value="2">Unexpected Results</option>
+                       <option value="4">Chinese Challenges</option>
+                       <option value="3">Gibberish</option>
+               </select>
+               <span class=info onclick="showInfo(1)"><img src='info.png' 
style='height:1em' alt="Get more info." title="Get more info."></span>
+       </div>
+
+       <br class='clearIt'>
+</div>
+
+<div class="subContainer odd">
+       <div style="float:right" class="info" onclick="showInfo(2)"><img 
src='info.png' style='height:1em' alt="Get more info." title="Get more 
info."></div>
+       <div class="LMContainer">
+               <div class="LM" onclick="LMDirSelect(this)" id="LMDirQuery" 
style="font-weight:bold">Query Lan&shy;guage Models</div>
+               <div class="LM dimText" onclick="LMDirSelect(this)" id="LMDir" 
font-weight:normal">Wiki-Text Lan&shy;guage Models</div>
+       </div>
+       <div class="LMList" id="LMDirQueryModels">
+               <div style="float:left; margin-left:-1.5em"><div 
class="dismiss" onclick="LMClear()"><img src="close.png" style='height:1em' 
alt="Deselect all languages." title="Deselect all languages."></div><div 
class="dismiss" onclick="LMAll()"><img src="add.png" style='height:1em' 
alt="Select all languages." title="Select all languages."></div></div>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Afrikaans">Afrikaans</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Albanian">Albanian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Arabic">Arabic</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Armenian">Armenian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Basque">Basque</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Belarusian">Belarusian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Bengali">Bengali</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Bosnian">Bosnian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Breton">Breton</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Bulgarian">Bulgarian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Burmese">Burmese</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Cantonese">Cantonese</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Catalan">Catalan</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Chinese">Chinese</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Croatian">Croatian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Czech">Czech</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Danish">Danish</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Dutch">Dutch</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="English">English</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Esperanto">Esperanto</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Estonian">Estonian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Finnish">Finnish</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="French">French</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Georgian">Georgian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="German">German</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Greek">Greek</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Gujarati">Gujarati</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Hebrew">Hebrew</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Hindi">Hindi</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Hungarian">Hungarian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Icelandic">Icelandic</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Indonesian">Indonesian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Irish">Irish</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Italian">Italian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Japanese">Japanese</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Javanese">Javanese</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Kannada">Kannada</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Korean">Korean</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Latin">Latin</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Latvian">Latvian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Lithuanian">Lithuanian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Malay">Malay</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Malayalam">Malayalam</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Marathi">Marathi</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Norwegian">Norwegian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Oriya">Oriya</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Persian">Persian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Polish">Polish</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Portuguese">Portuguese</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Romanian">Romanian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Russian">Russian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Scots">Scots</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Serbian">Serbian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="SerboCroatian">Serbo-Croatian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Slovak">Slovak</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Slovenian">Slovenian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Spanish">Spanish</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Sundanese">Sundanese</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Swedish">Swedish</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Tagalog">Tagalog</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Tamil">Tamil</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Telugu">Telugu</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Thai">Thai</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Turkish">Turkish</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Turkmen">Turkmen</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Ukrainian">Ukrainian</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Urdu">Urdu</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Vietnamese">Vietnamese</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="Welsh">Welsh</span>
+               <span class="langModel" onclick="LMToggle(this)" 
id="WesternPunjabi">Western Punjabi</span>
+               <br class='clearIt'>
+               <div class="moreLess" id="moreLess" 
onclick="extraLangToggle(this);">more...</div>
+               <br class='clearIt'>
+               <div class="details" style="margin-bottom:-0.5rem; 
margin-top:0.4rem">Select the languages to be considered when identifying the 
query below.</div>
+       </div>
+       <br class='clearIt'>
+</div>
+
+<div class="subContainer even">
+       <div style="float:right" class="info" onclick="showInfo(3)"><img 
src='info.png' style='height:1em' alt="Get more info." title="Get more 
info."></div>
+       <div>
+       Query<br>
+       <textarea rows="3" class="embiggen" style="margin-top:0.5em; 
font-size:1em" onkeypress="return catchReturn(this);" id="queryTA"></textarea>
+       </div>
+       <div class="details" style="margin-bottom:-0.5rem;">Type your query and 
then &lt;enter&gt; to submit your query for language detection. Results will be 
shown below.</div>
+       <br class='clearIt'>
+</div>
+
+<div class="subContainer odd">
+       <div style="float:right" class="info" onclick="showInfo(4)"><img 
src='info.png' style='height:1em' alt="Get more info." title="Get more 
info."></div>
+       <div id="IDresults" class="embiggen" style="min-height:2em">
+       <span class="dimText">Language ID results...</span>
+       </div>
+       <div class="details" style="margin-bottom:-1rem;">Click on the name of 
a language to view search results below.</div>
+       <br class='clearIt'>
+</div>
+
+<div class="subContainer even">
+<div>Wikipedia search results</div>
+       <div style="float:right" class="info" onclick="showInfo(5)"><img 
src='info.png' style='height:1em' alt="Get more info." title="Get more 
info."></div>
+       <iframe src="blank.html" class="embiggen" style="margin:0.5em auto; 
height:400px; border:1px solid #ccc; display:block;" name="iframeWiki"></iframe>
+       <br class='clearIt'>
+</div>
+
+
+</div>
+</body>
+</html>
\ No newline at end of file
diff --git a/info.png b/info.png
new file mode 100644
index 0000000..a9cc35c
--- /dev/null
+++ b/info.png
Binary files differ
diff --git a/textcatdemo.css b/textcatdemo.css
new file mode 100644
index 0000000..6606459
--- /dev/null
+++ b/textcatdemo.css
@@ -0,0 +1,186 @@
+.external::after { 
+    content: url('external.png');
+    padding-left:0.2em;
+}
+
+.embiggen {
+    width: 95%;
+}
+
+.container {
+    margin: 1em;
+    padding: 0;
+    border: 1px solid #bdf;
+}
+
+.subContainer {
+    margin: .5em;
+    padding: 1em;
+}
+
+.info {
+    font-size: 1rem;
+    cursor: help;
+    vertical-align: middle;
+    font-variant: normal;
+    margin-left: .5rem;
+}
+
+.infoIcon {
+    float: left;
+    font-size: 150%;
+    font-weight: 700;
+    margin: .5rem .25rem .25rem;
+}
+
+.dismiss {
+    font-size: 1rem;
+    cursor: pointer;
+    vertical-align: middle;
+    font-variant: normal;
+}
+
+.LM {
+    float: left;
+    margin: -1px -1px 0 0;
+    padding: .5em;
+    border: 1px solid #a3bfb1;
+    cursor: pointer;
+    background-color: #cef2e0;
+}
+
+.langModel {
+    padding: .1em;
+    cursor: pointer;
+}
+
+.LMList {
+    clear: left;
+    margin-left: 2em;
+    padding-top: .5em;
+    line-height: 150%;
+}
+
+.LMContainer {
+    display: flex;
+}
+
+.dimText {
+       color:#ccc;
+}
+
+.clearIt {
+       clear:both;
+       line-height:0;
+}
+
+.details {
+       color:#999;
+    font-size:90%;
+    font-style:italic;
+    line-height:120%;
+    float:left;
+    clear:left;
+}
+
+.moreLess {
+    float: right;
+    margin-bottom: -1rem;
+    padding: 0 .5em 0 .6em;
+    border: 1px solid #ccc;
+    background-color: #f4f4f4;
+    font-size: 75%;
+    cursor: pointer;
+    font-weight: 700;
+}
+
+.demoContinue {
+    float: right;
+    padding: 0 .5em 0 .6em;
+    margin-top:-0.75rem;
+    border: 1px solid #ccc;
+    background-color: #f4f4f4;
+    font-size: 75%;
+    cursor: pointer;
+    font-weight: 700;
+}
+
+.pickADemo {
+    margin-top: .5em;
+}
+
+.langRes {
+    float: left;
+    margin-right: 1em;
+    margin-bottom: .5em;
+}
+
+.odd,.even {
+    border: 1px solid #ccc;
+}
+
+.odd {
+    background-color: #f5fffa;
+}
+
+.even {
+    background-color: #f5faff;
+}
+
+@media (min-width:450px) and (max-width: 675px) {
+    .embiggen {
+        width: 90%;
+    }
+
+    h1 {
+        font-size: 150%;
+    }
+
+    .pickADemo {
+        margin-top: .1em;
+    }
+}
+
+@media (min-width:301px) and (max-width: 449px) {
+    .embiggen {
+        width: 85%;
+    }
+
+    h1 {
+        font-size: 120%;
+    }
+
+    .pickADemo {
+        margin-top: 0;
+    }
+}
+
+@media (max-width: 300px) {
+    .embiggen {
+        width: 100%;
+        clear: right;
+    }
+
+    h1 {
+        font-size: 120%;
+    }
+
+    .pickADemo {
+        margin-top: .1em;
+    }
+
+    .LMContainer {
+        width: 90%;
+        display: block;
+        clear: right;
+    }
+
+    .LM {
+        float: none;
+        width: 100%;
+    }
+
+    body {
+        font-size: 80%;
+    }
+}
\ No newline at end of file
diff --git a/textcatdemo.js b/textcatdemo.js
new file mode 100644
index 0000000..f50abde
--- /dev/null
+++ b/textcatdemo.js
@@ -0,0 +1,508 @@
+var initLangs = ['English', 'French', 'German', 'Italian', 'Spanish'];
+
+var extraLangs = ['Afrikaans', 'Albanian', 'Armenian', 'Basque', 'Belarusian',
+    'Bengali', 'Bosnian', 'Breton', 'Bulgarian', 'Burmese', 'Cantonese',
+    'Catalan', 'Croatian', 'Czech', 'Danish', 'Dutch', 'Esperanto',
+    'Estonian', 'Finnish', 'Georgian', 'Gujarati', 'Hindi', 'Hungarian',
+    'Icelandic', 'Indonesian', 'Irish', 'Javanese', 'Kannada',
+    'Latin', 'Latvian', 'Lithuanian', 'Malay', 'Malayalam', 'Marathi',
+    'Norwegian', 'Oriya', 'Persian', 'Polish', 'Portuguese', 'Romanian',
+    'Scots', 'Serbian', 'SerboCroatian', 'Slovak', 'Slovenian', 'Sundanese',
+    'Swedish', 'Tagalog', 'Tamil', 'Telugu', 'Turkish', 'Turkmen',
+    'Ukrainian', 'Urdu', 'Vietnamese', 'Welsh', 'WesternPunjabi'
+];
+
+var wikiLangs = ['Afrikaans', 'Albanian', 'Basque', 'Belarusian', 'Bosnian',
+    'Breton', 'Burmese', 'Cantonese', 'Catalan', 'Croatian', 'Danish',
+    'Esperanto', 'Estonian', 'Finnish', 'Gujarati', 'Hungarian',
+    'Icelandic', 'Irish', 'Javanese', 'Kannada', 'Latin', 'Latvian',
+    'Lithuanian', 'Malay', 'Malayalam', 'Marathi', 'Norwegian', 'Oriya',
+    'Romanian', 'Scots', 'Serbian', 'SerboCroatian', 'Slovak', 'Slovenian',
+    'Sundanese', 'Tagalog', 'Turkmen', 'Urdu', 'Welsh', 'WesternPunjabi'
+];
+
+var activeLangs = {};
+
+var showExtraLangs = 0;
+var showWikiLangs = 0;
+
+var textCatDirs = ["LM-query/", "LM/"];
+var textCatDir = textCatDirs[0];
+
+var demoNum = -1;
+var demoStep = -1;
+
+
+function setInitLangs() {
+       initializeLangs(initLangs, 0, 0);
+       }
+
+function initializeLangs(theLangs, theDir, theMore) {
+       activeLangs = {};
+
+       showWikiLangs = 1 - theDir;
+       LMDirSelect(document.querySelectorAll(".LM")[theDir]);
+
+       showExtraLangs = 1 - theMore;
+       extraLangToggle(document.querySelector("#moreLess"));
+
+    for (var i = 0; i < theLangs.length; i++) {
+        var lang = document.querySelector("#" + theLangs[i]);
+        LMToggle(lang);
+    }
+    displayLangs();
+}
+
+document.addEventListener("DOMContentLoaded", function(event) {
+    setInitLangs();
+});
+
+document.addEventListener("keydown", catchKeyDownEvent, false);
+
+function LMClear() {
+    var langs = document.querySelectorAll(".langModel");
+    for (var i = 0; i < langs.length; i++) {
+        langs[i].style.color = "black";
+        langs[i].style.border = "";
+    }
+       activeLangs = {};
+}
+
+function LMAll() {
+    var langs = document.querySelectorAll(".langModel");
+    for (var i = 0; i < langs.length; i++) {
+        langs[i].style.color = "black";
+        langs[i].style.border = "";
+    }
+       activeLangs = {};
+    for (var i = 0; i < langs.length; i++) {
+               LMToggle(langs[i]);
+    }
+}
+
+function LMToggleByName(name) {
+       LMToggle(document.querySelector("#" + name));
+       }
+
+function LMToggle(item) {
+    if (activeLangs[item.id] == 1) {
+        item.style.color = "black";
+        item.style.border = "";
+        activeLangs[item.id] = 0;
+    } else {
+        item.style.color = "green";
+        item.style.border = "1px solid #a3bfb1";
+        activeLangs[item.id] = 1;
+    }
+}
+
+function LMDirSelect(item) {
+    var tabs = document.querySelectorAll(".LM");
+    showWikiLangs = 0;
+    for (var i = 0; i < tabs.length; i++) {
+        if (tabs[i] == item) {
+            tabs[i].style.color = "#000";
+            tabs[i].style.fontWeight = "bold";
+            textCatDir = textCatDirs[i];
+            showWikiLangs = i;
+        } else {
+            tabs[i].style.color = "#ccc";
+            tabs[i].style.fontWeight = "normal";
+        }
+    }
+    displayLangs();
+}
+
+function extraLangToggle(item) {
+    if (showExtraLangs == 1) {
+        item.innerHTML = "more...";
+        showExtraLangs = 0;
+    } else {
+        item.innerHTML = "less...";
+        showExtraLangs = 1;
+    }
+    displayLangs();
+}
+
+function displayLangs() {
+    for (var i = 0; i < extraLangs.length; i++) {
+        var lang = document.querySelector("#" + extraLangs[i]);
+        lang.style.display = showExtraLangs ? "inline" : "none";
+    }
+    for (var i = 0; i < wikiLangs.length; i++) {
+        var lang = document.querySelector("#" + wikiLangs[i]);
+        lang.style.display = showWikiLangs ? "inline" : "none";
+    }
+    if (!showExtraLangs) {
+        for (var i = 0; i < extraLangs.length; i++) {
+            var lang = document.querySelector("#" + extraLangs[i]);
+            lang.style.display = "none";
+        }
+    }
+}
+
+function catchReturn(ta) {
+    if (window.event.keyCode == 13) {
+        submitQuery();
+        return false;
+    }
+    return true;
+}
+
+function catchKeyDownEvent(e) {
+    if (e.keyCode == 13) {
+        submitQuery();
+        return;
+    }
+    if (e.keyCode == 39) {
+       if (document.getElementById("queryTA") != document.activeElement) {
+                       demoNext();
+                       }
+        return;
+    }
+    if (e.keyCode == 27) {
+        closeInfo();
+        hideDemo(0);
+        return;
+    }
+}
+
+function langIDLink(lang, score, basescore, query) {
+    // 
https://en.m.wikipedia.org/w/index.php?title=Special:Search&fulltext=Search&search=qqq
+    var relScore = score / basescore;
+    return "<a target='iframeWiki' href='https://"; + lang +
+        ".m.wikipedia.org/w/index.php?title=Special:Search&" +
+        "fulltext=Search&uselang=en&search=" + encodeURI(query) + "'>" + 
+        code2lang[lang] + "</a> (" + relScore.toFixed(4) + ")";
+}
+
+function submitQuery(query = "") {
+       var ta = document.getElementById("queryTA");
+       if (query) {
+               ta.value=query;
+               }
+       var idResults = document.getElementById("IDresults");
+       ta.value = ta.value.replace(/^\s+/, "");
+       ta.value = ta.value.replace(/\s+$/, "");
+       var query = ta.value;
+
+    if (query != "") {
+       idResults.innerHTML = "<span class='dimText'>...Thinking...</span>";
+        var lang = "";
+        for (var l in activeLangs) {
+            if (activeLangs[l]) {
+               if (document.getElementById(l).style.display != "none") {
+                       lang += (lang ? "," : "") + lang2code[l];
+                       }
+            }
+        }
+        var msize = 3000;
+        if (lang) {
+            var xmlhttp = new XMLHttpRequest();
+            xmlhttp.onreadystatechange = function() {
+                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+                    var output = "";
+                    if (xmlhttp.responseText.match(/^Cannot/)) {
+                        output = xmlhttp.responseText;
+                    } else {
+                        var phpResults = JSON.parse(xmlhttp.responseText);
+                        var basescore = 1;
+                        for (var detectedLang in phpResults) {
+                            if (output == "") {
+                                basescore = phpResults[detectedLang];
+                            }
+                            output += "<div class='langRes'>" +
+                                langIDLink(detectedLang, phpResults[
+                                    detectedLang], basescore, query) +
+                                "</div>";
+                        }
+                    }
+                    idResults.innerHTML = output;
+                }
+            };
+            xmlhttp.open("GET", "textcatdemo.php?q=" + encodeURI(query) +
+                "&lang=" + encodeURI(lang) + "&dir=" + encodeURI(
+                    textCatDir) + "&msize=" + encodeURI(msize), true);
+            xmlhttp.send();
+            return;
+        }
+    }
+    clearIDresults();
+}
+
+function clearIDresults() {
+       document.getElementById("IDresults").innerHTML =
+        '<span class="dimText">Language ID results...</span>';
+       }
+
+function closeInfo() {
+    document.querySelector("#infoPop").style.display = "none";
+    document.querySelector("#infoPopText").innerHTML =
+        '<span class="dimText">Additional Information...</span>';
+}
+
+function showInfo(msgNum) {
+    document.querySelector("#infoPopText").innerHTML =
+        "<div class='infoIcon'><img src='info.png' style='height:1em'></div>" +
+        infoMsg[msgNum];
+    document.querySelector("#infoPop").style.display = "block";
+}
+
+// Demos
+demoScript = [
+               // Europanto
+               [ "Europanto",
+                 [
+                       ["<a class=external 
href='https://en.wikipedia.org/wiki/Europanto' target=_blank>Europanto</a> is a 
macaronic language (i.e., a mixture of languages), made up of whatever European 
languages the speaker wishes to use. Of course, it will be difficult for 
TextCat to handle since it is a mix of languages and there is no single right 
answer. In this demo we&rsquo;ll look at how TextCat&rsquo;s results depend on 
the languages selected for comparison.",
+                        ""],
+                       ["Let&rsquo;s use the Query Language Models with the 
larger list of languages, and activate Dutch, English, French, German, Italian, 
Portuguese, and Spanish.",
+                        
"initializeLangs(['English','Spanish','French','German','Portuguese', 
'Italian', 'Dutch'], 0, 1)"],
+                       ["After pasting the <a class=external 
href='https://en.wikipedia.org/wiki/Europanto#Example' target=_blank>Europanto 
Example text</a> from English Wikipedia into the Query box, submit it to 
TextCat. The results should be German followed closely by Dutch, with English 
and French in third and fourth place, and Italian coming in a distant fifth.",
+                        "submitQuery('Europanto want nicht informe aber amuse. 
Porqué betanke aan die illuminante forza van eine laugh, sometimes man remarque 
things dat anders el hadde noticed nicht. Laugh esse directe emanatione des 
intelligence, Aristotele dixit.');"],
+                       ["Let&rsquo;s disable German and re-submit to TextCat. 
Now English is first with French a very close second, followed by Italian, as 
before. Spanish is now fourth. When German was available, Spanish didn&rsquo;t 
score well enough to be reported.",
+                        "LMToggleByName('German'); LMToggleByName('Dutch'); 
submitQuery();"],
+                       ["Let&rsquo;s disable English and French and try again. 
Now Italian moves up to first place, with Spanish in second. Portuguese makes 
an appearance. You can try the same query string using the Wiki-Text Language 
Models to see how they behave differently from the Query Language Models.",
+                        "LMToggleByName('English'); LMToggleByName('French'); 
submitQuery();"],
+                       ["For use on a Wikipedia—say, to redirect queries in 
another language to a different wiki—we need to tune the languages we want to 
consider based on what other-language queries occur most frequently on that 
Wikipedia. We don&rsquo;t want to include languages that rarely occur or that 
get many more errors than correct answers. You can read a lot more about this 
kind of <a target=_blank class=external 
href='https://www.mediawiki.org/wiki/User:TJones_(WMF)/Notes/TextCat_Optimization_for_frwiki_eswiki_itwiki_and_dewiki'>tuning
 for French, Spanish, Italian, and German Wikipedias</a>.",
+                        ""]
+                 ]
+               ],
+               // Names are Weird
+               [ "Names are Weird",
+                 [
+                       ["Names are particularly hard when it comes to language 
identification, in part because they are often short, and in part because they 
aren’t really in a particular language. The line between the <a class=external 
href='https://en.wikipedia.org/wiki/Ethnolinguistics' 
target=_blank>ethnolinguistic</a> source of a name and a given language can be 
more or less blurry, depending on the writing system, the popularity of the 
name around the world (<i><a class=external 
href='https://en.wikipedia.org/wiki/Maria_(given_name)' 
target=_blank>Maria</a>,</i> for example, is common across incredibly diverse 
cultures), the ethnolinguistic distinctiveness of the name elements, where the 
person was born, etc.",
+                        ""],
+                       ["Let’s look at four celebrity names of distinctive 
ethnolinguistic decent; all of these celebrities were born in the United 
States. These names were chosen in part for their relative fame, and so happen 
to have articles in the languages TextCat thinks they are in. That’s not always 
the case for less famous people, who may be notable in one culture/language, 
while not being well-known in the language most associated with their names.",
+                        ""],
+                       ["We&rsquo;ll use the Query Language Models with the 
larger list of languages, and activate all of the languages, just to make 
things hard. (And a bit slower—so be patient.)",
+                        
"extraLangToggle(document.querySelector('#moreLess'));LMAll();"],
+                       ["Our first name is <a class=external 
href='https://en.wikipedia.org/wiki/Carla_Gugino' target=_blank>Carla 
Gugino</a>, an American actress of Italian descent, born in Florida. Her name 
is very Italian.",
+                        "submitQuery('Carla Gugino');"],
+                       ["Our next name is <a class=external 
href='https://en.wikipedia.org/wiki/Mehmet_Oz' target=_blank>Mehmet Öz</a>, the 
full name of the Turkish-American surgeon and TV personality better known as 
Dr. Oz. He was born in Ohio. His name is very Turkish, in particular his given 
name, <i>Mehmet,</i> which is the Turkish form of <i>Muhammad.</i>",
+                        "submitQuery('Mehmet Öz');"],
+                       ["Next up is <a class=external 
href='https://en.wikipedia.org/wiki/Jane_Kaczmarek' target=_blank>Jane 
Kaczmarek</a>, an American actress of Polish descent, born in Wisconsin. While 
<i>Jane</i> is a common name in English-speaking countries, <i>Kaczmarek</i> 
has the very distinctive Polish <i>cz</i> in it.",
+                        "submitQuery('Jane Kaczmarek');"],
+                       ["<a class=external 
href='https://en.wikipedia.org/wiki/Robert_Kardashian' target=_blank>Ռոբերտ 
Քարդաշյան</a> is Robert Kardashian’s name in Armenian script. He was born in 
California, but the Armenian version of his name, not surprisingly, is very 
Armenian.",
+                        "submitQuery('Ռոբերտ Քարդաշյան');"],
+                       ["Names with multiple ethnolinguistic sources are most 
likely to give... “interesting” results. You can try the names of other 
celebrities, with all the languages, or a more restricted set. For example, <a 
class=external 
href='https://en.wikipedia.org/wiki/C%C3%A9lia_%C5%A0a%C5%A1i%C4%87' 
target=_blank>Célia Šašić</a> is a German footballer. She has a French given 
name by birth and a Croatian surname by marriage. What’s the right “language” 
in which to categorize her name?<br><br>Try the Query Language Models and the 
Wiki-Text Language Models on her name before finishing the demo.",
+                        "clearIDresults(); 
document.getElementById('queryTA').value='Célia Šašić';"],
+                 ]
+               ],
+               // Unexpected Results
+               [ "Unexpected Results and Language Tuning",
+                 [
+                       ["Since TextCat’s language identification is based on 
statistical models, there will always be the possibility of odd results, 
particularly on shorter strings—where there isn’t much on which to gather 
statistics—and strings that either happen not to be very typical of their 
language, or happen to have characteristics typical of another language.",
+                        ""],
+                       ["When deciding which languages models to use on German 
Wikipedia, for example, we looked to see what languages other than German were 
present in a sample of poorly performing queries (i.e., those with fewer than 3 
results). The <a class=external 
href='https://www.mediawiki.org/wiki/User:TJones_(WMF)/Notes/TextCat_Optimization_for_frwiki_eswiki_itwiki_and_dewiki#German_Results'
 target=_blank>languages found</a>, by volume, were English, Italian, Spanish, 
French, Chinese, Polish, Vietnamese, Turkish, Swedish, and Dutch. There was 
also some Latin, but we don’t have a model for that. Let’s activate the rest of 
them.",
+                        "initializeLangs(['English', 'Italian', 'Spanish', 
'French', 'Chinese', 'Polish', 'Vietnamese', 'Turkish', 'Swedish', 'Dutch'], 0, 
1)"],
+                       ["Our first examples is <i>impstoffe adhaesive</i>, a 
typo for <i>impfstoffe adhaesive,</i> which means “vaccines adhesive”. TextCat 
recognizes it as English. Restoring the missing <i>f</i> gives is the more 
distinctively German <i>pf</i> cluster, and German edges out English instead of 
the other way around. <br><br>Mistakes will happen, and in our test set, there 
were 124 out of 520 queries in English. 76/124 were correctly tagged as 
English, with only 4 other non-English tagged incorrectly. So having English in 
the mix does more good than not.",
+                        "submitQuery('impstoffe adhaesive');"],
+                       ["Medical and scientific terminology often get borrowed 
from language to language. The word <i>aortotomie,</i> meaning “aortotomy”—an 
incision of the aorta—is identified by TextCat as Italian. The source of 
<i>aorta</i> in English is Latin, from earlier Greek, and it is spelled exactly 
the same in at least a <a class=external 
href='https://en.wiktionary.org/wiki/aorta' target=_blank>dozen languages</a>, 
and similarly in many others. While <i>Aortotomie</i>, properly capitalized in 
German, is a German word, it’s also the same in French. Scientific terms in 
isolation can be very ambiguous.<br><br>Overall, there were only 8 out of 520 
Italian queries in our sample. 5/8 were identified as Italian, but 12 more were 
incorrectly identified as Italian. Including Italian does more harm than good.",
+                        "submitQuery('aortotomie');"],
+                       ["Next, <i>personalunion</i>, meaning “staff union”, is 
identified as Spanish. Overall, there were only 8 out of 520 Spanish queries in 
our sample. 7/8 were identified as Spanish (pretty good!), but 14 non-Spanish 
queries were incorrectly identified as Spanish. Having Spanish does more harm 
than good.",
+                        "submitQuery('personalunion');"],
+                       ["Compound nouns are very Germanic, but 
<i>organisationsdokumentation</i>, “organizational documentation”, was 
identified as French. There were only 5 out of 520 French queries in our 
sample, with 4 tagged correctly, but 13 non-French queries tagged incorrectly. 
Including French does more harm than good.",
+                        "submitQuery('organisationsdokumentation');"],
+                       ["You can also click to try:<ul><li><i><a href='' 
onclick=\"submitQuery('Biolumineszenz'); return false;\">Bioluminiszez</a>,</i> 
typo for <i>Biolumineszenz,</i> “bioluminescence”, which is tagged as 
Polish</li><li><i><a href='' onclick=\"submitQuery('humanmedezin'); return 
false;\">humanmedezin</a>,</i> typo for <i>humanmedizin,</i> “human medicine”, 
which is tagged as Turkish</li><li><i><a href='' 
onclick=\"submitQuery('Auflösevermögen'); return 
false;\">Auflösevermögen</a>,</i> “resolving power”, which is tagged as 
Swedish, and</li><li><i><a href='' onclick=\"submitQuery('kammilentee'); return 
false;\">kammilentee</a>,</i> typo for <i>kamillentee,</i> “Camomile tea”, 
which is tagged as Dutch.</li></ul>Dutch and Swedish were both rare—only one 
example in our sample—but both were very bad about incorrectly tagging queries 
in German, with more than 30 each incorrectly tagged in our sample of only 
520.",
+                        "submitQuery('');"],
+                       ["When tuning the choice of languages to include for 
detection for a given wiki, it’s important to know how often they are likely to 
occur, and how often they are likely to be tagged incorrectly. If Italian, 
Spanish, or French were more common among queries on German Wikipedia, it would 
make sense to tolerate a relatively small number of identification errors. 
Dutch or Swedish would have to be much more common to offset the likelihood of 
errors. As it is, though, including these languages generates significantly 
more incorrect answers than correct, so it’s best to exclude them.",
+                        ""],
+                 ]
+               ],
+               // Gibberish
+               [ "Gibberish: Garbage In, Garbage Out",
+                 [
+                       ["We get a surprising number of gibberish queries on 
the various Wikipedias. For example, <i>fdshkfldshflshdkflsr.</i> These pose a 
minor problem for language identification. Obviously they aren’t in any 
particular language, but they may be identified as being in some language by 
TextCat, because the statistics will always have a least bad match.",
+                        ""],
+                       ["Enabling all the smaller set of Query Language 
Models, we can submit <i>fdshkfldshflshdkflsr</i> for identification and see 
that it is scores similarly for all of German, English, French, Italian, and 
Spanish—that is, all the languages available that use the Latin alphabet; there 
really isn’t much to distinguish it among them other than slight statistical 
variations.",
+                        "LMAll();submitQuery('fdshkfldshflshdkflsr');"],
+                       ["If we enable more languages TextCat cannot even guess 
at what language <i>fdshkfldshflshdkflsr</i> is in, as the scores across all 
the languages in the Latin alphabet are too similar, and—as configured 
here—TextCat deems any result as too ambiguous if more than five languages are 
within 5% of each other.",
+                        
"extraLangToggle(document.querySelector('#moreLess'));submitQuery('fdshkfldshflshdkflsr');"],
+                       ["If we enable five models for languages that don’t use 
the Latin alphabet, the scores on our gibberish (or any other string of Latin 
characters) are all 1.0000. Every <a class=external 
href='https://en.wikipedia.org/wiki/N-gram' target=_blank>n-gram</a> in the 
string received the unknown n-gram penalty score in each language, so they are 
all the same. Upon closer inspection, note that the results are sorted in 
reverse alphabetical order by language code (the code for Chinese is “zh”, for 
example), rather than numerically, because that’s all there is to sort on.",
+                        "LMClear();initializeLangs(['Arabic', 'Armenian', 
'Bengali', 'Bulgarian', 'Chinese'], 0, 1); 
submitQuery('fdshkfldshflshdkflsr');"],
+                       ["In an actual Wikipedia search scenario, a gibberish 
query is unlikely to get a match on the wiki it’s on. If language detection 
returns another language, it’s also unlikely to get any results on that other 
wiki, which just wastes CPU cycles. A potential future project is gibberish 
detection, which would allow us to note this kind of query and allow us to 
treat them differently—not expending too much extra effort to get results, or 
ignoring them in certain data analyses.<br><br>But of course we’d still search 
for them! Old school sci-fi fans would recognize that <a class=external 
href='https://en.wikipedia.org/wiki/Electronic_Labyrinth:_THX_1138_4EB' 
target=_blank>THX 1138 4EB</a> is not gibberish, and elite H4x0rs would 
certainly note that <a class=external 
href='https://en.wikipedia.org/wiki/10100111001' target=_blank>10100111001</a> 
is meaningful.",
+                        ""],
+                 ]
+               ],
+               // Chinese Challenges
+               [ "Chinese Can Be Harder Than It Would Seem",
+                 [
+                       ["It seems like Chinese should be easy to identify, and 
when it occurs by itself, it usually is. But when it is mixed with other 
languages, or even just with text in the Latin alphabet, weird things can 
happen.",
+                        "extraLangToggle(document.querySelector('#moreLess')); 
LMClear();"],
+                       ["The current Chinese language model was built like all 
the other language models, and so it includes <a class=external 
href='https://en.wikipedia.org/wiki/N-gram' target=_blank>n-grams</a> of size 
from 1 to 5. When many languages share a writing system, like the Latin 
alphabet, the distribution of characters and the co-occurence of characters are 
very important in distinguishing languages. Although Chinese characters 
<i>are</i> used in other writing systems, they are distinctly Chinese when they 
occur alone.",
+                        ""],
+                       ["Another important issue is that Chinese writing uses 
many more unique characters than most writing systems, so not all of them are 
present in our models. Our default model size is 3000 n-grams, and at the 
moment it’s important to use the same model size across language models so the 
scoring is normalizes. Even a 5000 n-gram model has fewer than 2300 distinct 
characters in it, so the rarer Chinese characters are not even represented. 
Also note that at the level of individual characters, common single Latin 
letters are much more frequent in their language models (such as <i>e, a, i, o, 
n, r, t,</i> and <i>s</i> in English) than any individual Chinese character is 
in the Chinese language model.",
+                        ""],
+                       ["As a result, we can get some unexpected results when 
Chinese and Latin characters are mixed, especially if the Chinese characters 
are rare or few in number. We have a fairly frequent pattern of queries that 
consist of a snippet of Chinese text followed by something that looks like a 
serial number or other arbitrary string of letters and numbers. Sometimes the 
letters happen to be very characteristic of a particular language that uses the 
Latin alphabet, and it overwhelms the Chinese statistics.",
+                        ""],
+                       ["Let’s activate a number of Chinese along with a 
number of European languages. Try any of these (see if you can guess the 
language before you click):<ul style='margin-bottom:0'><li><a href='' 
onclick=\"submitQuery('的科学研究17lho4232'); return 
false;\">的科学研究17lho4232</a></li><li><a href='' 
onclick=\"submitQuery('的科学研究17ein4232'); return 
false;\">的科学研究17ein4232</a></li><li><a href='' 
onclick=\"submitQuery('的科学研究17eau4232'); return 
false;\">的科学研究17eau4232</a></li><li><a href='' 
onclick=\"submitQuery('的科学研究17van4232'); return 
false;\">的科学研究17van4232</a></li><li><a href='' 
onclick=\"submitQuery('的科学研究17ight4232'); return 
false;\">的科学研究17ight4232</a></li><li><a href='' 
onclick=\"submitQuery('的科学研究17ione4232'); return 
false;\">的科学研究17ione4232</a></li><li><a href='' 
onclick=\"submitQuery('的科学研究17los4232'); return 
false;\">的科学研究17los4232</a></li><li><a href='' 
onclick=\"submitQuery('的科学研究17osz4232'); return 
false;\">的科学研究17osz4232</a></li></ul>",
+                        "initializeLangs(['Chinese', 'Portuguese', 'German', 
'French', 'Dutch', 'English', 'Italian', 'Spanish', 'Polish'], 0, 1);"],
+                       ["A future project may include doing some sort of 
Chinese-specific language modeling to improve coverage of and statistics for 
Chinese characters.",
+                        ""],
+                 ]
+               ],
+       ];
+
+
+// Info Boxes
+var infoMsg = [
+    // TextCat
+    "<b>TextCat</b> is a language detection library based on <a class=external 
href='https://en.wikipedia.org/wiki/N-gram' target=_blank>n-gram</a> text 
categorization. This is a demo of the <a class=external 
href='https://www.mediawiki.org/wiki/TextCat' target=_blank>modernized TextCat 
libraries</a>, ported from Perl to PHP by the Wikimedia Foundation Discovery 
team. It provides a look into how TextCat works&mdash;and sometimes 
doesn&rsquo;t work—and it&rsquo;s also just fun to play with.",
+    // demos
+    "These <b>demos</b> provide step-by-step walkthroughs of some of the 
features of TextCat, demonstrate how some of the settings affect 
TextCat&rsquo;s behavior, and show some interesting ways it can fail.",
+    //language models
+    "<p>We have two sets of <b>language models</b> available to TextCat. In 
general, these language models are frequency lists of <a class=external 
href='https://en.wikipedia.org/wiki/N-gram' target=_blank>n-grams</a> (in this 
case, substrings of 1 to 5 characters) found in example text. The frequency 
rank of n-grams extracted from new text to be identified is compared to these 
known models, and the closest matches are reported by TextCat.</p><p><b>Click 
on the languages you want TextCat to consider when identifying your 
query.</b></p><p>The <i>Query Language Models</i> are built on real query log 
data from Wikipedia in various languages. The <a class=external 
href='https://www.mediawiki.org/wiki/User:TJones_(WMF)/Notes/Language_Detection_with_TextCat#Query_Data_Collection'
 target=_blank>query data is very messy</a>, but better represents the 
idiosyncrasies of queries—shorter strings, more question words, fewer function 
words, frequent absence of diacritics, etc. There are fewer models, because 
they require more manual effort to create. The selection is based largely on 
query volume on the respective Wikipedias. These models generally work better 
on shorter strings in a less formal style of the sort that show up in the query 
logs.</p><p>The <i>Wiki-Text Language Models</i> are built on text extracted 
from Wikipedias in various languages. The data is generally cleaner, the 
writing more formal, and the models much less effort to generate. Many more 
models are available. The selection is based in part on sizes of Wikipedias, 
and the list of languages supported by the original version of TextCat. These 
models are probably better for more general use.</p>",
+    // queries
+    "Enter a <b>query</b> and hit return to send it off to TextCat, which will 
consider only the languages you&rsquo;ve selected above, using the model type 
you&rsquo;ve selected. Language identification and relative scores will be 
displayed below.",
+    //results
+    "<p>The scores used by TextCat and shown in the <b>language identification 
results</b> are technically <i>costs,</i> so the least costly model to match is 
the one TextCat likes best.</p><p>Since the cost of matching a model depends on 
the length of the string being matched—every <a class=external 
href='https://en.wikipedia.org/wiki/N-gram' target=_blank>n-gram</a> has a 
cost, so longer strings have bigger costs, even if they are good matches—the 
raw numbers don&rsquo;t mean much.</p><p>Here we show the costs relative to the 
lowest cost/best match, which thus always has a score of 1.000. TextCat only 
considers alternatives that have a score that is close to the best score 
(we&rsquo;ve set it for within 5%, so the maximum score that could be shown is 
1.0500).</p><p>If too many languages are detected (here set for more than 
five), TextCat says it can&rsquo;t determine the language the text is in.</p>",
+    //Wikipedia search results
+    "<p>If you click on the name of one of the languages detected by TextCat, 
your query will be sent to the appropriate Wikipedia and displayed.</p><p>Keep 
in mind that Wikipedia has a maximum query length of 300 characters, so you 
might be able to do language detection on your query/text, but not be able to 
search for it on Wikipedia.</p><p>Since it&rsquo;s unlikely that anyone will be 
able to read all the languages available in this demo, the <b>Wikipedia search 
results</b> are configured to use English as the user interface language for 
all results shown. The mobile version of the results is also used to keep 
things simple and streamlined.</p>"
+];
+
+var lang2code = {};
+lang2code['Afrikaans'] = 'af';
+lang2code['Czech'] = 'cs';
+lang2code['Estonian'] = 'et';
+lang2code['Hindi'] = 'hi';
+lang2code['Javanese'] = 'jv';
+lang2code['Marathi'] = 'mr';
+lang2code['Portuguese'] = 'pt';
+lang2code['Serbian'] = 'sr';
+lang2code['Turkish'] = 'tr';
+lang2code['Arabic'] = 'ar';
+lang2code['Welsh'] = 'cy';
+lang2code['Basque'] = 'eu';
+lang2code['Croatian'] = 'hr';
+lang2code['Georgian'] = 'ka';
+lang2code['Malay'] = 'ms';
+lang2code['Romanian'] = 'ro';
+lang2code['Sundanese'] = 'su';
+lang2code['Ukrainian'] = 'uk';
+lang2code['Belarusian'] = 'be';
+lang2code['Danish'] = 'da';
+lang2code['Persian'] = 'fa';
+lang2code['Hungarian'] = 'hu';
+lang2code['Kannada'] = 'kn';
+lang2code['Burmese'] = 'my';
+lang2code['Russian'] = 'ru';
+lang2code['Swedish'] = 'sv';
+lang2code['Urdu'] = 'ur';
+lang2code['Bulgarian'] = 'bg';
+lang2code['German'] = 'de';
+lang2code['Finnish'] = 'fi';
+lang2code['Armenian'] = 'hy';
+lang2code['Korean'] = 'ko';
+lang2code['Dutch'] = 'nl';
+lang2code['Scots'] = 'sco';
+lang2code['Tamil'] = 'ta';
+lang2code['Vietnamese'] = 'vi';
+lang2code['Bengali'] = 'bn';
+lang2code['Greek'] = 'el';
+lang2code['French'] = 'fr';
+lang2code['Indonesian'] = 'id';
+lang2code['Latin'] = 'la';
+lang2code['Norwegian'] = 'no';
+lang2code['Serbo-Croatian'] = 'sh';
+lang2code['Telugu'] = 'te';
+lang2code['Cantonese'] = 'zh-yue';
+lang2code['Breton'] = 'br';
+lang2code['English'] = 'en';
+lang2code['Irish'] = 'ga';
+lang2code['Icelandic'] = 'is';
+lang2code['Lithuanian'] = 'lt';
+lang2code['Oriya'] = 'or';
+lang2code['Slovak'] = 'sk';
+lang2code['Thai'] = 'th';
+lang2code['Chinese'] = 'zh';
+lang2code['Bosnian'] = 'bs';
+lang2code['Esperanto'] = 'eo';
+lang2code['Gujarati'] = 'gu';
+lang2code['Italian'] = 'it';
+lang2code['Latvian'] = 'lv';
+lang2code['Polish'] = 'pl';
+lang2code['Slovenian'] = 'sl';
+lang2code['Turkmen'] = 'tk';
+lang2code['Catalan'] = 'ca';
+lang2code['Spanish'] = 'es';
+lang2code['Hebrew'] = 'he';
+lang2code['Japanese'] = 'ja';
+lang2code['Malayalam'] = 'ml';
+lang2code['Western Punjabi'] = 'pnb';
+lang2code['Albanian'] = 'sq';
+lang2code['Tagalog'] = 'tl';
+
+// create inverse index
+var code2lang = {};
+for (var lang in lang2code) {
+    code2lang[lang2code[lang]] = lang;
+}
+
+// add alternate forms without spaces or dashes
+lang2code['SerboCroatian'] = 'sh';
+lang2code['WesternPunjabi'] = 'pnb';
+
+// Demos
+function startDemo(num) {
+       hideDemo(1);
+
+    if (num == -1) {
+        return;
+    }
+    demoNum = num;
+    demoStep = 0;
+    document.querySelector("#demoDiv").style.display = "block";
+    document.querySelector("#TextCatHeader").style.display = "none";
+    demoNext();
+}
+
+function hideDemo(forceIt) {
+       if (!forceIt && demoNum < 0) {
+               return;
+               }
+       demoStep = -1;
+       demoNum = -1;
+       demoText.innerHTML = "";
+
+       window.scrollTo(0,0);
+    document.getElementById("TextCatHeader").style.display = "block";
+    document.getElementById("TextCatHeaderContainer").style.paddingTop =
+        '1em';
+       document.getElementById("demoPicker").selectedIndex = 0;
+    document.getElementById("demoDiv").style.display = "none";
+    document.getElementById("demoContinue").innerHTML = "Continue&nbsp;➤";
+       clearIDresults();
+
+    LMClear();
+    LMDirSelect(document.querySelector("#LMDirQuery"));
+    document.getElementById('queryTA').value = "";
+    setInitLangs();
+}
+
+function demoNext() {
+       if (demoNum < 0) {
+               return;
+               }
+
+       var demoDiv = document.querySelector("#demoDiv");
+    var demoText = document.querySelector("#demoText");
+    var demoTitle = document.querySelector("#demoTitle");
+    demoTitle.innerHTML = demoScript[demoNum][0];
+    var demoSteps = demoScript[demoNum][1];
+    if (demoStep < demoSteps.length) {
+        demoText.innerHTML = demoSteps[demoStep][0];
+        demoDiv.scrollTop = 0;
+        if (demoSteps[demoStep][1] != "") {
+            eval(demoSteps[demoStep][1]);
+        }
+        if (demoStep == demoSteps.length - 1) {
+            document.querySelector("#demoContinue").innerHTML = "End.";
+        }
+        document.querySelector("#TextCatHeaderContainer").style.paddingTop =
+            document.querySelector("#demoDiv").offsetHeight + 8 + "px";
+    } else if (demoStep >= demoSteps.length) {
+        hideDemo(1);
+        return;
+    }
+    demoStep += 1;
+}
\ No newline at end of file
diff --git a/textcatdemo.php b/textcatdemo.php
new file mode 100644
index 0000000..f83db65
--- /dev/null
+++ b/textcatdemo.php
@@ -0,0 +1,53 @@
+<?php
+
+// This program is the PHP backend for the TextCat Demo web interface.
+// It is adapted from catus.php in the TextCat PHP implementation:
+//    https://github.com/wikimedia/wikimedia-textcat
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+// http://www.gnu.org/copyleft/gpl.html
+
+
+require_once __DIR__.'/textcat/TextCat.php';
+
+// php catus.php -c "en,fr,de" -d LM-query/ -t 3000 -l "linguistics ist zehr 
awesome"
+
+$lang  = $_REQUEST["lang"];
+$dir   = 
$_REQUEST["dir"]?__DIR__.'/textcat/'.$_REQUEST["dir"]:__DIR__.'/textcat/LM';
+$msize = $_REQUEST["msize"]?$_REQUEST["msize"]:3000;
+$q     = $_REQUEST["q"];
+
+$output = "";
+
+$output .= "query: " . $q . "<br>";
+$output .= "dir: "   . $dir . "<br>";
+$output .= "lang: "  . $lang . "<br>";
+$output .= "msize: " . $msize . "<br>";
+
+$cat = new TextCat( $dir );
+$cat->setMaxNgrams( intval( $msize ) );
+$result = $cat->classify( $q, explode( ",", $lang ) );
+
+$max = reset( $result ) * 1.05;
+
+$top = 5;
+
+$result = array_filter( $result, function ( $res ) use( $max ) { return $res < 
$max; } );
+
+if ( $result && count( $result ) <= $top ) {
+       echo json_encode($result);
+} else {
+       echo "Cannot determine language.";
+}
+
+?>
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/291939
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I159b4318fa5e1ce36b902b1a19dfb84b1409758e
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/textcat-demo
Gerrit-Branch: master
Gerrit-Owner: Tjones <tjo...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to