text:
import os
import shutil
import time

from logger import logger
from perfrunner.helpers import local
from perfrunner.helpers.cbmonitor import with_stats
from perfrunner.helpers.profiler import with_profiles
from perfrunner.helpers.worker import ycsb_data_load_task, ycsb_task
from perfrunner.tests import PerfTest
from perfrunner.tests.n1ql import N1QLTest

class YCSBTest(PerfTest):

    ALL_BUCKETS = True

    def download_ycsb(self):
        if self.worker_manager.is_remote:
            self.remote.init_ycsb(
                    repo=self.test_config.ycsb_settings.repo,
                    branch=self.test_config.ycsb_settings.branch,
                    worker_home=self.worker_manager.WORKER_HOME,
                    sdk_version=self.test_config.ycsb_settings.sdk_version)
        else:
            local.clone_git_repo(repo=self.test_config.ycsb_settings.repo,
                                 branch=self.test_config.ycsb_settings.branch)

    def build_ycsb(self, ycsb_client):
        if self.worker_manager.is_remote:
            self.remote.build_ycsb(self.worker_manager.WORKER_HOME, ycsb_client)
        else:
            local.build_ycsb(ycsb_client)

    def collect_export_files(self):
        if self.worker_manager.is_remote:
            shutil.rmtree("YCSB", ignore_errors=True)
            os.mkdir('YCSB')
            self.remote.get_export_files(self.worker_manager.WORKER_HOME)

    def load(self, *args, **kwargs):
        self.build_ycsb(self.test_config.load_settings.ycsb_client)
        PerfTest.load(self, task=ycsb_data_load_task)

    @with_stats
    @with_profiles
    def access(self, *args, **kwargs):
        self.build_ycsb(self.test_config.access_settings.ycsb_client)
        PerfTest.access(self, task=ycsb_task)
        self.wait_for_persistence()

    def access_bg(self, *args, **kwargs):
        self.build_ycsb(self.test_config.access_settings.ycsb_client)
        PerfTest.access_bg(self, task=ycsb_task)

    @with_stats
    def collect_cb(self):
        duration = self.test_config.access_settings.time
        self.cb_start = duration*0.8
        time.sleep(self.cb_start)
        start_time = time.time()
        self.remote.collect_info()
        end_time = time.time()
        self.cb_time = round(end_time - start_time)
        logger.info("cbcollect_info finished and it took: {} seconds".format(self.cb_time))
        self.worker_manager.wait_for_workers()

    def generate_keystore(self):
        if self.worker_manager.is_remote:
            self.remote.generate_ssl_keystore(self.ROOT_CERTIFICATE,
                                              self.test_config.access_settings
                                              .ssl_keystore_file,
                                              self.test_config.access_settings
                                              .ssl_keystore_password,
                                              self.worker_manager.WORKER_HOME)
        else:
            local.generate_ssl_keystore(self.ROOT_CERTIFICATE,
                                        self.test_config.access_settings.ssl_keystore_file,
                                        self.test_config.access_settings.ssl_keystore_password)

    def run(self):
        if self.test_config.access_settings.ssl_mode == 'data':
            self.download_certificate()
            self.generate_keystore()
        self.download_ycsb()

        self.load()
        if self.dynamic_infra:
            time.sleep(30)
        else:
            self.wait_for_persistence()
            self.check_num_items()

        if self.test_config.access_settings.cbcollect:
            self.access_bg()
            self.collect_cb()
        else:
            self.access()

        self.report_kpi()

class YCSBThroughputTest(YCSBTest):

    COLLECTORS = {'disk': True, 'net': True}

    def _report_kpi(self):
        self.collect_export_files()

        self.reporter.post(
            *self.metrics.ycsb_throughput()
        )

class YCSBDurabilityThroughputTest(YCSBTest):

    COLLECTORS = {'disk': True, 'net': True}

    def log_latency_percentiles(self, type: str, percentiles):
        for percentile in percentiles:
            latency_dic = self.metrics.ycsb_get_latency(percentile=percentile)
            for key, value in latency_dic.items():
                if str(percentile) in key \
                        and type in key \
                        and "CLEANUP" not in key \
                        and "FAILED" not in key:
                    logger.info("{}: {}".format(key, latency_dic[key]))

    def log_percentiles(self):
        logger.info("------------------")
        logger.info("Latency Percentiles")
        logger.info("-------READ-------")
        self.log_latency_percentiles("READ", [95, 96, 97, 98, 99])
        logger.info("------UPDATE------")
        self.log_latency_percentiles("UPDATE", [95, 96, 97, 98, 99])
        logger.info("------------------")

    def _report_kpi(self):
        self.collect_export_files()

        self.log_percentiles()

        for key, value in self.metrics.ycsb_get_max_latency().items():
            max_latency, _, _ = self.metrics.ycsb_slo_max_latency(key, value)
            logger.info("Max {} Latency: {}".format(key, max_latency))

        for key, value in self.metrics.ycsb_get_failed_ops().items():
            failures, _, _ = self.metrics.ycsb_failed_ops(key, value)
            logger.info("{} Failures: {}".format(key, failures))

        gcs, _, _ = self.metrics.ycsb_gcs()
        logger.info("Garbage Collections: {}".format(gcs))

        self.reporter.post(
            *self.metrics.ycsb_durability_throughput()
        )

        for percentile in self.test_config.ycsb_settings.latency_percentiles:
            latency_dic = self.metrics.ycsb_get_latency(percentile=percentile)
            for key, value in latency_dic.items():
                if str(percentile) in key \
                        and "CLEANUP" not in key \
                        and "FAILED" not in key:
                    self.reporter.post(
                        *self.metrics.ycsb_slo_latency(key, latency_dic[key])
                    )

class YCSBLatencyTest(YCSBTest):

    COLLECTORS = {'disk': True, 'net': True}

    def _report_kpi(self):
        self.collect_export_files()

        for percentile in self.test_config.ycsb_settings.latency_percentiles:
            latency_dic = self.metrics.ycsb_get_latency(percentile=percentile)
            for key, value in latency_dic.items():
                if str(percentile) in key \
                        and "CLEANUP" not in key \
                        and "FAILED" not in key:
                    self.reporter.post(
                        *self.metrics.ycsb_latency(key, latency_dic[key])
                    )

        if self.test_config.ycsb_settings.average_latency == 1:
            latency_dic = self.metrics.ycsb_get_latency(
                percentile=99)

            for key, value in latency_dic.items():
                if "Average" in key \
                        and "CLEANUP" not in key \
                        and "FAILED" not in key:
                    self.reporter.post(
                        *self.metrics.ycsb_latency(key, latency_dic[key])
                    )

class YCSBSOETest(YCSBThroughputTest, N1QLTest):

    def run(self):
        self.download_ycsb()
        self.restore()
        self.wait_for_persistence()

        self.create_indexes()
        self.wait_for_indexing()

        self.load()

        self.access()

        self.report_kpi()

class YCSBN1QLTest(YCSBTest, N1QLTest):

    def run(self):
        if self.test_config.access_settings.ssl_mode == 'data':
            self.download_certificate()
            self.generate_keystore()
        self.download_ycsb()

        self.create_indexes()
        self.wait_for_indexing()

        self.load()
        self.wait_for_persistence()
        self.check_num_items()
        self.wait_for_indexing()

        if self.test_config.access_settings.cbcollect:
            self.access_bg()
            self.collect_cb()
        else:
            self.access()

        self.report_kpi()

class YCSBN1QLLatencyTest(YCSBN1QLTest, YCSBLatencyTest):

    pass

class YCSBN1QLThroughputTest(YCSBN1QLTest, YCSBThroughputTest):

    pass


text:
package springfox.documentation.swagger.readers.operation;

import io.swagger.annotations.ApiOperation;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.OperationBuilderPlugin;
import springfox.documentation.spi.service.contexts.OperationContext;
import springfox.documentation.swagger.common.SwaggerPluginSupport;

@Component
@Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER)
public class OperationSummaryReader implements OperationBuilderPlugin {

  @Override
  public void apply(OperationContext context) {
    ApiOperation apiOperationAnnotation = context.getHandlerMethod().getMethodAnnotation(ApiOperation.class);
    if (null != apiOperationAnnotation && StringUtils.hasText(apiOperationAnnotation.value())) {
      context.operationBuilder().summary(apiOperationAnnotation.value());
    }
  }

  @Override
  public boolean supports(DocumentationType delimiter) {
    return SwaggerPluginSupport.pluginDoesApply(delimiter);
  }
}

redpajama_set_name: RedPajamaGithub


text:
package com.xxl.job.admin.controller;

import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.model.XxlJobLogGlue;
import com.xxl.job.admin.core.util.I18nUtil;
import com.xxl.job.admin.dao.XxlJobInfoDao;
import com.xxl.job.admin.dao.XxlJobLogGlueDao;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.glue.GlueTypeEnum;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * job code controller
 * @author xuxueli 2015-12-19 16:13:16
 */
@Controller
@RequestMapping("/jobcode")
public class JobCodeController {

	@Resource
	private XxlJobInfoDao xxlJobInfoDao;
	@Resource
	private XxlJobLogGlueDao xxlJobLogGlueDao;

	@RequestMapping
	public String index(HttpServletRequest request, Model model, int jobId) {
		XxlJobInfo jobInfo = xxlJobInfoDao.loadById(jobId);
		List<XxlJobLogGlue> jobLogGlues = xxlJobLogGlueDao.findByJobId(jobId);

		if (jobInfo == null) {
			throw new RuntimeException(I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
		}
		if (GlueTypeEnum.BEAN == GlueTypeEnum.match(jobInfo.getGlueType())) {
			throw new RuntimeException(I18nUtil.getString("jobinfo_glue_gluetype_unvalid"));
		}

		// valid permission
		JobInfoController.validPermission(request, jobInfo.getJobGroup());

		// Glue类型-字典
		model.addAttribute("GlueTypeEnum", GlueTypeEnum.values());

		model.addAttribute("jobInfo", jobInfo);
		model.addAttribute("jobLogGlues", jobLogGlues);
		return "jobcode/jobcode.index";
	}

	@RequestMapping("/save")
	@ResponseBody
	public ReturnT<String> save(Model model, int id, String glueSource, String glueRemark) {
		// valid
		if (glueRemark==null) {
			return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_glue_remark")) );
		}
		if (glueRemark.length()<4 || glueRemark.length()>100) {
			return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_remark_limit"));
		}
		XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(id);
		if (exists_jobInfo == null) {
			return new ReturnT<String>(500, I18nUtil.getString("jobinfo_glue_jobid_unvalid"));
		}

		// update new code
		exists_jobInfo.setGlueSource(glueSource);
		exists_jobInfo.setGlueRemark(glueRemark);
		exists_jobInfo.setGlueUpdatetime(new Date());

		exists_jobInfo.setUpdateTime(new Date());
		xxlJobInfoDao.update(exists_jobInfo);

		// log old code
		XxlJobLogGlue xxlJobLogGlue = new XxlJobLogGlue();
		xxlJobLogGlue.setJobId(exists_jobInfo.getId());
		xxlJobLogGlue.setGlueType(exists_jobInfo.getGlueType());
		xxlJobLogGlue.setGlueSource(glueSource);
		xxlJobLogGlue.setGlueRemark(glueRemark);

		xxlJobLogGlue.setAddTime(new Date());
		xxlJobLogGlue.setUpdateTime(new Date());
		xxlJobLogGlueDao.save(xxlJobLogGlue);

		// remove code backup more than 30
		xxlJobLogGlueDao.removeOld(exists_jobInfo.getId(), 30);

		return ReturnT.SUCCESS;
	}

}


text:
package org.apache.sling.launchpad.webapp.integrationtest.jcrinstall;

import java.util.LinkedList;
import java.util.List;

/** Try installing some cloned bundles */
public class InstallClonedBundlesTest extends JcrinstallTestBase {

	public void testInstallAndRemoveBundles() throws Exception {
		final int activeBeforeTest = getActiveBundlesCount();
		final List<String> installed = new LinkedList<String>();

		final int nBundles = 10 * scaleFactor;
		for(int i=0 ; i < nBundles; i++) {
			installed.add(installClonedBundle(null, null));
		}

		assertActiveBundleCount("after adding bundles",
				activeBeforeTest + nBundles, defaultBundlesTimeout);

		for(String path : installed) {
			removeClonedBundle(path);
		}

		assertActiveBundleCount("after removing added bundles",
				activeBeforeTest, defaultBundlesTimeout);
	}
}


text:
package RiveScript::WD;

use strict;
use warnings;

our $VERSION = '1.36';

# This is not a real module; it's only a current copy of the RiveScript
# Working Draft. See the latest version at
# http://www.rivescript.com/wd/RiveScript.html
1;

=head1 NAME

RiveScript::WD - RiveScript 2.00 Working Draft (2009/07/30)

=head1 DESCRIPTION

This document details the standards for the RiveScript scripting language. The
purpose of this document is that interpreters for RiveScript could be written
in various programming languages that would meet the standards for the
RiveScript language itself.

The most current version of this document is at
http://www.rivescript.com/wd/RiveScript.html

=head1 INTRODUCTION

RiveScript is an interpreted scripting language for giving responses to
chatterbots and other intelligent chatting entities in a simple trigger/reply
format. The scripting language is intended to be simplistic and easy to learn
and manage.

=head1 VOCABULARY

=over 4

=item RiveScript

RiveScript is the name of the scripting language that this document explains.

=item Interpreter

The RiveScript interpreter is a program or library in another programming
language that loads and parses a RiveScript document.

=item RiveScript Document

A RiveScript Document is a text file containing RiveScript code.

=item Bot

A Bot (short for robot) is the artificial entity that is represented by an
instance of a RiveScript Interpreter object. That is, when you create a new
Interpreter object and load a set of RiveScript Documents, that becomes the
"brain" of the bot.

=item Bot Variable

A variable that describes the bot, such as its name, age, or other details
you want to define for the bot.

=item Client Variable

A variable that the bot keeps about a specific client, or user of the bot.
Usually as the client tells the bot information about itself, the bot could
save this information into Client Variables and recite it later.

=back

=head1 FORMAT

A RiveScript document should be parsed line by line, and preferrably arranged
in the interpreter's memory in an efficient way.

The first character on each line should be the C<command>, and the rest of the
line is the command's C<arguments>. The C<command> should be a single character
that is not a number or a letter.

In its most simple form, a valid RiveScript trigger/response pair looks like
this:

  + hello bot
  - Hello, human.

=head1 WHITESPACE

A RiveScript interpreter should ignore leading and trailing whitespace characters
on any line. It should also ignore whitespace characters surrounding individual
arguments of a RiveScript command, where applicable. That is to say, the following
two lines should be interpreted as being exactly the same:

  ! global debug = 1
  !    global    debug=    1

=head1 COMMANDS

=head2 ! DEFINITION

The C<!> command is for defining variables within RiveScript. It's used to
define information about the bot, define global arrays that can be used in
multiple triggers, or override interpreter globals such as debug mode.

The format of the C<!> command is as follows:

  ! type name = value

Where C<type> is one of C<version, global, var, array, sub,> or C<person>.
The C<name> is the name of the variable being defined, and C<value> is the
value of said variable.

Whitespace surrounding the C<=> sign should be stripped out.

Setting a value to C<E<lt>undefE<gt>> will undefine the variable (deleting it
or uninitializing it, depending on the implementation).

The variable types supported are detailed as follows:

=head3 version

It's highly recommended practice that new RiveScript documents explicitly
define the version of RiveScript that they are following. RiveScript 2.00
has some compatibility issues with the old 1.x line (see L<"REVERSE COMPATIBILITY">).
Newer RiveScript versions should encourage that RiveScript documents define their
own version numbers.

  ! version = 2.00

=head3 global

This should override a global variable at the interpreter level. The obvious
variable name might be "debug" (to enable/disable debugging within the
RiveScript interpreter).

The interpreter should take extra care not to allow reserved globals to be
overridden by this command in ways that might break the interpreter.

Examples:

  ! global debug = 1

=head3 var

This should define a "bot variable" for the bot. This should only be used in an
initialization sense; that is, as the interpreter loads the document, it should
define the bot variable as it reads in this line. If you'd want to redefine or
alter the value of a bot variable, you should do so using a tag inside of a
RiveScript document (see L<"TAGS">).

Examples:

  ! var name      = RiveScript Bot
  ! var age       = 0
  ! var gender    = androgynous
  ! var location  = Cyberspace
  ! var generator = RiveScript

=head3 array

This will create an array of strings, which can then be used later in triggers
(see L<"+ TRIGGER">). If the array contains single words, separating the words
with a space character is fine. If the array contains items with multiple words
in them, separate the entries with a pipe symbol (C<"|">).

Examples:

  ! array colors = red green blue cyan magenta yellow black white orange brown
  ! array be     = is are was were
  ! array whatis = what is|what are|what was|what were

Arrays have special treatment when spanned over multiple lines. Each extension
of the array data is treated individually. For example, to break an array of
many single-words into multiple lines of RiveScript code:

  ! array colors = red green blue cyan
  ^ magenta yellow black white
  ^ orange brown

The data structure pulled from that code would be identical to the previous
example above for this array.

Since each extension line is processed individually, you can combine the
space-delimited and pipe-delimited formats. In this case, we can add some color
names to our list that have multiple words in them.

  ! array colors = red green blue cyan magenta yellow
  ^ light red|light green|light blue|light cyan|light magenta|light yellow
  ^ dark red|dark green|dark blue|dark cyan|dark magenta|dark yellow
  ^ white orange teal brown pink
  ^ dark white|dark orange|dark teal|dark brown|dark pink

Finally, if your array consists of almost entirely single-word items, and you
want to add in just one multi-word item, but don't want to require an extra line
of RiveScript code to accomplish this, just use the C<\s> tag where you need
spaces to go.

  ! array blues = azure blue aqua cyan baby\sblue sky\sblue

=head3 sub

The C<sub> variables are for defining substitutions that should be run against
the client's message before any attempts are made to match it to a reply.

The interpreter should do the minimum amount of formatting possible on the
client's message until after it has been passed through all the substitution
patterns.

B<NOTE:> Spaces are allowed in both the variable name and the value fields.

Examples:

  ! sub what's  = what is
  ! sub what're = what are
  ! sub what'd  = what did
  ! sub a/s/l   = age sex location
  ! sub brb     = be right back
  ! sub afk     = away from keyboard
  ! sub l o l   = lol

=head3 person

The C<person> variables work a lot like C<sub>s do, but these are run against
the bot's response, specifically within C<E<lt>personE<gt>> tags (See L<"TAGS">).

Person substitutions should swap first- and second-person pronouns. This is so
that ex. if the client asks the bot a direct question using "you" when addressing
the bot, if the bot uses the client's message in the response it should swap
"you" for "I".

Examples:

  ! person you are = I am
  ! person i am    = you are
  ! person you     = I
  ! person i       = you

=head2 E<gt> LABEL

The C<E<gt>> and C<E<lt>> commands are for defining a subset of your code under
a certain label. The label command takes between one and three arguments. The
first argument defines the type of the label, which is one of C<begin, topic,>
or C<object>. The various types are as follows.

=head3 begin

This is a special label used with the C<BEGIN block>. Every message the
client sends to the bot gets passed through the Begin Statement first, and the
response in there determines whether or not to get an actual reply.

Here's a full example of the Begin Statement.

  > begin

    + request
    - {ok}

  < begin

In the C<BEGIN block>, the trigger named "C<request>" is called by the
interpreter, and it should return the tag "C<{ok}>" to tell the interpreter
that it's OK to get a real reply. This way the bot could have a "maintenance
mode," or could filter the results of your trigger based on a variable.

Here's a maintenance mode example:

  > begin

    + request
    * <id> eq <bot master> => {ok} // Always let the bot master get a reply
    * <env maint> eq true  => Sorry, I'm not available for chat right now!
    - {ok}

  < begin

  // Allow the owner to change the maintenance mode
  + activate maintenance mode
  * <id> eq <bot master> => <env maint=true>Maintenance mode activated.
  - You're not my master! You can't tell me what to do!

  + deactivate maintenance mode
  * <id> eq <bot master> => <env maint=false>Maintenance mode deactivated.
  - Only my master can deactivate maintenance mode!

With this example, if the global variable "maint" is set to "true", the bot
will always reply "Sorry, I'm not available for chat right now!" when a user
sends it a message -- unless the user is the bot's owner.

Here is another example that will modify the response formatting based on a
bot variable called "mood," to simulate humanoid moods for the bot:

  > begin

    + request
    * <get mood> == happy => {ok} :-)
    * <get mood> == sad   => {lowercase}{ok}{/lowercase}
    * <get mood> == angry => {uppercase}{ok}{/uppercase}
    - {ok}

  < begin

In this example the bot will use smiley faces when it's happy, reply in all
lowercase when it's sad, or all uppercase when it's angry. If its mood doesn't
fall into any of those categories, it replies normally.

Here is one last example: say you want your bot to interview its users when
they first talk to it, by asking them for their name:

  > begin

    + request
    * <get name> == undefined => {topic=newuser}{ok}
    - {ok}

  < begin

  > topic newuser
    + *
    - Hello! My name is <bot name>! I'm a robot. What's your name?

    + _
    % * what is your name
    - <set name=<formal>>Nice to meet you, <get name>!{topic=random}
  < topic

Begin blocks are B<optional!> They are not required. You only need to manually
define them if you need to do any "pre-processing" or "post-processing" on the
user's message or the bot's response. Having no begin block is the same as
having a super basic begin block, which always returns C<{ok}>.

=head3 topic

A topic is a smaller set of responses to which the client will be bound until
the topic is changed to something else. The default topic is C<random>.

The C<topic> label only requires one additional argument, which is the name of
the topic. The topic's name should be one word and lowercase.

Example:

  + i hate you
  - Well then, I won't talk to you until you take that back.{topic=apology}

  > topic apology

    + *
    - I won't listen to you until you apologize for being mean to me.
    - I have nothing to say until you say you're sorry.

    + (sorry|i apologize)
    - Okay. I guess I'll forgive you then.{topic=random}

  < topic

Topics are able to C<include> and C<inherit> triggers that belong to a
different topic. When a topic C<includes> another topic, it means that the
triggers in another topic are made available in the topic that did the
inclusion (hereby called the "source topic", which includes triggers from
the "included topic").

When a topic inherits another topic, it means that the entire collection
of triggers of the source topic I<and> any included topics, will have a
higher matching priority than the inherited topics.

See L<"Sorting +Triggers"> to see how triggers are sorted internally. The
following example shows how includes and inheritence works:

  // This is in the default "random" topic and catches all non-matching
  // triggers.
  + *
  - I'm afraid I don't know how to reply to that!

  > topic alpha
    + alpha trigger
    - Alpha's response.
  < topic

  > topic beta
    + beta trigger
    - Beta's response.
  <

  > topic gamma
    + gamma trigger
    - Gamma's response.
  < topic

  > topic delta
    + delta trigger
    - Delta's response.

    + *
    - You can't access any other triggers! Haha!
  < topic

These are all normal topics. Alpha, beta, and gamma all have a single
trigger corresponding to their topic names. If the user were put into
one of these topics, this is the only trigger available. Anything else
would give them a "NO REPLY" error message. They are unable to match the
C<*> trigger at the top, because that trigger belongs to the "C<random>"
topic, and they're not in that topic.

Now let's see how we can pair these topics up with includes and
inheritence.

  > topic ab includes alpha
    + hello bot
    - Hello human!
  < topic

  // Matching order:
  alpha trigger
  hello bot

If the user were put into topic "C<ab>", they could match the trigger
C<hello bot> as well as the trigger C<alpha trigger>, as if they were
both in the same topic.

Note that in the matching order, "alpha trigger" is at the top: this
is because it is the longest trigger. If the user types "alpha trigger",
the interpreter knows that "alpha trigger" does not belong to the topic
"ab", but since "ab" includes triggers from "alpha", the interpreter
searches there and finds the trigger. Then it gives the user the
correct reply of "Alpha's response."

  > topic abc includes alpha beta
    + how are you
    - Good, how are you?
  < topic

  // Matching order:
  how are you
  alpha trigger
  beta trigger

In this case, "how are you" is on the top of the matching list because
it has three words, then "alpha trigger" and "beta trigger" -- "alpha
trigger" is first because it is longer than "beta trigger", even though
they both have 2 words.

Now consider this example:

  > topic abc includes alpha beta
    + how are you
    - Good, how are you?

    + *
    - You matched my star trigger!
  < topic

  // Matching order:
  how are you
  alpha trigger
  beta trigger
  *

Notice what happened here: we had a trigger of simply C<*> in the "abc"
topic - C<*> is the fallback trigger which matches anything that wasn't
matched by a better trigger. But this trigger is at the end of our matching
list! This is because the triggers available in the "alpha" and "beta" topics
are included in the "abc" topic, meaning they all share the same "space"
when the triggers are sorted. Since C<*> has the lowest sort priority,
it ends up at the very end of the collective list.

What if we want C<*>, or any other short trigger, to match in our current
topic before anything in an included topic? We need to C<inherit> another
topic. Consider this:

  > topic abc inherits alpha beta
    + how are you
    - Good, how are you?

    + *
    - You matched my star trigger!
  < topic

  // Matching order:
  how are you
  *
  alpha trigger
  beta trigger

Now the C<*> trigger is the second on the matching list. Because "abc"
I<inherits> alpha and beta, it means that the collection of triggers
inside "abc" are sorted independently, and I<then> the triggers of alpha
and beta are sorted. So this way every trigger in "abc" inherits, or
I<overrides>, all triggers in the inherited topics.

Of course, using a C<*> trigger in a topic that inherits other topics is
useless, because you could just leave the topic as it is. However it might
be helpful in the case that a trigger in your topic is very short or has
very few words, and you want to make sure that this trigger will have a
good chance of matching before anything that appears in a different topic.

You can combine inherited and included topics together, too.

  > topic abc includes alpha beta delta inherits gamma
    + how are you
    - Good, how are you?
  < topic

  // Matching order:
  how are you
  alpha trigger
  delta trigger
  beta trigger
  *
  gamma trigger

In this example, the combined triggers from abc, alpha, beta, and delta
are all merged together in one pool and sorted amongst themselves, and
then triggers from gamma are placed after them in the sort list.

This effectively means you can combine the triggers from multiple
topics together, and have ALL of those triggers override triggers
from an inherited topic.

You can use as many "includes" and "inherits" keywords as you want, but
the order you specify them has no effect. So the following two formats
are identical:

  > topic alpha includes beta inherits gamma
  > topic alpha inherits gamma includes beta

In both cases, alpha and beta's triggers are pooled and have higher
priority than gamma's. If gamma wants to include beta and have alpha's
triggers be higher priority than gamma's and beta's, gamma will need
to include beta first.

  > topic gamma includes beta
  > topic alpha inherits gamma

In this case the triggers in "alpha" are higher priority than the
combined triggers in gamma and beta.

=head3 object

Objects are bits of program code that the interpreter should try to process.
The programming language that the interpreter was written in will determine
whether or not it will attempt to process the object.

See L<"OBJECT MACROS"> for more information on objects.

The C<object> label should have two arguments: a lowercase single-word name for
the object, and the programming language that the object should be interpreted
by, which should also be lowercase.

Example:

  > object encode perl
    my ($obj,$method,@args) = @_;
    my $msg = join(" ",@args);

    use Digest::MD5 qw(md5_hex);
    use MIME::Base64 qw(encode_base64);

    if ($method eq 'md5') {
      return md5_hex($msg);
    }
    else {
      return encode_base64($msg);
    }
  < object

=head2 + TRIGGER

The C<+> command is the basis for all things that actually do stuff within a
RiveScript document. The trigger command is what matches the user's message to
a response.

The trigger's text should be entirely lowercase and not contain any symbols
(except those used for matching complicated messages). That is, a trigger that
wants to match "C<what's your name>" shouldn't be used; you should use a
L<"sub">stitution to convert C<what's> into C<what is> ahead of time.

Example:

  + are you a bot
  - How did you know I'm a robot?

=head3 Atomic Trigger

An atomic trigger is a trigger that matches nothing but plain text. It doesn't
contain any wildcards (C<*>) or optionals, but it may contain alternations.
Atomic triggers should take higher priority for matching a client's message
than should triggers containing wildcards and optionals.

Examples:

  + hello bot
  + what is your name
  + what is your (home|office) phone number
  + who is george w bush

=head3 Trigger Wildcards

Using an asterisk (C<*>) in the trigger will make it act as a wildcard. Anything
the user says in place of the wildcard may still match the trigger. For example:

  + my name is *
  - Pleased to meet you, <star>.

An asterisk (C<*>) will match any character (numbers and letters). If you want
to only match numbers, use C<#>, and to match only letters use C<_>. Example:

  // This will ONLY take a number as the wildcard.
  + i am # years old
  - I will remember that you are <star> years old.

  // This will ONLY take letters but not numbers.
  + my name is _
  - Nice to meet you, <star>.

The values matched by the wildcards can be retrieved in the responses by using
the tags C<E<lt>star1E<gt>>, C<E<lt>star2E<gt>>, C<E<lt>star3E<gt>>, etc. in the
order that the wildcard appeared. C<E<lt>starE<gt>> is an alias for C<E<lt>star1E<gt>>.

=head3 Trigger Alternations

An alternation in a trigger is a sub-set of strings, in which any one of the
strings will still match the trigger. For example, the following trigger should
match both "are you okay" and "are you alright":

  + are you (okay|alright)

Alternations can contain spaces in them, too.

  + (are you|you) (okay|alright)

That would match all of the following questions from the client:

  are you okay
  are you alright
  you okay
  you alright

Alternations match the same as wildcards do; they can be retrieved via the
C<E<lt>starE<gt>> tags.

=head3 Trigger Optionals

Triggers can contain optional words as well. Optionals are written similarly to
alternations, but they use square braces. The following example would match both
"what is your phone number" as well as "what is your B<home> phone number"

  + what is your [home] phone number

Optionals do B<NOT> match like wildcards do. They do NOT go into the
C<E<lt>starE<gt>> tags. The reason for this is that optionals are optional, and
won't always match anything if the client didn't actually say the optional word(s).

=head3 Arrays in Triggers

Arrays defined via the L<"! DEFINITION"> L<"array"> commands can be used within
a trigger. This is the only place where arrays are used, and they're added as a
convenience feature.

For example, you can make an array of color names, and then use that array in
multiple triggers, without having to copy a whole bunch of alternation code between
triggers.

  ! array colors = red green blue cyan magenta yellow black white orange brown

  + i am wearing a (@colors) shirt
  - I don't know if I have a shirt that's colored <star>.

  + my favorite color is (@colors)
  - I like <star> too.

  + i have a @colors colored *
  - Have you thought about getting a <star> in a different color?

When an array is called within parenthesis, it should be matched into a
C<E<lt>starE<gt>> tag. When the parenthesis are absent, however, it should not
be matched into a C<E<lt>starE<gt>> tag.

=head3 Priority Triggers

A new feature proposed for RiveScript 2.00 is to add a priority tag to triggers.
When the interpreter sorts all the loaded triggers into a search sequence, any
triggers that have a priority defined will be sorted with higher priority
triggers first.

The idea is to have "important" triggers that should always be matched before a
different trigger, which may have been a better match, can be tried. The best
example would be for commands. For example:

  + google *
  - Searching Google... <call>google <star></call>

  + * or not
  - Or yes. <@>

In that example, if the bot had a Google search function and the user wanted to
search for whether or not Perl is a superior programming language to PHP, the
user might ask "C<google is perl better than php or not>". However, without
priorities in effect, that question would actually match the "C<* or not>"
trigger, because that trigger has more words than "C<google *>" does.

Adding a priority to the "C<google *>" trigger would ensure that conflicts like
this don't happen, by always sorting the Google search trigger with higher
priority than the other.

  + {weight=100}google *
  - Searching Google... <call>google <star></call>

B<NOTE:> It would NOT be recommended to put a priority tag on every one of your
triggers. To the interpreter this might mean extra processing work to sort
prioritized triggers by each number group. Only add priorities to triggers that
need them.

=head2 - RESPONSE

The C<-> tag is used to indicate a response to a matched trigger. A single
response to a single trigger is called an "atomic response." When more than one
response is given to a single trigger, the collection of responses become a
"random response," where a response is chosen randomly from the list. Random
responses can also use a C<{weight}> tag to improve the likelihood of one response
being randomly chosen over another.

=head3 Atomic Response

A single response to a single trigger makes an Atomic Response. The bot will
respond pretty much the same way each time the trigger is matched.

Examples:

  + hello bot
  - Hello human.

  + my name is *
  - Nice to meet you, <star>.

  + i have a (@colors) shirt
  - You're not the only one that has a <star> shirt.

=head3 Random Response

Multiple responses to a single trigger will be chosen randomly.

  + hello
  - Hey there!
  - Hello!
  - Hi, how are you?

  + my name is *
  - Nice to meet you, <star>.
  - Hi, <star>, my name is <bot name>.
  - <star>, nice to meet you.

=head3 Weighted Random Response

When using random responses, it's possible to give weight to them to change the
likelihood that a response will be chosen. In this example, the response of
"Hello there" will be much more likely to be chosen than would the response of
"Hi".

  + hello
  - Hello there!{weight=50}
  - Hi.

When the C<{weight}> tag isn't used, a default weight of 1 is implied for that
response. The C<{weight}> should always be a number greater than zero and must
be an integer (no decimal point).

=head2 % PREVIOUS

The C<%> command is for drawing the user back to finish a short discussion. Its
behavior is similar to using topics, but is implied automatically and used for
short-term things. It's also less strict than topics are; if the client replies
in a way that doesn't match, a normal reply is given anyway. For example:

  + knock knock
  - Who's there?

  + *
  % who is there
  - <star> who?

  + *
  % * who
  - lol! <star>! That's hilarious!

The text of the C<%> command looks similar to the text next to the trigger. In
essence, they work the same; the only difference is that the C<%> command matches
the last thing that the I<bot> sent to you.

Here's another example:

  + i have a dog
  - What color is it?

  + (@colors)
  % what color is it
  - That's an odd color for a dog.

In that case, if the client says "I have a dog," the bot will reply asking what
color it is. Now, if I tell it the color in my next message, it will reply back
and tell me what an odd color that is. However, if I change the topic instead and
say something else to the bot, it will answer my new question anyway. This is in
contrast to using topics, where I'd be stuck inside of the topic until the bot
resets the topic to C<random>.

Similarly to the wildcards in C<+ Trigger>, the wildcards matched in the
C<% Previous> command are put into C<E<lt>botstarE<gt>>. See L<"TAGS"> for
more information.

=head2 ^ CONTINUE

The C<^> command is used to continue the text of a lengthy previous command down
to the new line. It can be used to extend any other command. Example:

  + tell me a poem
  - Little Miss Muffit sat on her tuffet\n
  ^ in a nonchalant sort of way.\n
  ^ With her forcefield around her,\n
  ^ the Spider, the bounder,\n
  ^ Is not in the picture today.

Note that when the C<^> command continues the previous command, no spaces or
line breaks are implied at the joining of the two lines. The C<\s> and C<\n>
tags must be explicitly defined where needed.

=head2 @ REDIRECT

The C<@> command is used to redirect an entire response to appear as though the
client asked an entirely different question. For example:

  + my name is *
  - Nice to meet you, <star>.

  + call me *
  @ my name is <star>

If the client says "call me John", the bot will redirect it as though the client
actually said "my name is John" and give the response of "Nice to meet you,
John."

=head2 * CONDITION

The C<*> command is used with conditionals when replying to a trigger. Put simply,
they compare two values, and when the comparison is true the associated response
is given. The syntax is as follows:

  * value symbol value => response

The following inequality symbols may be used:

  ==  equal to
  eq  equal to (alias)
  !=  not equal to
  ne  not equal to (alias)
  <>  not equal to (alias)
  <   less than
  <=  less than or equal to
  >   greater than
  >=  greater than or equal to

In each of the value places, tags can be used to i.e. insert client or bot
variables.

Examples:

  + am i a boy or a girl
  * <get gender> eq male   => You told me you were a boy.
  * <get gender> eq female => You told me you were a girl.
  - You never told me what you were.

  + am i your master
  * <id> eq <bot master> => Yes, you are.
  - No, you're not my master.

  + my name is *
  * <get name> eq <star>    => I know, you told me that already.
  * <get name> ne undefined => Did you get a name change?<set name=<star>>
  - <set name=<star>>Nice to meet you, <star>.

It's recommended practice to always include at least one response in case all
of the conditionals return false.

B<NOTE:> Conditionals are tried in the order they appear in the RiveScript
document, and the next condition is tried when the previous ones are false.

=head2 // COMMENT

The C<//> command is for putting comments into your RiveScript document. The
C-style multiline comment syntax C</* */> is also supported.

Comments on their own line should be ignored by all interpreters. For inline
comments, only the C<//> format is acceptable. If you want a literal C<//> in
your RiveScript data, escape at least one of the symbols, i.e. C<\//> or C<\/\/>
or C</\/>.

Examples:

  // A single regular comment

  /*
    This comment can span
    multiple lines
  */

  > begin // The "BEGIN" block
    + request // This is required
    - {ok}    // An {ok} means to get a real reply
  < begin//End the begin block

=head1 OBJECT MACROS

An C<object macro> is a piece of program code that is processed by the interpreter
to give a little more "kick" to the RiveScript. All objects are required to define
the programming language they use. Ones that don't should result in vociferous
warnings by the interpreter.

Objects should be able to be declared inline within RiveScript code, however they
may also be defined by the program utilizing the interpreter as well. All objects
should receive, at a minimum, some kind of reference to the RiveScript interpreter
object that called them.

Here is an example of a simple Perl object that encodes a bit of text into
MD5 or Base64.

  > object encode perl
    my ($obj,$method,@args) = @_;
    my $msg = join(" ",@args);

    use Digest::MD5 qw(md5_hex);
    use MIME::Base64 qw(encode_base64);

    if ($method eq 'md5') {
      return md5_hex($msg);
    }
    else {
      return encode_base64($msg);
    }
  < object

To call an object within a response, call it in the format of:

  <call>object_name arguments</call>

For example:

  + encode * in md5
  - The MD5 hash of "<star>" is: <call>encode md5 <star></call>

  + encode * in base64
  - The Base64 hash of "<star>" is: <call>encode base64 <star></call>

In the above examples, C<encode> calls on the object named "encode", which we
defined above; C<md5> and C<base64> calls on the method name, which is received
by the object as C<$method>. Finally, C<@args> as received by the object would
be the value of E<lt>starE<gt> in this example.

C<$obj> in this example would be a reference to the RiveScript interpreter.

=head1 TAGS

Tags are bits of text inserted within the argument space of a RiveScript command.
As a general rule of thumb, tags with E<lt>angle bracketsE<gt> are for setting
and getting a variable or for inserting text. Tags with {curly brackets} modify
the text around them, such as to change the formatting of enclosed text.

No tags can be used within C<! Definition> and C<E<gt> Label> under any
circumstances.

Unless otherwise specified, all of the tags can be used within every RiveScript
command.

=head2 E<lt>starE<gt>, E<lt>star1E<gt> - E<lt>starNE<gt>

The C<E<lt>starE<gt>> tags are used for matching responses. See
L<"+ TRIGGER"> for usage examples.

The C<E<lt>starE<gt>> tags can NOT be used within C<+ Trigger>.

=head2 E<lt>botstarE<gt>, E<lt>botstar1E<gt> - E<lt>botstarNE<gt>

If the trigger included a C<% Previous> command, C<E<lt>botstarE<gt>> will match
any wildcards that matched the bot's previous response.

  + ask me a question
  - What color's your {random}shirt shoes socks{/random}

  + *
  % what colors your *
  - I wouldn't like <star> as a color for my <botstar>.

=head2 E<lt>input1E<gt> - E<lt>input9E<gt>; E<lt>reply1E<gt> - E<lt>reply9E<gt>.

The input and reply tags insert the previous 1 to 9 things the client said, and
the last 1 to 9 things the bot said, respectively. When these tags are used with
C<+ Trigger>, they should be formatted against substitutions first. This way, the
bot might be able to detect when the client is repeating themself or when they're
repeating the bot's replies.

  + <reply1>
  - Don't repeat what I say.

  + <input1>
  * <input1> eq <input2> => That's the second time you've repeated yourself.
  * <input1> eq <input3> => If you repeat yourself again I'll stop talking to you.
  * <input1> eq <input4> => That's it. I'm done talking to you.{topic=blocked}
  - Please don't repeat yourself.

C<E<lt>inputE<gt>> and C<E<lt>replyE<gt>> are aliases for C<E<lt>input1E<gt>> and
C<E<lt>reply1E<gt>>, respectively.

=head2 E<lt>idE<gt>

The C<E<lt>idE<gt>> tag inserts the client's ID, as told to the RiveScript
interpreter when the client's ID and message were passed in.

=head2 E<lt>botE<gt>

Insert a bot variable, which was previously defined via the C<! Definition>
L<"var"> commands.

  + what is your name
  - I am <bot name>, a chatterbot created by <bot company>.

  + my name is <bot name>
  - <set name=<bot name>>What a coincidence, that's my name too!

The C<E<lt>botE<gt>> tag allows assignment as well (which deprecates the old
C<{!...}> tag.

  + set mood to (happy|angry|sad)
  * <get master> == true => <bot mood=<star>>Updated my mood.
  - Only my botmaster can do that.

=head2 E<lt>envE<gt>

Insert a global variable, which was previously defined via C<! Definition>
L<"global"> commands.

  + is debug mode enabled
  * <env debug> == 1 => Yes, debug mode is active.
  - No, debug mode is set to "<env debug>"

The C<E<lt>envE<gt>> tag allows assignment as well (which deprecates the old
C<{!...}> tag.

  + turn debug mode on
  * <get master> == true => <env debug=1>Debug mode enabled.
  - You can't turn debug mode on.

=head2 E<lt>getE<gt>, E<lt>setE<gt>

Get and set a client variable. These variables are local to the user ID that is
chatting with the bot.

  + my name is *
  - <set name=<star>>Nice to meet you, <star>.

E<lt>getE<gt> can be used within C<+ Trigger>, but E<lt>setE<gt> can not.

=head2 E<lt>addE<gt>, E<lt>subE<gt>, E<lt>multE<gt>, E<lt>divE<gt>

Add, subtract, multiply, and divide a numeric client variable, respectively.

  + give me 5 points
  - <add points=5>I've added 5 points to your account.

These tags can not be used within C<+ Trigger>.

=head2 {topic=...}

Change the client's topic. This tag can only be used with C<* Condition> and
C<- Response>.

=head2 {weight=...}

When used with C<- Response>, this will weigh the response more heavily to be
chosen when random responses are available. When used with C<+ Trigger>, this
sets that trigger to have a higher matching priority.

=head2 {@...}, E<lt>@E<gt>

Perform an inline redirection. This should work like a regular redirection but
is embedded within another response. This tag can only be used with
C<- Response>, and in the response part of a C<* Condition>.

E<lt>@E<gt> is an alias for {@E<lt>starE<gt>}

  + your *
  - I think you meant to say "you are" or "you're", not "your". {@you are <star>}

=head2 {!...}

Perform an inline definition. This can be used just like the normal
C<! Definition> command from within a reply. This tag can only be used
with C<- Response>.

B<This tag is deprecated>. This tag's purpose was to redefine a global or bot
variable on the fly. Instead, the env and bot tags allow assignment.

  + set bot mood to *
  - <bot mood=<star>>Bot mood set to <star>.

=head2 {random}...{/random}

Insert a sub-set of random text. This tag can NOT be used with C<+ Trigger>. Use
the same array syntax as when defining arrays (separate single-word groups with
spaces and multi-word groups with pipes).

  + say something random
  - This {random}sentence statement{/random} has a random {random}set of words|gang of vocabulary{/random}.

=head2 {person}...{/person}, E<lt>personE<gt>

Process L<"person"> substitutions on a group of text.

  + say *
  - Umm... "<person>"

In that example, if the client says "say you are a robot", the bot should reply,
"Umm... "I am a robot.""

E<lt>personE<gt> is an alias for {person}E<lt>starE<gt>{/person}.

=head2 {formal}...{/formal}, E<lt>formalE<gt>

Formalize A String Of Text (Capitalize Every First Letter Of Every Word).

  + my name is *
  - Nice to meet you, <formal>.

E<lt>formalE<gt> is an alias for {formal}E<lt>starE<gt>{/formal}.

=head2 {sentence}...{/sentence}, E<lt>sentenceE<gt>

Format a string of text in sentence-case (capitilizing only the first letter
of the first word of each sentence).

E<lt>sentenceE<gt> is an alias for {sentence}E<lt>starE<gt>{/sentence}.

=head2 {uppercase}...{/uppercase}, E<lt>uppercaseE<gt>

FORMAT A STRING OF TEXT INTO UPPERCASE.

E<lt>uppercaseE<gt> is an alias for {uppercase}E<lt>starE<gt>{/uppercase}.

=head2 {lowercase}...{/lowercase}, E<lt>lowercaseE<gt>

format a string of text into lowercase.

E<lt>lowercaseE<gt> is an alias for {lowercase}E<lt>starE<gt>{/lowercase}.

=head2 {ok}

This is used only with the "request" trigger within the BEGIN block. It tells
the interpreter that it's okay to go and get a real response to the client's
message.

=head2 \s

Inserts a white space character. This is useful with the C<^ Continue>
command.

=head2 \n

Inserts a line break character.

=head2 \/

Inserts a forward slash.

=head2 \#

Inserts a pound symbol.

=head1 INTERPRETER IMPLEMENTATION

Interpreters of RiveScript should follow these guidelines when interpreting
RiveScript code. This details some of the priorities for processing tags and
sorting internal data structures. This part of the document should be
programming-language-independent.

=head2 STANDARD GLOBAL VARIABLES

The interpreter must support the following standard global variables:

  depth = a recursion limit before an attempt to fetch a reply will be abandoned.

It's recommended to also have a C<debug> variable for consistency, but it may
not be applicable.

The C<depth> variable is strongly encouraged, though. It's to set a user-defineable
recursion limit when fetching a response. For example, a pair of triggers like
this will cause infinite recursion:

  + one
  @ two

  + two
  @ one

The interpreter should protect itself against such possibilities and provide a
C<depth> variable to allow the user to adjust the recursion limit.

  ! global depth = 25

=head2 PARSING GUIDELINES

Interpreters should parse all of the RiveScript documents ahead of time and
store them in an efficient way in which replies can be looked up quickly.

=head3 Sorting +Triggers

Triggers should be sorted in a "most specific first" order. That is:

  1. Atomic triggers first. Sort them so that the triggers with the most amount
     of words are on top. For multiple triggers with the same amount of words,
     sort them by length, and then alphabetically if there are still matches
     in length.
  2. Sort triggers that contain optionals in their triggers next. Sort them in
     the same manner as the atomic triggers.
  3. Sort triggers containing wildcards next. Sort them by the number of words
     that aren't wildcards. The order of wildcard sorting should be as follows:

     A. Alphabetic wildcards (_)
     B. Numeric wildcards (#)
     C. Global wildcards (*)

  4. The very bottom of the list will be a trigger that simply matches * by
     itself, if it exists. If triggers of only _ or only # exist, sort them in
     the same order as in step 3.

=head3 Sorting %Previous

C<% Previous> triggers should be sorted in the same manner as C<+ Triggers>, and
associated with the reply group that they belong to (creating pseudotopics for
each C<% Previous> is a good way to go).

=head3 Syntax Checking

It will be helpful if the interpreter also offers syntax checking and will give
verbose warnings when it tries to parse something that doesn't follow standards.
When possible, it should try to correct the error, but should still emit a
warning so that the author might fix it.

It would also be good practice to keep track of file names and line numbers of
each parsed command, so that syntax warnings can direct the author to the exact
location where the problem occurred.

=head2 REPLY FETCHING

When attempting to get a response to a client's message, the interpreter should
support the sending of a "sender ID" along with the message. This would preferably
be a screen name or handle of the client who is sending the message, and the
interpreter should be able to keep different groups of user variables for each
user ID. The E<lt>idE<gt> tag should substitute for the user's ID.

If the BEGIN block was defined in any of the loaded RiveScript documents, it should
be tried for the "request" trigger. That is, this trigger should be matched:

  > begin
    + request
    - {ok}
  < begin

The interpreter should make the request for that trigger in the context of the
calling user, and allow it to change the user's topic or set a user variable
immediately. Do not process any other tags that are present in the response (see
L<"TAG PRIORITY">).

If the response contains the C<{ok}> tag, then make a second request to try to
match the client's actual message. When a response was found, substitute the
C<{ok}> tag from the BEGIN response with the text of the actual response the
client wanted, and then process any remaining tags in the BEGIN response.
Finally, return the reply to the client.

When fetching responses, the following order of events should happen.

  1. Build in a system of recursion prevention. Since replies can redirect to
     other replies, there's the possibility of deep recursion. The first thing
     that the reply fetching routine should do is prevent this from getting out
     of control.
  2. Dig through the triggers under the client's current topic. Check to see if
     there are any %Previous commands on any of these topics and see if they
     match the bot's last message to the client. If so, make sure the client's
     current message matches the trigger in question. If so, we have a response
     set; skip to step 4.
  3. Find a trigger that matches the client's message. If one is found, we have
     a response set; continue to step 4.

  4. If we found a reply set, process the reply. First check if this reply set
     has a "solid redirection" (an @ command). If so, recurse the response
     routine with the redirection trigger and resume from step 1. Break when an
     eventual response was returned.
  5. Process conditionals if they exist in order. As soon as one of them returns
     true, we have a response and break. If none are true, continue to step 6.
  6. See if there is more than one response to this trigger. If any of the random
     responses has a {weight}, take that into account as a random response is
     chosen. If we have a reply now, break.
  7. If there is still no reply, insert a generic "no reply" error message.

When a reply was obtained, then tags should be executed on them in the order
defined under L<"TAG PRIORITY">.

=head2 TAG PRIORITY

=head3 Within BEGIN/Request

Within the "request" response of the BEGIN block, the following tags can be
executed prior to getting a real response for the client's message:

  {topic}
  <set>

All other tags, especially modifier tags, must be held off until the final
response has been given. Substitute C<{ok}> for the final response, and then
process the other tags.

Things like this should be able to work:

  > begin

    + request
    * <get name> eq undefined => {topic=new_user}{ok}
    * <bot mood> eq happy     => {ok}
    * <bot mood> eq angry     => {uppercase}{ok}{/uppercase}
    * <bot mood> eq sad       => {lowercase}{ok}{/lowercase}
    - {ok}

  < begin

=head3 Within +Trigger

All tags that appear within the context of C<+ Trigger> must be processed prior
to any attempts to match on the trigger.

=head3 Within Replies

The order that the tags should be processed within a response or anywhere else
that a tag is allowed is as follows:

  <star>      # Static text macros
  <input>     #
  <reply>     #
  <id>        #
  \s          #
  \n          #
  \\          #
  \#          #
  {random}    # Random text insertion (which may contain other tags)
  <bot>       # Insert bot variables
  <env>       # Insert environment variables
  <person>    # String modifiers
  <formal>    #
  <sentence>  #
  <uppercase> #
  <lowercase> #
  <set>       # User variable modifiers
  <add>       #
  <sub>       #
  <mult>      #
  <div>       #
  <get>       # Get user variables
  {topic}     # Set user topic
  <@>         # Inline redirection
  <call>      # Object macros.

=head1 REVERSE COMPATIBILITY

RiveScript 2.00 will have limited backwards compatibility with RiveScript 1.x
documents. Here is a full breakdown of the differences:

  RiveScript Changes from 1.02 to 2.00
  ------------------------------------

  REMOVED:

  - Variants of !DEFINITION
    - ! addpath
    - ! include
    - ! syslib
  - RiveScript Libraries (RSL files)
  - RiveScript Packages  (RSP files)
    - These made code management messy. Keep your own
      brain's files together!

  COMPATIBLE CHANGES:

  - Object macros now require the programming language to be defined.
    - Old way: > object encode
    - New way: > object encode perl
  - The ^CONTINUE command can extend every command.
  - Most tags can be used with almost every command.
  - Topics can inherit triggers from other topics now.

  INCOMPATIBLE CHANGES:

  - Conditionals work differently now. Instead of comparing variables to values,
    they compare values to values, and each value can <get> variables to compare.
    - Old way: * name       =  Bob => Hello Bob!
    - New way: * <get name> eq Bob => Hello Bob!
  - Conditionals no longer use a single = for "equal to" comparison. Replace it
    with either == or "eq".
  - Object macros will receive a reference to the RiveScript object as their first
    argument.
  - Objects are called in a new <call> syntax instead of the old &object one.

  NEW THINGS:

  - {weight} is a valid tag in triggers now to increase matching priority.
  - <env> has been added for calling global variables.
  - <botstar> has been added for wildcard matching on %previous.
  - Conditionals have more inequality comparisons now:
    "==" and "eq"        : equal to
    "!=", "ne", and "<>" : not equal to

Nice interpreters might be able to fix some old RiveScript code to make them work.
For example, if a condition is found that has one equals sign instead of two, it
could print a warning that it's detected RiveScript 1.x code in action and
automatically adjust it to 2.x standards, and perhaps reparse the entire file or
group of files, assuming that they are RiveScript 1.x code and fix these
inconsistencies altogether.

Or perhaps there will just be a converter tool created that would go through code
that it already assumes will be RiveScript 1.x and update it to 2.x standards.

=head1 REVISIONS

  Rev 11 - Jun 13, 2013
  - Clarify the ability for the <bot> and <env> tags to be used for assignment.

  Rev 10 - May 15, 2012
  - Deprecated the {!...} tag. It was intended for reassigning global or bot
    variables. Instead use <env name=value>, <bot name=value>.

  Rev 9 - Jul 31, 2009
  - Added more explicit details on the usage of the BEGIN block, under the
    section on >Labels / "begin"
  - Revised the WD, fixing some typos.

  Rev 8 - Jul 30, 2009
  - The proper format for the `! version` line is to be `! version = 2.00`,
    and not `! version 2.00`
  - Included the "includes" option for triggers and changed how "inherits"
    works.

  Rev 7 - Dec  4, 2008
  - Topics are able to inherit additional triggers that belong to different
    topics, in the "> topic alpha inherits beta" syntax.
  - Added more documentation to the "! array" section of the document. Also
    check that section for some changes to the way arrays should be processed by
    the interpreter.
  - Deprecated the # command for inline comments. Use only // and /* */.

  Rev 6 - Sep 15, 2008
  - Updated the section about # for inline comments: when used next to a
    +Trigger, there should be at least 2 spaces before the # symbol and 1 space
    after, to avoid confusion with # as a wildcard character.

  Rev 5 - Jul 22, 2008
  - Added two new variants of the wildcard: # will match only numbers and _ will
    match only letters. * will still match anything at all.

  Rev 4 - Jun 19, 2008
  - Rearranged tag priorities:
    - <bot> and <env> moved higher up.

  Rev 3 - Apr  2, 2008
  - Typo fix: under the !person section, the examples were using !sub
  - Inconsistency fix: under %Previous it was saying the wildcards were
    unmatchable, but this isn't the case (they go into <botstar>).
  - Typo fix: under OBJECT MACROS, fixed the explanation of the code to match
    the new object syntax.
  - Inconsistency fix: <@> can be used in the response portion of conditionals.
  - Rearranged the tag priorities:
    - String modifiers (person - lowercase) come in higher priority than
      {random}
    - <env> comes in after <bot>
  - Typo fix: updated the object syntax (<call>) in the priority list.

  Rev 2 - Feb 18, 2008
  - Moved {random} to higher tag priority.
  - Change the &object syntax to <call>
  - Added the <env> variable.
  - Added the <botstar> variable.

  Rev 1 - Jan 15, 2008
  - Added the {priority} tag to triggers, to increase a trigger's matching
    priority over others, even when another trigger might be a better match
    to the client's message.

=head1 DISCLAIMER

Note that this document is only a working draft of the RiveScript 2.00
specification and may undergo numerous changes before a final standard is
agreed on. Changes to this document after the creation date on January 14, 2008
will be noted in a change log.

http://www.rivescript.com/

=cut


text:
import _Object$defineProperty from "../../core-js/object/define-property";
import _Object$getOwnPropertyDescriptor from "../../core-js/object/get-own-property-descriptor";
import _Object$getOwnPropertyNames from "../../core-js/object/get-own-property-names";
export default function _defaults(obj, defaults) {
  var keys = _Object$getOwnPropertyNames(defaults);

  for (var i = 0; i < keys.length; i++) {
    var key = keys[i];

    var value = _Object$getOwnPropertyDescriptor(defaults, key);

    if (value && value.configurable && obj[key] === undefined) {
      _Object$defineProperty(obj, key, value);
    }
  }

  return obj;
}


text:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Ultimate TIC TAC TOE</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="Player1">Player 1</string>
    <string name="Player2">Player 2</string>
    <string name="title_activity_tutorial">Game Tutorial</string>
    <string name="tutorial">Tutorial Heading</string>
    <string name="title_activity_display_message">DisplayMessageActivity</string>
    <string name="heading">Ultimate<br /> TIC TAC TOE</string>
    <string name="goback">Rematch</string>
    <string name="newgame">New Game</string>
    <string name="tut">Tutorial</string>
    <string name="settings">Settings</string>
    <string name="exit">Exit Game</string>
    <string name="toggle_sound">Sound On</string>

</resources>


text:
<?php

namespace Anytv\DashboardBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Anytv\DashboardBundle\Entity\SignupAnswer;

class UpdateSignupAnswersCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('anytv:update_signup_answers')
            ->setDescription('Updating SignupAnswers from Hasoffers to database.')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $text = 'Updating SignupAnswers from Hasoffers to database.';
        $container = $this->getContainer();
        $doctrine = $container->get('doctrine');
        $repository = $doctrine->getRepository('AnytvDashboardBundle:SignupAnswer');
        $affiliate_repository = $doctrine->getRepository('AnytvDashboardBundle:Affiliate');
        $question_repository = $doctrine->getRepository('AnytvDashboardBundle:SignupQuestion');
        $manager = $doctrine->getManager();

        $hasoffers = $container->get('hasoffers');

        $new_signup_answers = 0;
        $answers_request_batch = 50;

        $signup_answers_wo_answers = $affiliate_repository->findBy(array('status'=>'active', 'signupAnswersRequested'=>false), null, $answers_request_batch);

        if($signup_answers_wo_answers)
        {
          foreach($signup_answers_wo_answers as $affiliate)
          {
            $signup_answers_response = $hasoffers->getSignupAnswers($affiliate->getAffiliateId());

            if(($signup_answers_response->status == 1) && $signup_answers_response->data)
            {
              $signup_answers_data = (array) $signup_answers_response->data;

              if($signup_answers_data)
              {
                foreach($signup_answers_data as $signup_answer_data)
                {
                  $signup_answer_object = $signup_answer_data->SignupAnswer;

                  $signup_answer = new SignupAnswer();
                  $signup_answer->setAnswerId($signup_answer_object->id);
                  $signup_answer->setAnswer($signup_answer_object->answer);

                  if($question = $question_repository->findOneByQuestionId($signup_answer_object->question_id))
                  {
                    $signup_answer->setQuestion($question);
                  }

                  if($affiliate = $affiliate_repository->findOneByAffiliateId($signup_answer_object->responder_id))
                  {
                    $signup_answer->setAffiliate($affiliate);
                  }

                  $manager->persist($signup_answer);

                  $new_signup_answers++;
                }
              }
            }

            $affiliate->setSignupAnswersRequested(true);
          }

          $manager->flush();

        }

        $output->writeln($text);
        $output->writeln($new_signup_answers.' new SignupAnswers added.');
    }
}


text:
import random
import input_data
mnist = input_data.read_data_sets(raw_input(), raw_input(), raw_input())

import tensorflow as tf

x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
y_ = tf.placeholder(tf.float32, [None, 10])

cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

init = tf.initialize_all_variables()

with tf.Session() as sess:
  sess.run(init)
  # Added more learning iterations for an accuracy 92.9% max
  for i in range(5000):
    batch_xs, batch_ys = mnist.train.next_batch(100)
    sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})

  result = sess.run(tf.argmax(y,1), feed_dict={x: mnist.test.images})
  print ' '.join(map(str, result))


text:
require 'stringio'
require "base64"

module ResponsivePDF
  module Util
    class BMP
      class Writer
        PIXEL_ARRAY_OFFSET = 54
        BITS_PER_PIXEL     = 24
        DIB_HEADER_SIZE    = 40
        PIXELS_PER_METER   = 2835 # 2835 pixels per meter is basically 72dpi

        def initialize(width, height)
          @width, @height = width, height

          @pixels = Array.new(@height) { Array.new(@width) { "000000" } }
        end

        def []=(x,y,value)
          @pixels[y][x] = value
        end

        def save_as(filename)
          File.open(filename, "wb") do |file|
            write_bmp_file_header(file)
            write_dib_header(file)
            write_pixel_array(file)
          end
        end

        def to_binary
          strio = StringIO.new("", "wb")

          write_bmp_file_header(strio)
          write_dib_header(strio)
          write_pixel_array(strio)

          strio.string
        end

        def to_embed_img_tag(style="")
          ""
        end

        #private

        def file_size
          PIXEL_ARRAY_OFFSET + pixel_array_size
        end

        def pixel_array_size
          ((BITS_PER_PIXEL*@width)/32.0).ceil*4*@height
        end
        def write_bmp_file_header(file)
          file << ["BM", file_size, 0, 0, PIXEL_ARRAY_OFFSET].pack("A2Vv2V")
        end

        def write_dib_header(file)
          file << [DIB_HEADER_SIZE, @width, @height, 1, BITS_PER_PIXEL,
                   0, pixel_array_size, PIXELS_PER_METER, PIXELS_PER_METER,
                   0, 0].pack("V3v2V6")
        end

        def write_pixel_array(file)
          @pixels.reverse_each do |row|
            row.each do |color|
              file << pixel_binstring(color)
            end

            file << row_padding
          end
        end

        def pixel_binstring(rgb_string)
          raise ArgumentError unless rgb_string =~ /\A\h{6}\z/
          [rgb_string].pack("H6")
        end

        def row_padding
          "\x0" * (@width % 4)
        end
      end
    end
  end
end


text:
package com.theoryinpractice.testng.model;

import com.intellij.execution.Location;
import com.intellij.execution.PsiLocation;
import com.intellij.execution.testframework.*;
import com.intellij.execution.testframework.stacktrace.DiffHyperlink;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.ide.util.EditSourceUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.pom.Navigatable;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import org.testng.remote.strprotocol.MessageHelper;
import org.testng.remote.strprotocol.TestResultMessage;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Hani Suleiman Date: Jul 28, 2005 Time: 10:52:51 PM
 */
public class TestProxy extends AbstractTestProxy {
  @NonNls public static final Pattern COMPARISION_PATTERN =
    Pattern.compile("(.*)expected same with:\\<(.*)\\> but was:\\<(.*)\\>.*", Pattern.DOTALL);
  @NonNls public static final Pattern EXPECTED_BUT_WAS_PATTERN =
    Pattern.compile("(.*)expected:\\<(.*)\\> but was:\\<(.*)\\>.*", Pattern.DOTALL);
  @NonNls public static final Pattern EXPECTED_BUT_WAS_SET_PATTERN =
    Pattern.compile("(.*)expected \\[(.*)\\] but got \\[(.*)\\].*", Pattern.DOTALL);
  @NonNls public static final Pattern EXPECTED_NOT_SAME_BUT_WAS_PATTERN =
    Pattern.compile("(.*)expected not same with:\\<(.*)\\> but was same:\\<(.*)\\>.*", Pattern.DOTALL);
  @NonNls public static final Pattern EXPECTED_BUT_FOUND_PATTERN =
    Pattern.compile("(.*)expected \\[(.*)\\] but found \\[(.*)\\].*", Pattern.DOTALL);
  private final List<TestProxy> results = new ArrayList<TestProxy>();
  private TestResultMessage resultMessage;
  private String name;
  private TestProxy parent;
  private SmartPsiElementPointer psiElement;
  private boolean inProgress;
  private boolean myTearDownFailure;
  private DiffHyperlink myHyperlink;

  public TestProxy() {}

  public TestProxy(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  @Nullable
  public PsiElement getPsiElement() {
    return psiElement != null ? psiElement.getElement() : null;
  }

  public void setPsiElement(PsiElement psiElement) {
    if (psiElement != null) {
      final Project project = psiElement.getProject();
      PsiDocumentManager.getInstance(project).commitAllDocuments();
      this.psiElement = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(psiElement);
    } else {
      this.psiElement = null;
    }
  }

  public boolean isResult() {
    return resultMessage != null;
  }

  public List<AbstractTestProxy> getResults(Filter filter) {
    return filter.select(results);
  }

  public List<TestProxy> getChildren() {
    return results;
  }

  public TestResultMessage getResultMessage() {
    return resultMessage;
  }

  public void setResultMessage(final TestResultMessage resultMessage) {
    //if we have a result, then our parent is a class, so we can look up our method
    //this is a bit fragile as it assumes parent is set first and correctly
    ApplicationManager.getApplication().runReadAction(new Runnable() {
      public void run() {
        PsiClass psiClass = (PsiClass)getParent().getPsiElement();
        if (psiClass != null) {
          PsiMethod[] methods = psiClass.getAllMethods();
          for (PsiMethod method : methods) {
            if (method.getName().equals(resultMessage.getMethod())) {
              setPsiElement(method);
              break;
            }
          }
        }
      }
    });

    TestProxy current = this;
    while (current != null) {
      current.inProgress = resultMessage.getResult() == MessageHelper.TEST_STARTED;
      current = current.getParent();
    }
    if (this.resultMessage == null || this.resultMessage.getResult() == MessageHelper.TEST_STARTED) {
      this.resultMessage = resultMessage;
      final PsiElement psiElement = getPsiElement();
      this.name = toDisplayText(resultMessage, psiElement != null ? psiElement.getProject() : null);
    }
  }

  public boolean isInProgress() {
    final TestProxy parentProxy = getParent();
    return (parentProxy == null || parentProxy.isInProgress()) && inProgress;
  }

  public boolean isDefect() {
    return isNotPassed();
  }

  public boolean shouldRun() {
    return true;
  }

  public int getMagnitude() {
    return -1;
  }

  public boolean isLeaf() {
    return isResult();
  }

  public boolean isPassed() {
    return !isNotPassed();
  }

  public Location getLocation(final Project project, GlobalSearchScope searchScope) {
    if (psiElement == null) return null;
    final PsiElement element = psiElement.getElement();
    if (element == null) return null;
    return new PsiLocation<PsiElement>(project, element);
  }

  @Nullable
  public Navigatable getDescriptor(final Location location, final TestConsoleProperties testConsoleProperties) {
    if (location == null) return null;
    return EditSourceUtil.getDescriptor(location.getPsiElement());
  }

  @Override
  public String toString() {
    return name + ' ' + results;
  }

  public void addChild(TestProxy proxy) {
    results.add(proxy);
    proxy.setParent(this);
    proxy.setPrinter(myPrinter);
    addLast(proxy);
  }

  public void setParent(TestProxy parent) {
    this.parent = parent;
  }

  public TestProxy getParent() {
    return parent;
  }

  public boolean isNotPassed() {
    if (resultNotPassed()) return true;
    //we just added the node, so we don't know if it has passes or fails
    if (resultMessage == null && results.size() == 0) return true;
    for (TestProxy child : results) {
      if (child.isNotPassed()) return true;
    }
    return false;
  }

  private boolean resultNotPassed() {
    return resultMessage != null && resultMessage.getResult() != MessageHelper.PASSED_TEST;
  }

  public List<TestProxy> getAllTests() {
    List<TestProxy> total = new ArrayList<TestProxy>();
    total.add(this);
    for (TestProxy child : results) {
      total.addAll(child.getAllTests());
    }
    return total;
  }

  public int getChildCount() {
    return results.size();
  }

  public TestProxy getChildAt(int i) {
    return results.get(i);
  }

  public TestProxy getFirstDefect() {
    for (TestProxy child : results) {
      if (child.isNotPassed() && child.isResult()) return child;
      TestProxy firstDefect = child.getFirstDefect();
      if (firstDefect != null) return firstDefect;
    }
    return null;
  }

  public boolean isInterrupted() {
    return !isInProgress() && inProgress;
  }

  @Override
  public boolean isIgnored() {
    return resultMessage != null && MessageHelper.SKIPPED_TEST == resultMessage.getResult();
  }

  public boolean isTearDownFailure() {
    for (TestProxy result : results) {
      if (result.isTearDownFailure()) return true;
    }
    return myTearDownFailure;
  }

  public void setTearDownFailure(boolean tearDownFailure) {
    myTearDownFailure = tearDownFailure;
  }

  public void appendStacktrace(TestResultMessage result) {
    if (result.getResult() == MessageHelper.PASSED_TEST && Registry.is("testng.skip.expected.exceptions")) return;
    final String stackTrace = result.getStackTrace();
    if (stackTrace != null) {
      final List<Printable> printables = getPrintables(result);
      for (Printable printable : printables) {
        if (myHyperlink == null && printable instanceof DiffHyperlink) {
          myHyperlink = (DiffHyperlink)printable;
        }
        addLast(printable);
      }
    }
  }

  @Override
  public Long getDuration() {
    TestResultMessage message = getResultMessage();
    if (message != null) {
      return (message.getEndMillis() - message.getStartMillis());
    }
    else {
      // TODO cache?
      long duration = 0;
      for (TestProxy testProxy : getChildren()) {
        final Long d = testProxy.getDuration();
        duration += (d == null ? 0 : d.longValue());
      }
      return duration;
    }
  }

  @Override
  public boolean shouldSkipRootNodeForExport() {
    return true;
  }

  @Override
  public AssertEqualsDiffViewerProvider getDiffViewerProvider() {
    if (myHyperlink == null) {
      return null;
    }
    return new AssertEqualsDiffViewerProvider() {
      @Override
      public void openDiff(Project project) {
        myHyperlink.openDiff(project);
      }

      @Override
      public String getExpected() {
        return myHyperlink.getLeft();
      }

      @Override
      public String getActual() {
        return myHyperlink.getRight();
      }
    };
  }

  private static String trimStackTrace(String stackTrace) {
    String[] lines = stackTrace.split("\n");
    StringBuilder builder = new StringBuilder();

    if (lines.length > 0) {
      int i = lines.length - 1;
      while (i >= 0) {
        //first 4 chars are '\t at '
        int startIndex = lines[i].indexOf('a') + 3;
        if (lines[i].length() > 4 &&
            (lines[i].startsWith("org.testng.", startIndex) ||
             lines[i].startsWith("org.junit.", startIndex) ||
             lines[i].startsWith("sun.reflect.DelegatingMethodAccessorImpl", startIndex) ||
             lines[i].startsWith("sun.reflect.NativeMethodAccessorImpl", startIndex) ||
             lines[i].startsWith("java.lang.reflect.Method", startIndex) ||
             lines[i].startsWith("com.intellij.rt.execution.application.AppMain", startIndex))) {

        }
        else {
          // we're done with internals, so we know the rest are ok
          break;
        }
        i--;
      }
      for (int j = 0; j <= i; j++) {
        builder.append(lines[j]);
        builder.append('\n');
      }
    }
    return builder.toString();
  }

  private static List<Printable> getPrintables(final TestResultMessage result) {
    String s = trimStackTrace(result.getStackTrace());
    List<Printable> printables = new ArrayList<Printable>();
    //figure out if we have a diff we need to hyperlink
    if (appendDiffChuncks(result, s, printables, COMPARISION_PATTERN)) {
      return printables;
    }
    if (appendDiffChuncks(result, s, printables, EXPECTED_BUT_WAS_PATTERN)) {
      return printables;
    }
    if (appendDiffChuncks(result, s, printables, EXPECTED_BUT_WAS_SET_PATTERN)) {
      return printables;
    }
    if (appendDiffChuncks(result, s, printables, EXPECTED_NOT_SAME_BUT_WAS_PATTERN)) {
      return printables;
    }
    if (appendDiffChuncks(result, s, printables, EXPECTED_BUT_FOUND_PATTERN)) {
      return printables;
    }
    printables.add(new Chunk(s, ConsoleViewContentType.ERROR_OUTPUT));
    return printables;
  }

  private static boolean appendDiffChuncks(final TestResultMessage result, String s, List<Printable> printables, final Pattern pattern) {
    final Matcher matcher = pattern.matcher(s);
    if (matcher.matches()) {
      printables.add(new Chunk(matcher.group(1), ConsoleViewContentType.ERROR_OUTPUT));
      //we have an assert with expected/actual, so we parse it out and create a diff hyperlink
      DiffHyperlink link = new DiffHyperlink(matcher.group(2), matcher.group(3), null) {
        protected String getTitle() {
          //TODO should do some more farting about to find the equality assertion that failed and show that as title
          return result.getTestClass() + '#' + result.getMethod() + "() failed";
        }
      };
      //same as junit diff view
      printables.add(link);
      printables.add(new Chunk(trimStackTrace(s.substring(matcher.end(3) + 1)), ConsoleViewContentType.ERROR_OUTPUT));
      return true;
    }
    return false;
  }

  public static String toDisplayText(TestResultMessage message, Project project) {
    String name = message.getName();
    if (project != null && Comparing.strEqual(name, project.getName())) {
      name = message.getMethod();
    }
    final String mainNamePart = name;
    final String[] parameters = message.getParameters();
    if (parameters != null && parameters.length > 0) {
      final String[] parameterTypes = message.getParameterTypes();
      name += " (";
      for(int i= 0; i < parameters.length; i++) {
        if(i > 0) {
          name += ", ";
        }
        if(CommonClassNames.JAVA_LANG_STRING.equals(parameterTypes[i]) && !("null".equals(parameters[i]) || "\"\"".equals(parameters[i]))) {
          name += "\"" + parameters[i] + "\"";
        }
        else {
          name += parameters[i];
        }

      }
      name += ")";
    }
    final String testDescription = message.getTestDescription();
    if (testDescription != null && !Comparing.strEqual(testDescription, mainNamePart)) {
      name += " [" + testDescription + "]";
    }
    return name;
  }

  public static class Chunk implements Printable {
    public String text;
    public ConsoleViewContentType contentType;

    public void printOn(Printer printer) {
      printer.print(text, contentType);
    }

    public Chunk(String text, ConsoleViewContentType contentType) {
      this.text = text;
      this.contentType = contentType;
    }

    public String toString() {
      return text;
    }
  }
}


text:
package arduinoMeasurement.controller.events;

public class DisconnectEvent extends ControllerEvent
{

}


text:
$(function() {
    $('form.chat_form button[type="submit"]').click(function(event) {
        event.preventDefault();
        event.stopPropagation();

        var $form = $(event.currentTarget).closest('form.chat_form');

        $.post('/send?' + $form.serialize(), function(data, textStatus, jqXHR) {
            $form.find('input[name="message"]').val('');
        });
    });

    var wsUri = 'ws://localhost:8080';

    var ws_chat_1 = new WebSocket(wsUri);
    var ws_chat_2 = new WebSocket(wsUri);
    var ws_chat_3 = new WebSocket(wsUri);

    ws_chat_1.onopen = function(evt) {
        console.log('Open connection chat 1!');
    };
    ws_chat_2.onopen = function(evt) {
        console.log('Open connection chat 2!');
    };
    ws_chat_3.onopen = function(evt) {
        console.log('Open connection chat 3!');
    };

    ws_chat_1.onclose = function(evt) {
        console.log('CLOSE connection chat 1!');
    };
    ws_chat_2.onclose = function(evt) {
        console.log('CLOSE connection chat 2!');
    };
    ws_chat_3.onclose = function(evt) {
        console.log('CLOSE connection chat 3!');
    };

    ws_chat_1.onerror = function(evt) {
        console.log('ERROR chat 1!!!');
    };
    ws_chat_2.onerror = function(evt) {
        console.log('ERROR chat 2!!!');
    };
    ws_chat_3.onerror = function(evt) {
        console.log('ERROR chat 3!!!');
    };

    var template = _.template("
<%- user_name %>

<%- message %>
");

    ws_chat_1.onmessage = function(evt) {
        var html = template(JSON.parse(evt.data));
        $('#chat_1 dl').append(html);
        console.log('=====================');
        console.log('MESSAGE recived to chat 1!');
        console.log(evt);
        console.log('=====================');
    };
    ws_chat_2.onmessage = function(evt) {
        var html = template(JSON.parse(evt.data));
        $('#chat_2 dl').append(html);
        console.log('=====================');
        console.log('MESSAGE recived to chat 2!');
        console.log(evt);
        console.log('=====================');
    };
    ws_chat_3.onmessage = function(evt) {
        var html = template(JSON.parse(evt.data));
        $('#chat_3 dl').append(html);
        console.log('=====================');
        console.log('MESSAGE recived to chat 3!');
        console.log(evt);
        console.log('=====================');
    };
});


text:
class MemMapFile
{
	enum
	{
		MinViewLength = 512 * 1024 // 512KB seems reasonable
	};

	::SYSTEM_INFO       m_sysInfo;

	Handle              m_hFile;
	Handle              m_hFileMapping;

	unsigned __int64    m_fileSize;
	unsigned __int64    m_viewOffset;
	SIZE_T              m_viewLength;
	SIZE_T              m_minViewLength;
	char*               m_view;

public:
	MemMapFile()
		: m_hFile(), m_hFileMapping(NULL), m_view(NULL)
	{ }

	MemMapFile(const char* fileName, SIZE_T minViewLength = MinViewLength);
	~MemMapFile(void);

	bool Open(const char* fileName, SIZE_T minViewLength = MinViewLength);
	void Close();

	void* MapView(unsigned __int64 viewOffset, SIZE_T& viewLength);
};


text:
const set = require('regenerate')();
set.addRange(0x10F30, 0x10F59);
module.exports = set;


text:
export interface Drawable {
	id: number;
	name?: string;
	draw: (target: Node) => void;
}

class Rect implements Drawable {
	id: number;
	draw(target: Node) {}
}

const thing: Drawable = {
	id: 0,
	draw: function (target: Node) { }
};


text:
import * as React from 'react';
import type { StackHeaderProps } from '../../types';
declare const _default: React.NamedExoticComponent<StackHeaderProps>;
export default _default;


text:
<?php

namespace AppBundle\Entity\Main;

use AppBundle\Entity\Base\Simple;

class NewsletterUser extends Simple {

	/**
	 *
	 * @var string
	 */
	private $name;

	/**
	 *
	 * @var boolean
	 */
	private $infomarket;

	/**
	 *
	 * @var boolean
	 */
	private $infoprodukt;

	/**
	 *
	 * @var boolean
	 */
	private $subscribed;

	/**
	 *
	 * @var \Doctrine\Common\Collections\Collection
	 */
	private $newsletterUserNewsletterGroupAssignments;

	/**
	 *
	 * @var \Doctrine\Common\Collections\Collection
	 */
	private $newsletterUserNewsletterPageAssignments;

	/**
	 * Constructor
	 */
	public function __construct() {
		$this->newsletterUserNewsletterGroupAssignments = new \Doctrine\Common\Collections\ArrayCollection();
		$this->newsletterUserNewsletterPageAssignments = new \Doctrine\Common\Collections\ArrayCollection();
	}

	/**
	 * Set name
	 *
	 * @param string $name
	 *
	 * @return NewsletterUser
	 */
	public function setName($name) {
		$this->name = $name;

		return $this;
	}

	/**
	 * Get name
	 *
	 * @return string
	 */
	public function getName() {
		return $this->name;
	}

	/**
	 * Set infomarket
	 *
	 * @param boolean $infomarket
	 *
	 * @return NewsletterUser
	 */
	public function setInfomarket($infomarket) {
		$this->infomarket = $infomarket;

		return $this;
	}

	/**
	 * Get infomarket
	 *
	 * @return boolean
	 */
	public function getInfomarket() {
		return $this->infomarket;
	}

	/**
	 * Set infoprodukt
	 *
	 * @param boolean $infoprodukt
	 *
	 * @return NewsletterUser
	 */
	public function setInfoprodukt($infoprodukt) {
		$this->infoprodukt = $infoprodukt;

		return $this;
	}

	/**
	 * Get infoprodukt
	 *
	 * @return boolean
	 */
	public function getInfoprodukt() {
		return $this->infoprodukt;
	}

	/**
	 * Set subscribed
	 *
	 * @param boolean $subscribed
	 *
	 * @return NewsletterUser
	 */
	public function setSubscribed($subscribed) {
		$this->subscribed = $subscribed;

		return $this;
	}

	/**
	 * Get subscribed
	 *
	 * @return boolean
	 */
	public function getSubscribed() {
		return $this->subscribed;
	}

	/**
	 * Add newsletterUserNewsletterGroupAssignment
	 *
	 * @param \AppBundle\Entity\Assignments\NewsletterUserNewsletterGroupAssignment $newsletterUserNewsletterGroupAssignment
	 *
	 * @return NewsletterUser
	 */
	public function addNewsletterUserNewsletterGroupAssignment(
			\AppBundle\Entity\Assignments\NewsletterUserNewsletterGroupAssignment $newsletterUserNewsletterGroupAssignment) {
		$this->newsletterUserNewsletterGroupAssignments[] = $newsletterUserNewsletterGroupAssignment;

		return $this;
	}

	/**
	 * Remove newsletterUserNewsletterGroupAssignment
	 *
	 * @param \AppBundle\Entity\Assignments\NewsletterUserNewsletterGroupAssignment $newsletterUserNewsletterGroupAssignment
	 */
	public function removeNewsletterUserNewsletterGroupAssignment(
			\AppBundle\Entity\Assignments\NewsletterUserNewsletterGroupAssignment $newsletterUserNewsletterGroupAssignment) {
		$this->newsletterUserNewsletterGroupAssignments->removeElement($newsletterUserNewsletterGroupAssignment);
	}

	/**
	 * Get newsletterUserNewsletterGroupAssignments
	 *
	 * @return \Doctrine\Common\Collections\Collection
	 */
	public function getNewsletterUserNewsletterGroupAssignments() {
		return $this->newsletterUserNewsletterGroupAssignments;
	}

	/**
	 * Add newsletterUserNewsletterPageAssignment
	 *
	 * @param \AppBundle\Entity\Assignments\NewsletterUserNewsletterPageAssignment $newsletterUserNewsletterPageAssignment
	 *
	 * @return NewsletterUser
	 */
	public function addNewsletterUserNewsletterPageAssignment(
			\AppBundle\Entity\Assignments\NewsletterUserNewsletterPageAssignment $newsletterUserNewsletterPageAssignment) {
		$this->newsletterUserNewsletterPageAssignments[] = $newsletterUserNewsletterPageAssignment;

		return $this;
	}

	/**
	 * Remove newsletterUserNewsletterPageAssignment
	 *
	 * @param \AppBundle\Entity\Assignments\NewsletterUserNewsletterPageAssignment $newsletterUserNewsletterPageAssignment
	 */
	public function removeNewsletterUserNewsletterPageAssignment(
			\AppBundle\Entity\Assignments\NewsletterUserNewsletterPageAssignment $newsletterUserNewsletterPageAssignment) {
		$this->newsletterUserNewsletterPageAssignments->removeElement($newsletterUserNewsletterPageAssignment);
	}

	/**
	 * Get newsletterUserNewsletterPageAssignments
	 *
	 * @return \Doctrine\Common\Collections\Collection
	 */
	public function getNewsletterUserNewsletterPageAssignments() {
		return $this->newsletterUserNewsletterPageAssignments;
	}
}


text:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Смарт-меню</string>
    <string name="action_settings">Параметры настройки</string>
    <string name="cancel">Отмена</string>
    <string name="widetouch_help_label">Справка</string>
    <string name="widetouch_add_app">Добавить</string>
    <string name="widetouch_search">Поиск</string>
    <string name="widetouch_favor">Избранное</string>
    <string name="widetouch_camera">Камера</string>
    <string name="widetouch_back">Закрыть</string>
    <string name="widetouch_home">Гл. страница</string>
    <string name="widetouch_setting">Триггер</string>
    <string name="widetouch_lockscreen">Блок. экрана</string>
    <string name="widetouch_screencapture">Скриншоты</string>
    <string name="widetouch_recently">История</string>
    <string name="widetouch_music">Музыка</string>
    <string name="widetouch_video">Видео</string>
    <string name="widetouch_levoice">Поиск</string>
    <string name="widetouch_memoryclear">Очистить память</string>
    <string name="widetouch_calculator">Калькулятор</string>
    <string name="widetouch_note">Блокнот</string>
    <string name="widetouch_alarm">Будильник</string>
    <string name="widetouch_torchlight">Фонарик</string>
    <string name="widetouch_setting_area">S-Меню</string>
    <string name="widetouch_task_exchange">Переключение между заданиями</string>
    <string name="widetouch_multiwindow">Multi Window</string>
    <string name="widetouch_switch">Настройка активации функции</string>
    <string name="widetouch_float_button">Кнопка</string>
    <string name="widetouch_widetouch">Прикосновение</string>
    <string name="widetouch_float_button_summary">Нажмите плавающую кнопку для вызова меню</string>
    <string name="widetouch_widetouch_summary">Коснитесь любого свободного места на дисплее для вызова меню</string>
    <string name="widetouch_recentapp">Недавно открытые приложения</string>
    <string name="switch_brightness">Яркость</string>
    <string name="switch_wifi">WLAN</string>
    <string name="switch_rotation">Автоповор.</string>
    <string name="switch_smart_rotation">S-поворот</string>
    <string name="switch_rotation_off">Поворот</string>
    <string name="switch_bluetooth">Bluetooth</string>
    <string name="switch_profile">Звук</string>
    <string name="switch_flightmode">Полет</string>
    <string name="switch_mobile">Моб. Инет</string>
    <string name="switch_gps">GPS</string>
    <string name="switch_empty" />
    <string name="msg_memoryclear">Очистка</string>
    <string name="msg_clear_size">%d Мб памяти свободно</string>
    <string name="msg_function_select">Выбор приложений</string>
    <string name="msg_app_uninstalled">Приложение было удалено, или такого приложения не существует</string>
    <string name="msg_shutdown_singlehand">Shut down singlehand mode first</string>
    <string name="msg_close_home_landscape_prohibit">"shut down 'prohit Home key under landscape' first"</string>
    <string name="msg_open_flightmode">Включить автономный режим?</string>
    <string name="msg_title_flightmode">Airplane mode</string>
    <string name="msg_try_widetouch">Калибровка</string>
    <string name="msg_known">ОК</string>
    <string name="hint_normal">Для калибровки прижмите большой палец руки к центру круга</string>
    <string name="hint_secret_label">Рекомендация:</string>
    <string name="hint_secret_text">"1.Сильно нажмите пальцем
2.Полностью прижмите палец"</string>
    <string name="hint_counting_down">Осталось %d сек.</string>
    <string name="hint_success">Калибровка завершена</string>
    <string name="hint_fail_too_short">Осталось мало времени, повт. попытку</string>
    <string name="hint_fail_gesture_wrong">Ошибка распознав. жеста, повт. попытку</string>
    <string name="hint_first_use">Откалибруйте перед использованием</string>
    <string name="app_name_standard">Смарт-меню: калибровка</string>
    <string name="msg_phone_in_use">Функция распознавания голоса недоступна во время звонков</string>
    <string name="label_floatbutton_alpha">Прозрачность кнопки</string>
    <string name="switch_wifi_row">Wi-Fi</string>
    <string name="hello_world">Hello world!</string>
</resources>


text:
pike.graph module
=================

.. automodule:: pike.graph
    :members:
    :undoc-members:
    :show-inheritance:


text:
package se.walkercrou.ghp.ghp;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Uses {@link GitHubPages} to update the specified repository from the specified content directory.
 */
@Mojo(name = "update")
public class UpdatePagesMojo extends AbstractMojo {
    /**
     * The directory where the repository will be cloned to.
     */
    public static final String WORKING_DIR = "target/ghp-plugin";
    /**
     * Format string for commit message if left unset.
     */
    public static final String DEFAULT_COMMIT_MESSAGE = "Automatic commit message generated by " +
            "the GitHub Pages Maven Plugin\n%s";
    /**
     * The name of properties file for this plugin.
     */
    public static final String PROPERTIES_FILE_NAME = ".properties";

    @Parameter(defaultValue = "${project.scm.url}", required = true, readonly = true)
    private String uri;
    @Parameter(property = "push.branch", defaultValue = GitHubPages.DEFAULT_BRANCH)
    private String branch;
    @Parameter(property = "push.commitMessage")
    private String commitMessage;
    @Parameter(property = "push.contentDir", defaultValue = GitHubPages.APIDOCS)
    private String contentDir;
    @Parameter(property = "push.contentDestination")
    private String contentDestination;
    private Log log;

    @Override
    public void execute() throws MojoFailureException, MojoExecutionException {
        log = getLog();
        GitHubPages ghPages = new GitHubPages(this,
                new File(WORKING_DIR),
                new File(WORKING_DIR + File.separator + contentDestination),
                uri, branch);
        ghPages.resetContent();
        ghPages.addContent(new File(contentDir));
        String commitMessage = getCommitMessage();
        log.debug("Using commit message : \"" + commitMessage + "\"");
        ghPages.update(getCommitMessage());
    }

    private String getCommitMessage() {
        if (commitMessage == null || commitMessage.isEmpty()) {
            String url = getPluginUrl();
            log.debug("Plugin URL : \"" + url + "\"");
            return String.format(DEFAULT_COMMIT_MESSAGE, url == null ? "" : url);
        }
        return commitMessage;
    }

    private String getPluginUrl() {
        Properties properties = new Properties();
        try {
            InputStream in = UpdatePagesMojo.class.getResourceAsStream("/" + PROPERTIES_FILE_NAME);
            if (in == null)
                throw new IOException("Could not get InputStream for properties file");
            properties.load(in);
        } catch (IOException e) {
            getLog().warn("Could not load internal plugin properties", e);
        }
        return properties.getProperty("url");
    }
}