text:
"""Copyright 2009 Chris Davis

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License."""

import os
import sys
import pwd
import errno

from os.path import join, dirname, normpath, exists, isdir
from optparse import OptionParser
from ConfigParser import ConfigParser

from carbon import log, state
from carbon.database import TimeSeriesDatabase
from carbon.exceptions import CarbonConfigException

from twisted.python import usage

defaults = dict(
  USER="",
  MAX_CACHE_SIZE=float('inf'),
  MAX_UPDATES_PER_SECOND=500,
  MAX_CREATES_PER_MINUTE=float('inf'),
  LINE_RECEIVER_INTERFACE='0.0.0.0',
  LINE_RECEIVER_PORT=2003,
  ENABLE_UDP_LISTENER=False,
  UDP_RECEIVER_INTERFACE='0.0.0.0',
  UDP_RECEIVER_PORT=2003,
  PICKLE_RECEIVER_INTERFACE='0.0.0.0',
  PICKLE_RECEIVER_PORT=2004,
  CACHE_QUERY_INTERFACE='0.0.0.0',
  CACHE_QUERY_PORT=7002,
  LOG_UPDATES=True,
  LOG_CACHE_HITS=True,
  LOG_CACHE_QUEUE_SORTS=True,
  DATABASE='whisper',
  WHISPER_AUTOFLUSH=False,
  WHISPER_SPARSE_CREATE=False,
  WHISPER_FALLOCATE_CREATE=False,
  WHISPER_LOCK_WRITES=False,
  MAX_DATAPOINTS_PER_MESSAGE=500,
  MAX_AGGREGATION_INTERVALS=5,
  FORWARD_ALL=True,
  MAX_QUEUE_SIZE=1000,
  QUEUE_LOW_WATERMARK_PCT=0.8,
  TIME_TO_DEFER_SENDING=0.0001,
  ENABLE_AMQP=False,
  AMQP_VERBOSE=False,
  AMQP_SPEC=None,
  BIND_PATTERNS=['#'],
  ENABLE_MANHOLE=False,
  MANHOLE_INTERFACE='127.0.0.1',
  MANHOLE_PORT=7222,
  MANHOLE_USER="",
  MANHOLE_PUBLIC_KEY="",
  RELAY_METHOD='rules',
  REPLICATION_FACTOR=1,
  DIVERSE_REPLICAS=True,
  DESTINATIONS=[],
  USE_FLOW_CONTROL=True,
  USE_INSECURE_UNPICKLER=False,
  USE_WHITELIST=False,
  CARBON_METRIC_PREFIX='carbon',
  CARBON_METRIC_INTERVAL=60,
  CACHE_WRITE_STRATEGY='sorted',
  WRITE_BACK_FREQUENCY=None,
  MIN_RESET_STAT_FLOW=1000,
  MIN_RESET_RATIO=0.9,
  MIN_RESET_INTERVAL=121,
  USE_RATIO_RESET=False,
  LOG_LISTENER_CONN_SUCCESS=True,
  LOG_AGGREGATOR_MISSES=True,
  AGGREGATION_RULES='aggregation-rules.conf',
  REWRITE_RULES='rewrite-rules.conf',
  RELAY_RULES='relay-rules.conf',
  ENABLE_LOGROTATION=True,
  METRIC_CLIENT_IDLE_TIMEOUT=None
)

def _umask(value):
    return int(value, 8)

def _process_alive(pid):
    if exists("/proc"):
        return exists("/proc/%d" % pid)
    else:
        try:
            os.kill(int(pid), 0)
            return True
        except OSError, err:
            return err.errno == errno.EPERM

class OrderedConfigParser(ConfigParser):
  """Hacky workaround to ensure sections are always returned in the order
   they are defined in. Note that this does *not* make any guarantees about
   the order of options within a section or the order in which sections get
   written back to disk on write()."""
  _ordered_sections = []

  def read(self, path):
    # Verifies a file exists *and* is readable
    if not os.access(path, os.R_OK):
        raise CarbonConfigException("Error: Missing config file or wrong perms on %s" % path)

    result = ConfigParser.read(self, path)
    sections = []
    for line in open(path):
      line = line.strip()

      if line.startswith('[') and line.endswith(']'):
        sections.append( line[1:-1] )

    self._ordered_sections = sections

    return result

  def sections(self):
    return list( self._ordered_sections ) # return a copy for safety

class Settings(dict):
  __getattr__ = dict.__getitem__

  def __init__(self):
    dict.__init__(self)
    self.update(defaults)

  def readFrom(self, path, section):
    parser = ConfigParser()
    if not parser.read(path):
      raise CarbonConfigException("Failed to read config file %s" % path)

    if not parser.has_section(section):
      return

    for key,value in parser.items(section):
      key = key.upper()

      # Detect type from defaults dict
      if key in defaults:
        valueType = type( defaults[key] )
      else:
        valueType = str

      if valueType is list:
        value = [ v.strip() for v in value.split(',') ]

      elif valueType is bool:
        value = parser.getboolean(section, key)

      else:
        # Attempt to figure out numeric types automatically
        try:
          value = int(value)
        except ValueError:
          try:
            value = float(value)
          except ValueError:
            pass

      self[key] = value

settings = Settings()
settings.update(defaults)

class CarbonCacheOptions(usage.Options):

    optFlags = [
        ["debug", "", "Run in debug mode."],
        ]

    optParameters = [
        ["config", "c", None, "Use the given config file."],
        ["instance", "", "a", "Manage a specific carbon instance."],
        ["logdir", "", None, "Write logs to the given directory."],
        ["whitelist", "", None, "List of metric patterns to allow."],
        ["blacklist", "", None, "List of metric patterns to disallow."],
        ]

    def postOptions(self):
        global settings

        program = self.parent.subCommand

        # Use provided pidfile (if any) as default for configuration. If it's
        # set to 'twistd.pid', that means no value was provided and the default
        # was used.
        pidfile = self.parent["pidfile"]
        if pidfile.endswith("twistd.pid"):
            pidfile = None
        self["pidfile"] = pidfile

        # Enforce a default umask of '022' if none was set.
        if not self.parent.has_key("umask") or self.parent["umask"] is None:
            self.parent["umask"] = 022

        # Read extra settings from the configuration file.
        program_settings = read_config(program, self)
        settings.update(program_settings)
        settings["program"] = program

        # Normalize and expand paths
        settings["STORAGE_DIR"] = os.path.normpath(os.path.expanduser(settings["STORAGE_DIR"]))
        settings["LOCAL_DATA_DIR"] = os.path.normpath(os.path.expanduser(settings["LOCAL_DATA_DIR"]))
        settings["WHITELISTS_DIR"] = os.path.normpath(os.path.expanduser(settings["WHITELISTS_DIR"]))
        settings["PID_DIR"] = os.path.normpath(os.path.expanduser(settings["PID_DIR"]))
        settings["LOG_DIR"] = os.path.normpath(os.path.expanduser(settings["LOG_DIR"]))
        settings["pidfile"] = os.path.normpath(os.path.expanduser(settings["pidfile"]))

        # Set process uid/gid by changing the parent config, if a user was
        # provided in the configuration file.
        if settings.USER:
            self.parent["uid"], self.parent["gid"] = (
                pwd.getpwnam(settings.USER)[2:4])

        # Set the pidfile in parent config to the value that was computed by
        # C{read_config}.
        self.parent["pidfile"] = settings["pidfile"]

        storage_schemas = join(settings["CONF_DIR"], "storage-schemas.conf")
        if not exists(storage_schemas):
            print "Error: missing required config %s" % storage_schemas
            sys.exit(1)

        # Database-specific settings
        database = settings.DATABASE
        if database not in TimeSeriesDatabase.plugins:
            print "No database plugin implemented for '%s'" % database
            raise SystemExit(1)

        database_class = TimeSeriesDatabase.plugins[database]
        state.database = database_class(settings)

        if not "action" in self:
            self["action"] = "start"
        self.handleAction()

        # If we are not running in debug mode or non-daemon mode, then log to a
        # directory, otherwise log output will go to stdout. If parent options
        # are set to log to syslog, then use that instead.
        if not self["debug"]:
            if self.parent.get("syslog", None):
                log.logToSyslog(self.parent["prefix"])
            elif not self.parent["nodaemon"]:
                logdir = settings.LOG_DIR
                if not isdir(logdir):
                    os.makedirs(logdir)
                    if settings.USER:
                        # We have not yet switched to the specified user,
                        # but that user must be able to create files in this
                        # directory.
                        os.chown(logdir, self.parent["uid"], self.parent["gid"])
                log.logToDir(logdir)

        if self["whitelist"] is None:
            self["whitelist"] = join(settings["CONF_DIR"], "whitelist.conf")
        settings["whitelist"] = self["whitelist"]

        if self["blacklist"] is None:
            self["blacklist"] = join(settings["CONF_DIR"], "blacklist.conf")
        settings["blacklist"] = self["blacklist"]

    def parseArgs(self, *action):
        """If an action was provided, store it for further processing."""
        if len(action) == 1:
            self["action"] = action[0]

    def handleAction(self):
        """Handle extra argument for backwards-compatibility.

        * C{start} will simply do minimal pid checking and otherwise let twistd
              take over.
        * C{stop} will kill an existing running process if it matches the
              C{pidfile} contents.
        * C{status} will simply report if the process is up or not.
        """
        action = self["action"]
        pidfile = self.parent["pidfile"]
        program = settings["program"]
        instance = self["instance"]

        if action == "stop":
            if not exists(pidfile):
                print "Pidfile %s does not exist" % pidfile
                raise SystemExit(0)
            pf = open(pidfile, 'r')
            try:
                pid = int(pf.read().strip())
                pf.close()
            except IOError:
                print "Could not read pidfile %s" % pidfile
                raise SystemExit(1)
            print "Sending kill signal to pid %d" % pid
            try:
                os.kill(pid, 15)
            except OSError, e:
                if e.errno == errno.ESRCH:
                    print "No process with pid %d running" % pid
                else:
                    raise

            raise SystemExit(0)

        elif action == "status":
            if not exists(pidfile):
                print "%s (instance %s) is not running" % (program, instance)
                raise SystemExit(1)
            pf = open(pidfile, "r")
            try:
                pid = int(pf.read().strip())
                pf.close()
            except IOError:
                print "Failed to read pid from %s" % pidfile
                raise SystemExit(1)

            if _process_alive(pid):
                print ("%s (instance %s) is running with pid %d" %
                       (program, instance, pid))
                raise SystemExit(0)
            else:
                print "%s (instance %s) is not running" % (program, instance)
                raise SystemExit(1)

        elif action == "start":
            if exists(pidfile):
                pf = open(pidfile, 'r')
                try:
                    pid = int(pf.read().strip())
                    pf.close()
                except IOError:
                    print "Could not read pidfile %s" % pidfile
                    raise SystemExit(1)
                if _process_alive(pid):
                    print ("%s (instance %s) is already running with pid %d" %
                           (program, instance, pid))
                    raise SystemExit(1)
                else:
                    print "Removing stale pidfile %s" % pidfile
                    try:
                        os.unlink(pidfile)
                    except IOError:
                        print "Could not remove pidfile %s" % pidfile
            # Try to create the PID directory
            else:
                if not os.path.exists(settings["PID_DIR"]):
                    try:
                        os.makedirs(settings["PID_DIR"])
                    except OSError as exc: # Python >2.5
                        if exc.errno == errno.EEXIST and os.path.isdir(settings["PID_DIR"]):
                           pass
                        else:
                           raise

            print "Starting %s (instance %s)" % (program, instance)

        else:
            print "Invalid action '%s'" % action
            print "Valid actions: start stop status"
            raise SystemExit(1)

class CarbonAggregatorOptions(CarbonCacheOptions):

    optParameters = [
        ["rules", "", None, "Use the given aggregation rules file."],
        ["rewrite-rules", "", None, "Use the given rewrite rules file."],
        ] + CarbonCacheOptions.optParameters

    def postOptions(self):
        CarbonCacheOptions.postOptions(self)
        if self["rules"] is None:
            self["rules"] = join(settings["CONF_DIR"], settings['AGGREGATION_RULES'])
        settings["aggregation-rules"] = self["rules"]

        if self["rewrite-rules"] is None:
            self["rewrite-rules"] = join(settings["CONF_DIR"],
                                         settings['REWRITE_RULES'])
        settings["rewrite-rules"] = self["rewrite-rules"]

class CarbonRelayOptions(CarbonCacheOptions):

    optParameters = [
        ["rules", "", None, "Use the given relay rules file."],
        ["aggregation-rules", "", None, "Use the given aggregation rules file."],
        ] + CarbonCacheOptions.optParameters

    def postOptions(self):
        CarbonCacheOptions.postOptions(self)
        if self["rules"] is None:
            self["rules"] = join(settings["CONF_DIR"], settings['RELAY_RULES'])
        settings["relay-rules"] = self["rules"]

        if self["aggregation-rules"] is None:
            self["rules"] = join(settings["CONF_DIR"], settings['AGGREGATION_RULES'])
        settings["aggregation-rules"] = self["rules"]

        if settings["RELAY_METHOD"] not in ("rules", "consistent-hashing", "aggregated-consistent-hashing"):
            print ("In carbon.conf, RELAY_METHOD must be either 'rules' or "
                   "'consistent-hashing' or 'aggregated-consistent-hashing'. Invalid value: '%s'" %
                   settings.RELAY_METHOD)
            sys.exit(1)

def get_default_parser(usage="%prog [options] <start|stop|status>"):
    """Create a parser for command line options."""
    parser = OptionParser(usage=usage)
    parser.add_option(
        "--debug", action="store_true",
        help="Run in the foreground, log to stdout")
    parser.add_option(
        "--syslog", action="store_true",
        help="Write logs to syslog")
    parser.add_option(
        "--nodaemon", action="store_true",
        help="Run in the foreground")
    parser.add_option(
        "--profile",
        help="Record performance profile data to the given file")
    parser.add_option(
        "--profiler",
        help="Specify the profiler to use")
    parser.add_option(
        "--pidfile", default=None,
        help="Write pid to the given file")
    parser.add_option(
        "--umask", default=None,
        help="Use the given umask when creating files")
    parser.add_option(
        "--config",
        default=None,
        help="Use the given config file")
    parser.add_option(
      "--whitelist",
      default=None,
      help="Use the given whitelist file")
    parser.add_option(
      "--blacklist",
      default=None,
      help="Use the given blacklist file")
    parser.add_option(
        "--logdir",
        default=None,
        help="Write logs in the given directory")
    parser.add_option(
        "--instance",
        default='a',
        help="Manage a specific carbon instance")

    return parser

def get_parser(name):
    parser = get_default_parser()
    if name == "carbon-aggregator":
        parser.add_option(
            "--rules",
            default=None,
            help="Use the given aggregation rules file.")
        parser.add_option(
            "--rewrite-rules",
            default=None,
            help="Use the given rewrite rules file.")
    elif name == "carbon-relay":
        parser.add_option(
            "--rules",
            default=None,
            help="Use the given relay rules file.")
    return parser

def parse_options(parser, args):
    """
    Parse command line options and print usage message if no arguments were
    provided for the command.
    """
    (options, args) = parser.parse_args(args)

    if not args:
        parser.print_usage()
        raise SystemExit(1)

    if args[0] not in ("start", "stop", "status"):
        parser.print_usage()
        raise SystemExit(1)

    return options, args

def read_config(program, options, **kwargs):
    """
    Read settings for 'program' from configuration file specified by
    'options["config"]', with missing values provided by 'defaults'.
    """
    settings = Settings()
    settings.update(defaults)

    # Initialize default values if not set yet.
    for name, value in kwargs.items():
        settings.setdefault(name, value)

    graphite_root = kwargs.get("ROOT_DIR")
    if graphite_root is None:
        graphite_root = os.environ.get('GRAPHITE_ROOT')
    if graphite_root is None:
        raise CarbonConfigException("Either ROOT_DIR or GRAPHITE_ROOT "
                         "needs to be provided.")

    # Default config directory to root-relative, unless overriden by the
    # 'GRAPHITE_CONF_DIR' environment variable.
    settings.setdefault("CONF_DIR",
                        os.environ.get("GRAPHITE_CONF_DIR",
                                       join(graphite_root, "conf")))
    if options["config"] is None:
        options["config"] = join(settings["CONF_DIR"], "carbon.conf")
    else:
        # Set 'CONF_DIR' to the parent directory of the 'carbon.conf' config
        # file.
        settings["CONF_DIR"] = dirname(normpath(options["config"]))

    # Storage directory can be overriden by the 'GRAPHITE_STORAGE_DIR'
    # environment variable. It defaults to a path relative to GRAPHITE_ROOT
    # for backwards compatibility though.
    settings.setdefault("STORAGE_DIR",
                        os.environ.get("GRAPHITE_STORAGE_DIR",
                                       join(graphite_root, "storage")))

    # By default, everything is written to subdirectories of the storage dir.
    settings.setdefault(
        "PID_DIR", settings["STORAGE_DIR"])
    settings.setdefault(
        "LOG_DIR", join(settings["STORAGE_DIR"], "log", program))
    settings.setdefault(
        "LOCAL_DATA_DIR", join(settings["STORAGE_DIR"], "whisper"))
    settings.setdefault(
        "WHITELISTS_DIR", join(settings["STORAGE_DIR"], "lists"))

    # Read configuration options from program-specific section.
    section = program[len("carbon-"):]
    config = options["config"]

    if not exists(config):
        raise CarbonConfigException("Error: missing required config %r" % config)

    settings.readFrom(config, section)
    settings.setdefault("instance", options["instance"])

    # If a specific instance of the program is specified, augment the settings
    # with the instance-specific settings and provide sane defaults for
    # optional settings.
    if options["instance"]:
        settings.readFrom(config,
                          "%s:%s" % (section, options["instance"]))
        settings["pidfile"] = (
            options["pidfile"] or
            join(settings["PID_DIR"], "%s-%s.pid" %
                 (program, options["instance"])))
        settings["LOG_DIR"] = (options["logdir"] or
                              join(settings["LOG_DIR"],
                                "%s-%s" % (program ,options["instance"])))
    else:
        settings["pidfile"] = (
            options["pidfile"] or
            join(settings["PID_DIR"], '%s.pid' % program))
        settings["LOG_DIR"] = (options["logdir"] or settings["LOG_DIR"])

    return settings


text:
function [out] = gpdirectcover(hyp, varargin)
% This is a cover function that allows us to use the Direct algorithm.
% It takes an array of hyper parameters and converts them to a structure
% that the gp code can use.its a crude hack and prolly need to refine it.
% but will work for the present.

nmp = varargin{1};
N = length(hyp);

hyps.mean = hyp(N-nmp+1:N);
hyps.cov = hyp(1:N-nmp-1);
hyps.lik = hyp(N-nmp);

[out] = gp(hyps,varargin{2:end});
return;

redpajama_set_name: RedPajamaGithub


text:
package uk.nhs.careconnect.ri.stu3.dao;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenParam;
import org.hl7.fhir.dstu3.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;
import uk.nhs.careconnect.fhir.OperationOutcomeException;
import uk.nhs.careconnect.ri.database.daointerface.*;
import uk.nhs.careconnect.ri.stu3.dao.transforms.CompositionEntityToFHIRCompositionTransformer;
import uk.nhs.careconnect.ri.database.entity.codeSystem.ConceptEntity;
import uk.nhs.careconnect.ri.database.entity.composition.CompositionEntity;
import uk.nhs.careconnect.ri.database.entity.composition.CompositionIdentifier;
import uk.nhs.careconnect.ri.database.entity.composition.CompositionSection;
import uk.nhs.careconnect.ri.database.entity.encounter.EncounterEntity;
import uk.nhs.careconnect.ri.database.entity.organization.OrganisationEntity;
import uk.nhs.careconnect.ri.database.entity.patient.PatientEntity;
import uk.nhs.careconnect.ri.database.entity.practitioner.PractitionerEntity;
import uk.nhs.careconnect.ri.database.entity.relatedPerson.RelatedPersonEntity;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.*;
import javax.transaction.Transactional;
import java.net.URI;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

@Repository
@Transactional
public class CompositionDao implements CompositionRepository {

    @PersistenceContext
    EntityManager em;

    @Autowired
    @Lazy
    ConceptRepository conceptDao;

    @Autowired
    PatientRepository patientDao;

    @Autowired
    PractitionerRepository practitionerDao;

    @Autowired
    RelatedPersonRepository personDao;

    @Autowired
    @Lazy
    EncounterRepository encounterDao;

    @Autowired
    OrganisationRepository organisationDao;

    @Autowired
    private CodeSystemRepository codeSystemSvc;

    @Autowired
    private LibDao libDao;

    @Autowired
    CompositionEntityToFHIRCompositionTransformer compositionEntityToFHIRCompositionTransformer;

    private static final Logger log = LoggerFactory.getLogger(CompositionDao.class);
    @Override
    public void save(FhirContext ctx, CompositionEntity composition) {

    }

    @Override
    public Composition read(FhirContext ctx, IdType theId) {
        if (daoutils.isNumeric(theId.getIdPart())) {
            CompositionEntity composition = em.find(CompositionEntity.class, Long.parseLong(theId.getIdPart()));

            return composition != null ? compositionEntityToFHIRCompositionTransformer.transform(composition) : null;
        } else {
            return null;
        }
    }

    @Override
    public Long count() {
        CriteriaBuilder qb = em.getCriteriaBuilder();
        CriteriaQuery<Long> cq = qb.createQuery(Long.class);
        cq.select(qb.count(cq.from(CompositionEntity.class)));
        //cq.where(/*your stuff*/);
        return em.createQuery(cq).getSingleResult();
    }

    @Override
    public CompositionEntity readEntity(FhirContext ctx, IdType theId) {
        if (daoutils.isNumeric(theId.getIdPart())) {
            CompositionEntity composition = em.find(CompositionEntity.class, Long.parseLong(theId.getIdPart()));

            return composition;
        } else {
            return null;
        }
    }

    @Override
    public Composition create(FhirContext ctx, Composition composition, IdType theId, String theConditional) throws OperationOutcomeException {
        log.debug("Composition.save");

        CompositionEntity compositionEntity = null;

        if (composition.hasId()) compositionEntity = readEntity(ctx, composition.getIdElement());

        if (theConditional != null) {
            try {

                if (theConditional.contains("fhir.leedsth.nhs.uk/Id/composition")) {
                    URI uri = new URI(theConditional);

                    String scheme = uri.getScheme();
                    String host = uri.getHost();
                    String query = uri.getRawQuery();
                    log.debug(query);
                    String[] spiltStr = query.split("%7C");
                    log.debug(spiltStr[1]);

                    List<CompositionEntity> results = searchEntity(ctx, null, new TokenParam().setValue(spiltStr[1]).setSystem("https://fhir.leedsth.nhs.uk/Id/composition"),null, null, null);
                    for (CompositionEntity con : results) {
                        compositionEntity = con;
                        break;
                    }
                } else {
                    log.info("NOT SUPPORTED: Conditional Url = "+theConditional);
                }

            } catch (Exception ex) {

            }
        }

        if (compositionEntity == null) {
            compositionEntity = new CompositionEntity();
        }

        if (composition.hasStatus()) {
            compositionEntity.setStatus(composition.getStatus());
        }

        if (composition.hasType()) {
            ConceptEntity code = conceptDao.findAddCode(composition.getType().getCoding().get(0));
            if (code != null) { compositionEntity.setType(code); }
            else {
                log.info("Type: Missing System/Code = "+ composition.getType().getCoding().get(0).getSystem() +" code = "+composition.getType().getCoding().get(0).getCode());

                throw new IllegalArgumentException("Missing System/Code = "+ composition.getType().getCoding().get(0).getSystem()
                        +" code = "+composition.getType().getCoding().get(0).getCode());
            }
        }
        if (composition.hasClass_()) {
            ConceptEntity code = conceptDao.findAddCode(composition.getClass_().getCoding().get(0));
            if (code != null) { compositionEntity.setClass_(code); }
            else {
                log.info("Class: Missing System/Code = "+ composition.getClass_().getCoding().get(0).getSystem() +" code = "+composition.getClass_().getCoding().get(0).getCode());

                throw new IllegalArgumentException("Missing System/Code = "+ composition.getClass_().getCoding().get(0).getSystem()
                        +" code = "+composition.getClass_().getCoding().get(0).getCode());
            }
        } else {
            // Check extension for service type.
            for (Extension extension : composition.getExtension()) {
                if (extension.getUrl().contains("https://fhir.nhs.uk/STU3/StructureDefinition/Extension-ITK-CareSettingType-1")) {
                    CodeableConcept concept = (CodeableConcept) extension.getValue();
                    ConceptEntity code = conceptDao.findAddCode(concept.getCoding().get(0));
                    if (code != null) { compositionEntity.setClass_(code); }
                }
            }
        }
        PatientEntity patientEntity = null;
        if (composition.hasSubject()) {
            log.trace(composition.getSubject().getReference());
            patientEntity = patientDao.readEntity(ctx, new IdType(composition.getSubject().getReference()));
            compositionEntity.setPatient(patientEntity);
        }

        if (composition.hasEncounter()) {
            EncounterEntity encounterEntity = encounterDao.readEntity(ctx, new IdType(composition.getEncounter().getReference()));
            compositionEntity.setEncounter(encounterEntity);
        }
        if (composition.hasDate()) {
            compositionEntity.setDate(composition.getDate());
        }
        for (Reference reference : composition.getAuthor()) {
            if (reference.getReference().contains("Practitioner")) {
                PractitionerEntity practitionerEntity = practitionerDao.readEntity(ctx, new IdType(reference.getReference()));
                compositionEntity.setAuthorPractitioner(practitionerEntity);
            }
            if (reference.getReference().contains("RelatedPerson")) {
                RelatedPersonEntity personEntity = personDao.readEntity(ctx, new IdType(reference.getReference()));
                compositionEntity.setAuthorPerson(personEntity);
            }
        }
        if (composition.hasTitle()) {
            compositionEntity.setTitle(composition.getTitle());
        }
        if (composition.hasConfidentiality()) {
            compositionEntity.setConfidentiality(composition.getConfidentiality());
        }
        if (composition.hasCustodian()) {
            OrganisationEntity organisationEntity = organisationDao.readEntity(ctx, new IdType(composition.getCustodian().getReference()));
            compositionEntity.setCustodianOrganisation(organisationEntity);
        }

        em.persist(compositionEntity);

        if (composition.getIdentifier() != null) {
            Identifier identifier = composition.getIdentifier();
            CompositionIdentifier compositionIdentifier = null;

            for (CompositionIdentifier orgSearch : compositionEntity.getIdentifiers()) {
                if (identifier.getSystem().equals(orgSearch.getSystemUri()) && identifier.getValue().equals(orgSearch.getValue())) {
                    compositionIdentifier = orgSearch;
                    break;
                }
            }
            if (compositionIdentifier == null)  compositionIdentifier = new CompositionIdentifier();

            compositionIdentifier= (CompositionIdentifier) libDao.setIdentifier(identifier,compositionIdentifier  );
            compositionIdentifier.setComposition(compositionEntity);
            em.persist(compositionIdentifier);
        }

        for (Composition.SectionComponent section : composition.getSection()) {
            CompositionSection sectionEntity = null;
            if (section.hasCode()) {
               log.trace("New Section Code = "+section.getCode().getCoding().get(0).getCode());
                for (CompositionSection sectionSearch :compositionEntity.getSections()) {
                    if (sectionSearch.getCode() != null) {
                        log.trace("Existing Section Code = "+sectionSearch.getCode().getCode());
                        if (section.getCode().getCoding().get(0).getCode().equals(sectionSearch.getCode().getCode())) {
                            sectionEntity = sectionSearch;
                            log.trace("Found match");
                            break;
                        }
                    }
                }
            }
            if (sectionEntity == null) {
                log.trace("Section Not Found");
                sectionEntity = new CompositionSection();
                sectionEntity.setComposition(compositionEntity);
            }
            if (section.hasCode()) {
                ConceptEntity code = conceptDao.findAddCode(section.getCode().getCoding().get(0));
                if (code != null) { sectionEntity.setCode(code); }
                else {
                    log.info("Class: Missing System/Code = "+ section.getCode().getCoding().get(0).getSystem()
                            +" code = "+section.getCode().getCoding().get(0).getCode());

                    throw new IllegalArgumentException("Missing System/Code = "+ section.getCode().getCoding().get(0).getSystem()
                            +" code = "+section.getCode().getCoding().get(0).getCode());
                }
            }
            if (section.hasTitle()) {
                sectionEntity.setTitle(section.getTitle());
            }
            if (section.hasText()) {

                sectionEntity.setNarrative(section.getText().getDivAsString());
                sectionEntity.setNarrativeStatus(section.getText().getStatus());
            }
            if (section.hasOrderedBy()) {
                ConceptEntity code = conceptDao.findCode(section.getOrderedBy().getCoding().get(0));
                if (code != null) { sectionEntity.setOrderBy(code); }
                else {
                    log.info("Class: Missing System/Code = "+ section.getOrderedBy().getCoding().get(0).getSystem()
                            +" code = "+section.getOrderedBy().getCoding().get(0).getCode());

                    throw new IllegalArgumentException("Missing System/Code = "+ section.getOrderedBy().getCoding().get(0).getSystem()
                            +" code = "+section.getOrderedBy().getCoding().get(0).getCode());
                }
            }
            em.persist(sectionEntity);
        }

        return compositionEntityToFHIRCompositionTransformer.transform(compositionEntity);
    }

    @Override
    public List<Composition> search(FhirContext ctx, ReferenceParam patient, TokenParam identifier, StringParam id, TokenParam type
            , DateRangeParam dateRange) {
        List<CompositionEntity> qryResults = searchEntity(ctx,patient, identifier, id, type, dateRange);
        List<Composition> results = new ArrayList<>();

        for (CompositionEntity compositionEntity : qryResults)
        {
            Composition composition = compositionEntityToFHIRCompositionTransformer.transform(compositionEntity);
            results.add(composition);
        }

        return results;
    }

    @Override
    public List<CompositionEntity> searchEntity(FhirContext ctx, ReferenceParam patient, TokenParam identifier, StringParam id, TokenParam type
            , DateRangeParam dateRange) {
        List<CompositionEntity> qryResults = null;

        CriteriaBuilder builder = em.getCriteriaBuilder();

        CriteriaQuery<CompositionEntity> criteria = builder.createQuery(CompositionEntity.class);
        Root<CompositionEntity> root = criteria.from(CompositionEntity.class);

        List<Predicate> predList = new LinkedList<Predicate>();
        List<Condition> results = new ArrayList<Condition>();

        if (patient != null) {
            // KGM 4/1/2018 only search on patient id
            if (daoutils.isNumeric(patient.getIdPart())) {
                Join<CompositionEntity, PatientEntity> join = root.join("patient", JoinType.LEFT);

                Predicate p = builder.equal(join.get("id"),patient.getIdPart());
                predList.add(p);
            } else {
                Join<CompositionEntity, PatientEntity> join = root.join("patient", JoinType.LEFT);

                Predicate p = builder.equal(join.get("id"),-1);
                predList.add(p);
            }

        }
        if (id != null) {
            Predicate p = builder.equal(root.get("id"),id.getValue());
            predList.add(p);
        }
        if (identifier !=null)
        {
            Join<CompositionEntity, CompositionIdentifier> join = root.join("identifiers", JoinType.LEFT);

            Predicate p = builder.equal(join.get("value"),identifier.getValue());
            predList.add(p);
            // TODO predList.add(builder.equal(join.get("system"),identifier.getSystem()));

        }

        Predicate[] predArray = new Predicate[predList.size()];
        predList.toArray(predArray);
        if (predList.size()>0)
        {
            criteria.select(root).where(predArray);
        }
        else
        {
            criteria.select(root);
        }

        TypedQuery<CompositionEntity> typedQuery = em.createQuery(criteria).setMaxResults(daoutils.MAXROWS);

        qryResults = typedQuery.getResultList();
        return qryResults;
    }
}


text:
require "spec_helper"

describe Whois::Server::Adapters::NotImplemented do

  before(:each) do
    @definition = [:ipv6, "2001:0000::/32", "teredo", { :adapter => Whois::Server::Adapters::NotImplemented }]
  end

  describe "#query" do
    it "raises Whois::ServerNotImplemented" do
      lambda do
        klass.new(*@definition).query("example.test")
      end.should raise_error(Whois::ServerNotImplemented)
    end

    it "customizes the error message according to the host" do
      lambda do
        klass.new(*@definition).query("example.test")
      end.should raise_error(Whois::ServerNotImplemented, /teredo/)
    end
  end

end


text:
package uk.ac.susx.tag.classificationframework.clusters.clusteranalysis;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
import com.google.common.primitives.Ints;
import org.apache.commons.io.FileUtils;
import org.apache.commons.math.stat.clustering.Cluster;
import uk.ac.susx.tag.classificationframework.clusters.ClusteredProcessedInstance;
import uk.ac.susx.tag.classificationframework.datastructures.Instance;
import uk.ac.susx.tag.classificationframework.datastructures.ProcessedInstance;
import uk.ac.susx.tag.classificationframework.datastructures.RootedNgramCounter;
import uk.ac.susx.tag.classificationframework.datastructures.RootedNgramCounter.TopNgram;
import uk.ac.susx.tag.classificationframework.featureextraction.filtering.TokenFilterByRegex;
import uk.ac.susx.tag.classificationframework.featureextraction.filtering.TokenFilterRelevanceStopwords;
import uk.ac.susx.tag.classificationframework.featureextraction.inference.FeatureInferrer;
import uk.ac.susx.tag.classificationframework.featureextraction.pipelines.FeatureExtractionPipeline;
import uk.ac.susx.tag.classificationframework.featureextraction.pipelines.PipelineBuilder;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static uk.ac.susx.tag.classificationframework.clusters.clusteranalysis.FeatureClusterJointCounter.*;
import static uk.ac.susx.tag.classificationframework.clusters.clusteranalysis.IncrementalSurprisingPhraseAnalysis.OrderingMethod.LIKELIHOOD_IN_TARGET_OVER_BACKGROUND;
import static uk.ac.susx.tag.classificationframework.featureextraction.pipelines.FeatureExtractionPipeline.PipelineChanges;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;

/**
 *
 * Analyse the features in clusters of documents.
 *
 * WARNINGS:
 *   - CREATING AN INSTANCE OF THIS CLASS WITH BACKGROUND DOCUMENTS WILL MAKE YOUR PIPELINE USE A NON-FIXED VOCABULARY
 *   - This class maintains references to your clustered documents (not background), and maintains counts of all features
 *     it has seen.
 *   - Currently, only FeatureBasedCounts with Background documents is implemented fully.
 *
 * Workflow info:
 *
 *    - Words, hashtags, and account tags are considered different feature types. When selecting topFeatures() or
 *      topPhrases() you'll probably specify which kind you are interested in.
 *    - Top hashtags and account tags are selected using frequency.
 *    - Top words primarily use PMI.
 *    - Top phrases use the PMI words and frequency counts of surrounding ngrams.
 *    - use getTopFeatures() for lists of just top features.
 *    - use getTopPhrases() for mapping from top features to their surrounding frequent ngrams.
 *
 *
 * Some classes to know about:
 *
 * FeatureClusterJointCounter : these know a method of counting up feature/cluster occurrences, in
 *                              order to provide feature priors and joint cluster probabilities.
 *                              E.g. 1+ occurrences in a single document might count as a single
 *                              occurrence.
 *
 * FeatureClusterJointCounter
 *     .ClusterMembershipTest : when counting up features that occur in clusters, we need to determine
 *                              whether the containing document is considered "in" a cluster. Implementations
 *                              of this interface specify how this is done. E.g. only the cluster with the
 *                              highest membership probability.
 *
 * OrderingMethod             : When trying to get a list of most interesting features per cluster, there
 *                              are many methods of ranking. This enum allows the user to select between them.

 *
 * User: Andrew D. Robertson
 * Date: 16/10/2015
 * Time: 15:07
 */
public class ClusterFeatureAnalysis {

    // Allows specification of the type of feature we're interested in when asking for top features.
    private FeatureClusterJointCounter counts;
    private Collection<ClusteredProcessedInstance> documents;
    private ClusterMembershipTest t;
    private int numOfClusters;

    public enum OrderingMethod {
        LIKELIHOOD_IN_CLUSTER_OVER_PRIOR,  // Essentially PMI: P(feature|cluster) / P(feature)
    }

    public ClusterFeatureAnalysis(Collection<ClusteredProcessedInstance> documents, FeatureExtractionPipeline pipeline){
        this(documents, pipeline,
             new FeatureBasedCounts(),
             new HighestProbabilityOnly(),
             5);
    }

    public ClusterFeatureAnalysis(Collection<ClusteredProcessedInstance> documents,
                                  Iterable<Instance> backgroundDocuments,
                                  FeatureExtractionPipeline pipeline) {
        this(documents, backgroundDocuments, pipeline,
             new FeatureBasedCounts(),
             new HighestProbabilityOnly(),
             5,
             5);
    }

    public ClusterFeatureAnalysis(Collection<ClusteredProcessedInstance> documents,
                                  FeatureExtractionPipeline pipeline,
                                  FeatureClusterJointCounter c,
                                  ClusterMembershipTest t,
                                  int minimumFeatureCount) {
        counts = c;
        numOfClusters = documents.iterator().next().getClusterVector().length;
        this.documents = documents;
        this.t = t;
        c.count(documents, t, pipeline);
        c.pruneFeaturesWithCountLessThan(minimumFeatureCount);
    }

    public ClusterFeatureAnalysis(Collection<ClusteredProcessedInstance> documents,
                                  Iterable<Instance> backgroundDocuments,
                                  FeatureExtractionPipeline pipeline,
                                  FeatureClusterJointCounter c,
                                  ClusterMembershipTest t,
                                  int minimumBackgroundFeatureCount,
                                  int minimumClusterFeatureCount){
        counts = c;
        numOfClusters = documents.iterator().next().getClusterVector().length;
        this.documents = documents;
        this.t = t;

        pipeline.setFixedVocabulary(false);

        c.count(documents, backgroundDocuments, t, pipeline);
        if (minimumBackgroundFeatureCount > 1) {
            c.pruneOnlyBackgroundFeaturesWithCountLessThan(minimumBackgroundFeatureCount);
        }
        if (minimumClusterFeatureCount > 1) {
            c.pruneOnlyClusterFeaturesWithCountLessThan(minimumClusterFeatureCount);
        }
    }

    public static interface Logger {
        void log(String msg);
    }

    public static List<List<Integer>> getTopFeatures(
            int K,
            OrderingMethod method,
            FeatureType featureType,
            Collection<ClusteredProcessedInstance> documents,
            Iterable<Instance> backgroundDocuments,
            FeatureExtractionPipeline pipeline,
            FeatureClusterJointCounter counts,
            boolean reInitialiseCounts,
            ClusterMembershipTest t,
            int minimumBackgroundFeatureCount,
            int minimumClusterFeatureCount){
        return getTopFeatures(K, method, featureType, documents, backgroundDocuments, pipeline, counts, reInitialiseCounts, t, minimumBackgroundFeatureCount, minimumClusterFeatureCount, null);
    }

    public static List<List<Integer>> getTopFeatures(
            int K,
            OrderingMethod method,
            FeatureType featureType,
            Collection<ClusteredProcessedInstance> documents,
            Iterable<Instance> backgroundDocuments,
            FeatureExtractionPipeline pipeline,
            FeatureClusterJointCounter counts,
            boolean reInitialiseCounts,
            ClusterMembershipTest t,
            int minimumBackgroundFeatureCount,
            int minimumClusterFeatureCount,
            Logger logger){

        int numOfClusters = documents.iterator().next().getClusterVector().length;
        pipeline.setFixedVocabulary(false);

        if ( logger != null) logger.log("Counting");

        // Do feature counting
        counts.count(documents, backgroundDocuments, t, pipeline, reInitialiseCounts);

        if ( logger != null) logger.log("Pruning");

        if (!reInitialiseCounts) {
            // Do feature pruning by frequency
            if (minimumBackgroundFeatureCount > 1) {
                counts.pruneOnlyBackgroundFeaturesWithCountLessThan(minimumBackgroundFeatureCount);
            }
        }
        if (minimumClusterFeatureCount > 1) {
            counts.pruneOnlyClusterFeaturesWithCountLessThan(minimumClusterFeatureCount);
        }

        List<List<Integer>> topFeaturesPerCluster = new ArrayList<>();

        if ( logger != null) logger.log("Sorting.");
        // Get top features for each cluster
        for (int clusterIndex = 0; clusterIndex < numOfClusters; clusterIndex++){
            // Establish the feature ranking method
            Ordering<Integer> ordering;
            switch(method){
                case LIKELIHOOD_IN_CLUSTER_OVER_PRIOR:
                    ordering = new LikelihoodPriorRatioOrdering(clusterIndex, featureType, counts); break;
                default: throw new RuntimeException("OrderingMethod not recognised");
            }

            topFeaturesPerCluster.add(ordering.greatestOf(counts.getFeaturesInCluster(clusterIndex, featureType), K));
        }

        if ( logger != null) logger.log("Features found.");

        return topFeaturesPerCluster;
    }

    /**
     *
     * @param clusterIndex The index of the cluster of interest
     * @param topFeatures Top features as obtained from getTopFeatures()
     * @param documents The same documents used for getTopFeatures(), ensure that indices match up if you did any reprocessing
     * @param pipeline The pipeline used during getTopFeatures()
     * @param t A ClusterMembershipTest instance; an object which knows how to test whether a document is in a cluster
     * @param numPhrasesPerFeature The number of phrases to attempt to find per feature if possible
     * @param minLeafPruningThreshold Each n+1gram appeared a fraction of the time that its parent ngram occurred.
     *                                This is the minimum threshold on that fraction that the n+1gram must have
     *                                occurred to be considered a part of the phrase. The actual threshold could
     *                                be higher based on the other parameters.
     * @param minimumCount            An ngram must have occurred at least this many times to be considered at all.
     * @param level1NgramCount        When the occurrences of an n+1gram's parent ngram is less than this threshold
     *                                the n+1gram must have occurred 100% of these times to be considered.
     * @param level2NgramCount        When the occurrences of an n+1gram's parent ngram is less than this threshold
     *                                the n+1gram must have occurred more than 75% of these times to be considered
     * @param level3NgramCount        When the occurrences of an n+1gram's parent ngram is less than this threshold
     *                                the n+1gram must have occurred more than 50% of these times to be considered
     * @param stopwords               A set of stopwords; when frequency does not differentiate between ngrams, the
     *                                number of stopwords an ngram contains, or whether or not the ngram ends with a
     *                                stopword can be used to pick more interesting ngrams.
     * @param minPhraseSize           The minimum size ngrams that we'll be interested in.
     * @param maxPhraseSize           The maximum size ngrams that we'll be interested in.
     * @return A map from top feature to its top phrases
     */
    public static Map<String, List<String>> getTopPhrases(int clusterIndex,
                                                                List<Integer> topFeatures,
                                                                List<ClusteredProcessedInstance> documents,
                                                                FeatureExtractionPipeline pipeline,
                                                                ClusterMembershipTest t,
                                                                int numPhrasesPerFeature,
                                                                double minLeafPruningThreshold, // E.g. 0.2
                                                                int minimumCount, // E.g. 4
                                                                int level1NgramCount, // E.g. 5
                                                                int level2NgramCount, // E.g. 7
                                                                int level3NgramCount, // E.g. 15
                                                                Set<String> stopwords, // E.g. TokenFilterRelevanceStopwords.getStopwords()
                                                                int minPhraseSize,    // E.g. 1
                                                                int maxPhraseSize){  // E.g. 6

        Map<Integer, List<TopNgram<Integer>>> indexedTopPhrases = getTopPhrases(
                clusterIndex, topFeatures, documents, t, numPhrasesPerFeature,
                minLeafPruningThreshold, minimumCount,
                level1NgramCount, level2NgramCount, level3NgramCount, stopwords.stream().map(pipeline::featureIndex).collect(Collectors.toSet()),
                minPhraseSize, maxPhraseSize
        );

        Map<String, List<String>> topPhrasesPerFeature = new LinkedHashMap<>();

        for (Map.Entry<Integer, List<TopNgram<Integer>>> entry : indexedTopPhrases.entrySet()){
            List<String> phrases = entry.getValue().stream()
                    .map(topNgram -> (topNgram.ngram.stream().map(pipeline::featureString).collect(Collectors.joining(" "))))
                    .collect(Collectors.toList());
            topPhrasesPerFeature.put(pipeline.featureString(entry.getKey()), phrases);
        }
        return topPhrasesPerFeature;
    }

    public static Map<Integer, List<TopNgram<Integer>>> getTopPhrases(int clusterIndex,
                                                                  List<Integer> topFeatures,
                                                                  List<ClusteredProcessedInstance> documents,
                                                                  ClusterMembershipTest t,
                                                                  int numPhrasesPerFeature,
                                                                  double minleafPruningThreshold,
                                                                  int minimumCount,
                                                                  int level1NgramCount,
                                                                  int level2NgramCount,
                                                                  int level3NgramCount,
                                                                  Set<Integer> stopwords,
                                                                  int minPhraseSize,
                                                                  int maxPhraseSize){

        List<RootedNgramCounter<Integer>> counters = topFeatures.stream()
                                                        .map(f -> new RootedNgramCounter<>(f, minPhraseSize, maxPhraseSize, minleafPruningThreshold, minimumCount,level1NgramCount, level2NgramCount, level3NgramCount, stopwords))
                                                        .collect(Collectors.toList());
        // For each document that is in the relevant cluster, count occurrences of surrounding words of each word of interest
        for (ClusteredProcessedInstance document : documents) {
            t.setup(document);
            if (t.isDocumentInCluster(document, clusterIndex)){
                for(RootedNgramCounter<Integer> counter : counters){
                    counter.addContext(Ints.asList(document.getDocument().features), 1);
                }
            }
        }

        // For each word of interest, pick the longest most frequent phrases
        Map<Integer, List<TopNgram<Integer>>> topPhrasesPerFeature = new LinkedHashMap<>();
        for (RootedNgramCounter<Integer> counter : counters){
            topPhrasesPerFeature.put(counter.getRootToken(), counter.topNgrams(numPhrasesPerFeature));
        }

        return topPhrasesPerFeature;
    }

    public FeatureClusterJointCounter getCounts() {
        return counts;
    }

    public int getNumOfClusters() {
        return numOfClusters;
    }

    public List<Integer> getFrequentFeatures(int clusterIndex, int K, FeatureType t){
        return new JointLikelihoodOrdering(clusterIndex, t)
                    .greatestOf(counts.getFeaturesInCluster(clusterIndex, t), K);
    }
    public List<String> getFrequentFeatures(int clusterIndex, int K, FeatureType t, FeatureExtractionPipeline pipeline){
        return getFrequentFeatures(clusterIndex, K, t).stream()
                .map(pipeline::featureString)
                .collect(Collectors.toList());
    }

    public List<String> getTopFeatures(int clusterIndex, int K, FeatureExtractionPipeline pipeline, FeatureType t){
        return getTopFeatures(clusterIndex, K, OrderingMethod.LIKELIHOOD_IN_CLUSTER_OVER_PRIOR, pipeline, t);
    }

    public List<String> getTopFeatures(int clusterIndex, int K, OrderingMethod m, FeatureExtractionPipeline pipeline, FeatureType t){
        return getTopFeatures(clusterIndex, K, m, t).stream()
                .map(pipeline::featureString)
                .collect(Collectors.toList());
    }

    public List<Integer> getTopFeatures(int clusterIndex, int K, FeatureType t){
        return getTopFeatures(clusterIndex, K, OrderingMethod.LIKELIHOOD_IN_CLUSTER_OVER_PRIOR, t);
    }

    /**
     * Get a list of the K most interesting features for a given cluster and ordering method.
     */
    public List<Integer> getTopFeatures(int clusterIndex, int K, OrderingMethod m, FeatureType t) {
        Ordering<Integer> ordering;
        switch(m) {
            case LIKELIHOOD_IN_CLUSTER_OVER_PRIOR:
                ordering = new LikelihoodPriorRatioOrdering(clusterIndex, t, counts); break;
            default:
                throw new RuntimeException("OrderingMethod not recognised.");

        }

        return ordering.greatestOf(counts.getFeaturesInCluster(clusterIndex, t), K);
    }

    public Map<String, List<String>> getTopPhrases(int clusterIndex, int numFeatures, int numPhrasesPerFeature, FeatureExtractionPipeline pipeline){
        return getTopPhrases(clusterIndex,
                numFeatures, numPhrasesPerFeature, pipeline,
                OrderingMethod.LIKELIHOOD_IN_CLUSTER_OVER_PRIOR, FeatureType.WORD,
//                Here i changed a static behaviour of getStopwords
                0.3, 4, 5, 7, 15, TokenFilterRelevanceStopwords.getStopwords("en"), 1, 6);
    }

    /**
     * Obtain a mapping from the top features (as produced by getTopFeatures()), to the top phrases that involve said
     * feature.
     * @param clusterIndex The cluster of interest
     * @param numFeatures  The max number of top features to consider
     * @param numPhrasesPerFeature The max number of top phrases to consider
     * @param pipeline used for de-indexing features
     * @param m The method of selecting the top features
     * @param featureType The type of feature of interest. Probably you want FEATURE_TYPE.WORD
     * @param minLeafPruningThreshold Used for deciding how long a phrase should be allowed to be. E.g. if set to 0.3, then
     *                             a longer ngram must account for >=30% of the occurrences of its shorter variant to be permissible.
     * @param minPhraseSize The minimum size ngram to be considered
     * @param maxPhraseSize The maximum size ngram to be considered.
     * @return A mapping from top features to the most common phrases they occur in.
     */
    public Map<String, List<String>> getTopPhrases(int clusterIndex,
                                                   int numFeatures,
                                                   int numPhrasesPerFeature,
                                                   FeatureExtractionPipeline pipeline,
                                                   OrderingMethod m,
                                                   FeatureType featureType,
                                                   double minLeafPruningThreshold,
                                                   int minimumCount,
                                                   int level1NgramCount,
                                                   int level2NgramCount,
                                                   int level3NgramCount,
                                                   Set<String> stopwords,
                                                   int minPhraseSize,
                                                   int maxPhraseSize ){

        Map<Integer, List<TopNgram<Integer>>> indexedTopPhrases = getTopPhrases(
                clusterIndex, numFeatures, numPhrasesPerFeature, m, featureType,
                minLeafPruningThreshold, minimumCount,
                level1NgramCount, level2NgramCount, level3NgramCount, stopwords.stream().map(pipeline::featureIndex).collect(Collectors.toSet()),
                minPhraseSize, maxPhraseSize
        );

        Map<String, List<String>> topPhrasesPerFeature = new LinkedHashMap<>();

        for (Map.Entry<Integer, List<TopNgram<Integer>>> entry : indexedTopPhrases.entrySet()){
            List<String> phrases = new ArrayList<>();
            for (TopNgram<Integer> topNgram : entry.getValue()){
                phrases.add(Joiner.on(" ").join(topNgram.ngram.stream().map(pipeline::featureString).collect(Collectors.toList())));
            }
            topPhrasesPerFeature.put(pipeline.featureString(entry.getKey()), phrases);
        }
        return topPhrasesPerFeature;
    }

    public Map<Integer, List<TopNgram<Integer>>> getTopPhrases(int clusterIndex,
                                                     int numFeatures,
                                                     int numPhrasesPerFeature,
                                                     OrderingMethod m,
                                                     FeatureType featureType,
                                                     double minLeafPruningThreshold,
                                                     int minimumCount,
                                                     int level1NgramCount,
                                                     int level2NgramCount,
                                                     int level3NgramCount,
                                                     Set<Integer> stopwords,
                                                     int minPhraseSize,
                                                     int maxPhraseSize){

        List<Integer> features = getTopFeatures(clusterIndex, numFeatures, m, featureType);

        List<RootedNgramCounter<Integer>> counters = features.stream()
                                                        .map(f -> new RootedNgramCounter<>(f, minPhraseSize, maxPhraseSize, minLeafPruningThreshold, minimumCount, level1NgramCount, level2NgramCount, level3NgramCount, stopwords))
                                                        .collect(Collectors.toList());

        // For each document that is in the relevant cluster, count occurrences of surrounding words of each word of interest
        for (ClusteredProcessedInstance document : documents){
            t.setup(document);
            if (t.isDocumentInCluster(document, clusterIndex)){
                for (RootedNgramCounter<Integer> counter : counters){
                    counter.addContext(Ints.asList(document.getDocument().features), 1);
                }
            }
        }

        // For each word of interest, pick the longest most frequent phrases
        Map<Integer, List<TopNgram<Integer>>> topPhrases = new LinkedHashMap<>();
        for (RootedNgramCounter<Integer> counter : counters){
            topPhrases.put(counter.getRootToken(), counter.topNgrams(numPhrasesPerFeature));
        }

        return topPhrases;
    }

    public static class LikelihoodPriorRatioOrdering extends Ordering<Integer> {

        int clusterIndex = 0;
        FeatureType t;
        FeatureClusterJointCounter theCounts;

        public LikelihoodPriorRatioOrdering(int clusterIndex, FeatureType t, FeatureClusterJointCounter counts) {
            this.clusterIndex = clusterIndex;
            this.t = t;
            this.theCounts = counts;
        }

        @Override
        public int compare(Integer feature1, Integer feature2) {

            double leftRatio = Math.log(theCounts.likelihoodFeatureGivenCluster(feature1, clusterIndex, t)) - Math.log(theCounts.featurePrior(feature1, t));
            double rightRatio = Math.log(theCounts.likelihoodFeatureGivenCluster(feature2, clusterIndex, t)) - Math.log(theCounts.featurePrior(feature2, t));
            return Double.compare(leftRatio, rightRatio);
        }
    }

    public class JointLikelihoodOrdering extends Ordering<Integer> {

        int clusterIndex;
        FeatureType t;

        public JointLikelihoodOrdering(int clusterIndex, FeatureType t){
            this.clusterIndex = clusterIndex;
            this.t = t;
        }

        @Override
        public int compare(Integer left, Integer right) {
            return Double.compare(counts.likelihoodFeatureGivenCluster(left, clusterIndex, t), counts.likelihoodFeatureGivenCluster(right, clusterIndex, t));
        }
    }

//    /**
//     * Order by:
//     *
//     *    P(feature|cluster) / P(feature|NOT-cluster)
//     */
//    public class LikelihoodsInAndOutOfClusterRatioOrdering extends Ordering<Integer> {
//
//        int clusterIndex = 0;
//        public LikelihoodsInAndOutOfClusterRatioOrdering(int clusterIndex) {
//            this.clusterIndex = clusterIndex;
//        }
//
//        @Override
//        public int compare(Integer feature1, Integer feature2) {
//
//            double leftRatio = Math.log(counts.likelihoodFeatureGivenCluster(feature1, clusterIndex)) - Math.log(counts.likelihoodFeatureGivenNotCluster(feature1, clusterIndex));
//            double rightRatio = Math.log(counts.likelihoodFeatureGivenCluster(feature2, clusterIndex)) - Math.log(counts.likelihoodFeatureGivenNotCluster(feature2, clusterIndex));
//
//            return Double.compare(leftRatio, rightRatio);
//        }
//
//    }

    public static FeatureBasedCounts saveNewBackgroundCounter(File outputFile, int numOfClusters, Iterable<Instance> backgroundDocuments, FeatureExtractionPipeline pipeline, int minimumBackgroundFeatureCount) throws IOException {
        FeatureBasedCounts counter = new FeatureBasedCounts();
        System.out.println("Start processing background ");
        // Only pass in the background documents. Make a fake clustered document, so that the function can extract a number of clusters, though this will be overwritten later
        counter.count(Lists.newArrayList(new ClusteredProcessedInstance(new ProcessedInstance(0, new int[0], null), new double[numOfClusters])), backgroundDocuments, new HighestProbabilityOnly(), pipeline);
        // Prune low frequency features
        counter.pruneOnlyBackgroundFeaturesWithCountLessThan(minimumBackgroundFeatureCount);
        System.out.println("Writing background ");
        try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(outputFile))){
            out.writeObject(counter);
        }
        return counter;
    }

    public static FeatureBasedCounts loadBackgroundCounter(File inputFile) throws IOException, ClassNotFoundException {
        try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(inputFile))){
            return (FeatureBasedCounts)in.readObject();
        }
    }

    public static List<Instance> readCsv(String inpath) {
        List<Instance> list = new ArrayList<Instance>();
        try {
            Reader reader = Files.newBufferedReader(Paths.get(inpath) , StandardCharsets.UTF_16);
            CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
//                    change based on the the number of columns in the file, my file had only text column which contains the articles
                    .withHeader("text")
                    .withIgnoreHeaderCase()
                    .withTrim());

            for (CSVRecord csvRecord: csvParser) {
                String text = csvRecord.get("text").replaceAll("[^\u0000-\u200f]", "");
//                This was added by Qiwiei to check if there is some errors in the file i guess for missing values i kept it but change the size to the number of columns your file have in my case only one column
                if (csvRecord.size()!=1) {
                    System.out.println("!!!!!!! corrupted instance !!!!!");
                    System.out.println(text);
                    System.out.println("!!!!!!! corrupted instance !!!!!");
                }
                else {
                    Instance text_i = new Instance("", text, "");
                    list.add(text_i);

                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        return list;

    }

//    To save the articles
    public static List<Instance> savecorpus(File outputFile, String inpath) throws IOException{
        List<Instance> bg_list = readCsv(inpath);

        try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(outputFile))){
            out.writeObject(bg_list);
        }

        return bg_list;
    }
// To save the pipeline
    public static void savepipeline(File outputFile, FeatureExtractionPipeline pipeline) throws IOException{
        try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(outputFile))){
            out.writeObject(pipeline);
        }
    }
//    load the saved file for testing
    public static Iterable<Instance> load(File inputFile) throws IOException, ClassNotFoundException{

        try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(inputFile))){
            return (Iterable<Instance>)in.readObject();
        }

    }
//      to count the size of the ser file that saved the articles
    public static int count_size(Iterable<Instance> corpus) {
        if (corpus instanceof Collection)
            return ((Collection<?>)corpus).size();
        int i = 0;
        for (Object obj : corpus) i++;
        return i;

    }

//    To print the articles saved in the ser
    public static void print_instance(Iterable<Instance> corpus) {
        for (Instance i: corpus){
            System.out.println(i.text);
            System.out.println("~~~~~~~~~~~~~~~~");
        }
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {

//        // Deserialised it to see if it contains the lang key
//        ObjectInputStream ios = new ObjectInputStream(new FileInputStream("/Users/ay227/Desktop/CASM/Arabic_background/ar-wiki-pipeline.ser"));
//        FeatureExtractionPipeline temp;
//        try {
//            while ((temp = (FeatureExtractionPipeline) ios.readObject()) != null) {
//                System.out.println(temp);
//            }
//        } catch (EOFException e) {
//        } finally {
//            ios.close();
//        }

        List<String> topFeatures = Lists.newArrayList(
                "visualisation",
                "workbench",
                "legasee",
                "findable",
                "voyant",
                "methodologies",
                "mir",
                "retrieval",
                "oral",
                "algorithms"
        );

//        build the pipeline
        FeatureExtractionPipeline arabic_pipeline = new PipelineBuilder().build(new PipelineBuilder.OptionList() // Instantiate the pipeline.
                .add("tokeniser", ImmutableMap.of(
                        "type", "arabicstanford",
                        "filter_punctuation", true,
                        "normalise_urls", true
                        )
                )
                .add("remove_stopwords", ImmutableMap.of(
                        "use", "true",
                        "lang", "ar"))
                .add("filter_regex", "[\\-(())【\\[\\]】]")
                .add("unigrams", true)
        );

//      Read the csv file that contains the article and save it in articles.ser
        List<Instance> bl = savecorpus(new File("/Users/ay227/Desktop/CASM/Arabic_background/ar-wiki-articles.ser"), "/Users/ay227/Desktop/CASM/source_background/ar_background_10.csv");
//        to test the correctness of serializing articles load the generated file
        Iterable<Instance> bl_test = load(new File("/Users/ay227/Desktop/CASM/Arabic_background/ar-wiki-articles.ser"));
//        load one of the files previously generated by other language
        Iterable<Instance> bl_en_test = load(new File("/Users/ay227/Desktop/CASM/git/wikisample-withzh/sample/zh-wiki-articles.ser"));

        System.out.println("Done loading articles");
//        to print the count of the serialized articles for example for the output should be
//        done loading articles
//        36205 the size of the generated Arabic file (approximately)
//        15000 the size of english
        System.out.println(count_size(bl_test));
        System.out.println(count_size(bl_en_test));
//        to print the serialized articles
        print_instance(bl_test);

        savepipeline(new File("/Users/ay227/Desktop/CASM/Arabic_background/ar-wiki-pipeline.ser"), arabic_pipeline);
        System.out.println("Done saving pipeline.ser");

        FeatureBasedCounts counter1 = saveNewBackgroundCounter(new File("/Users/ay227/Desktop/CASM/Arabic_background/ar-wiki-count.ser"), 1, bl, arabic_pipeline, 3);
        System.out.println("Done testing FeatureBasedCounts");

        IncrementalFeatureCounter cNew = new IncrementalFeatureCounter(0.1);
        cNew.incrementCounts(bl, arabic_pipeline, 10);
        cNew.pruneFeaturesWithCountLessThanN(3);
        System.out.println("Done testing IncrementalFeatureCounter");

        try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("/Users/ay227/Desktop/CASM/Arabic_background/ar-wiki-inc-feat-counts.ser"))){
            out.writeObject(cNew);
        }
        System.out.println("Done saving ar-wiki-inc-feat-counts.ser");

    }

    public static void buildGermanBackground() {

    }
}


text:
package org.bouncycastle.jsse.provider;

import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.net.ssl.HandshakeCompletedEvent;
import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;

import org.bouncycastle.jsse.BCSSLSocket;

abstract class ProvSSLSocketBase
    extends SSLSocket
    implements BCSSLSocket
{
    protected static final boolean provAssumeOriginalHostName = PropertyUtils
        .getBooleanSystemProperty("org.bouncycastle.jsse.client.assumeOriginalHostName", false);
    protected static final boolean provJdkTlsTrustNameService = PropertyUtils
        .getBooleanSystemProperty("jdk.tls.trustNameService", false);

    protected final Closeable socketCloser = new Closeable()
    {
        public void close() throws IOException
        {
            closeSocket();
        }
    };

    protected final Map<HandshakeCompletedListener, AccessControlContext> listeners = Collections.synchronizedMap(
        new HashMap<HandshakeCompletedListener, AccessControlContext>(4));

    protected ProvSSLSocketBase()
    {
    }

    @Override
    public void addHandshakeCompletedListener(HandshakeCompletedListener listener)
    {
        if (listener == null)
        {
            throw new IllegalArgumentException("'listener' cannot be null");
        }

        listeners.put(listener, AccessController.getContext());
    }

    protected void closeSocket() throws IOException
    {
        super.close();
    }

    public void connect(String host, int port, int timeout) throws IOException
    {
        setHost(host);

        connect(createInetSocketAddress(host, port), timeout);
    }

    @Override
    public final boolean getOOBInline() throws SocketException
    {
        throw new SocketException(
            "This method is ineffective, since sending urgent data is not supported by SSLSockets");
    }

    @Override
    public void removeHandshakeCompletedListener(HandshakeCompletedListener listener)
    {
        if (listener == null)
        {
            throw new IllegalArgumentException("'listener' cannot be null");
        }
        if (null == listeners.remove(listener))
        {
            throw new IllegalArgumentException("'listener' is not registered");
        }
    }

    @Override
    public final void sendUrgentData(int data) throws IOException
    {
        throw new SocketException("This method is not supported by SSLSockets");
    }

    @Override
    public final void setOOBInline(boolean on) throws SocketException
    {
        throw new SocketException("This method is ineffective, since sending urgent data is not supported by SSLSockets");
    }

    // TODO[jsse] Proper toString for sockets
//    @Override
//    public String toString()
//    {
//        return super.toString();
//    }

    protected InetSocketAddress createInetSocketAddress(InetAddress address, int port) throws IOException
    {
        return new InetSocketAddress(address, port);
    }

    protected InetSocketAddress createInetSocketAddress(String host, int port) throws IOException
    {
        return null == host
            ? new InetSocketAddress(InetAddress.getByName(null), port)
            : new InetSocketAddress(host, port);
    }

    protected void implBind(InetAddress clientAddress, int clientPort) throws IOException
    {
        bind(createInetSocketAddress(clientAddress, clientPort));
    }

    protected void implConnect(InetAddress address, int port) throws IOException
    {
        connect(createInetSocketAddress(address, port), 0);
    }

    protected void implConnect(String host, int port) throws IOException, UnknownHostException
    {
        connect(createInetSocketAddress(host, port), 0);
    }

    protected void notifyHandshakeCompletedListeners(final SSLSession eventSession)
    {
        final Collection<Map.Entry<HandshakeCompletedListener, AccessControlContext>> entries = getHandshakeCompletedEntries();
        if (null == entries)
        {
            return;
        }

        final HandshakeCompletedEvent event = new HandshakeCompletedEvent(this, eventSession);

        final Runnable notifyRunnable = new Runnable()
        {
            public void run()
            {
                for (Map.Entry<HandshakeCompletedListener, AccessControlContext> entry : entries)
                {
                    final HandshakeCompletedListener listener = entry.getKey();
                    final AccessControlContext accessControlContext = entry.getValue();

                    AccessController.doPrivileged(new PrivilegedAction<Void>()
                    {
                        public Void run()
                        {
                            listener.handshakeCompleted(event);
                            return null;
                        }
                    }, accessControlContext);
                }
            }
        };

        SSLSocketUtil.handshakeCompleted(notifyRunnable);
    }

    private Collection<Map.Entry<HandshakeCompletedListener, AccessControlContext>> getHandshakeCompletedEntries()
    {
        synchronized (listeners)
        {
            return listeners.isEmpty()
                ? null
                : new ArrayList<Map.Entry<HandshakeCompletedListener, AccessControlContext>>(listeners.entrySet());
        }
    }
}


text:
import { ExtensionContext, languages } from 'vscode';
import RuleCompletionProvider from './providers/completion';
import RuleHoverProvider from './providers/hover';

export function activate(context: ExtensionContext) {
   context.subscriptions.push(
      languages.registerCompletionItemProvider(
         'firerules',
         new RuleCompletionProvider(),
         '.',
         ' '
      ),
      languages.registerHoverProvider('firerules', new RuleHoverProvider())
   );
}


text:
#include <string>

#include "flatbuffers/flexbuffers.h"  // from @flatbuffers
#include "tensorflow/lite/c/builtin_op_data.h"
#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/core/api/flatbuffer_conversions.h"
#include "tensorflow/lite/core/subgraph.h"
#include "tensorflow/lite/experimental/resource/lookup_interfaces.h"
#include "tensorflow/lite/kernels/kernel_util.h"
#include "tensorflow/lite/schema/schema_generated.h"

namespace tflite {
namespace ops {
namespace custom {
namespace hashtable {

static constexpr int kResourceHandleTensor = 0;
static constexpr const char kSharedNameStr[] = "shared_name";
static constexpr const char kKeyDtypeStr[] = "key_dtype";
static constexpr const char kValueDtypeStr[] = "value_dtype";

// TODO(b/144728911): The following structure should be moved to
// builtin_op_data.h when it is ready to become a builtin op.
typedef struct {
  std::string table_name;
  TfLiteType key_dtype;
  TfLiteType value_dtype;
} TfLiteHashtableParams;

void* InitHashtable(TfLiteContext* context, const char* buffer, size_t length) {
  TFLITE_CHECK(buffer != nullptr);

  const uint8_t* buffer_t = reinterpret_cast<const uint8_t*>(buffer);
  const flexbuffers::Map& m = flexbuffers::GetRoot(buffer_t, length).AsMap();
  const std::string table_name = m[kSharedNameStr].AsString().str();

  TfLiteType key_dtype, value_dtype;
  ConvertTensorType(static_cast<TensorType>(m[kKeyDtypeStr].AsInt32()),
                    &key_dtype, nullptr);
  ConvertTensorType(static_cast<TensorType>(m[kValueDtypeStr].AsInt32()),
                    &value_dtype, nullptr);

  TfLiteHashtableParams* option = new TfLiteHashtableParams;
  option->table_name = table_name;
  option->key_dtype = key_dtype;
  option->value_dtype = value_dtype;

  return option;
}

void FreeHashtable(TfLiteContext* context, void* buffer) {
  delete reinterpret_cast<TfLiteHashtableParams*>(buffer);
}

TfLiteStatus PrepareHashtable(TfLiteContext* context, TfLiteNode* node) {
  TF_LITE_ENSURE_EQ(context, NumInputs(node), 0);
  TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);

  TF_LITE_ENSURE(context, node->user_data != nullptr);
  const auto* params =
      reinterpret_cast<const TfLiteHashtableParams*>(node->user_data);

  TF_LITE_ENSURE(context, !params->table_name.empty());
  TF_LITE_ENSURE(context, (params->key_dtype == kTfLiteInt64 &&
                           params->value_dtype == kTfLiteString) ||
                              (params->key_dtype == kTfLiteString &&
                               params->value_dtype == kTfLiteInt64));

  TfLiteTensor* resource_handle_tensor =
      GetOutput(context, node, kResourceHandleTensor);
  TF_LITE_ENSURE(context, resource_handle_tensor != nullptr);
  TF_LITE_ENSURE_EQ(context, resource_handle_tensor->type, kTfLiteInt32);
  TfLiteIntArray* outputSize = TfLiteIntArrayCreate(1);
  outputSize->data[0] = 1;
  return context->ResizeTensor(context, resource_handle_tensor, outputSize);
}

TfLiteStatus EvalHashtable(TfLiteContext* context, TfLiteNode* node) {
  TF_LITE_ENSURE(context, node->user_data != nullptr);
  const auto* params =
      reinterpret_cast<const TfLiteHashtableParams*>(node->user_data);

  // The resource id is generated based on the given table name.
  const int resource_id = std::hash<std::string>{}(params->table_name);

  TfLiteTensor* resource_handle_tensor =
      GetOutput(context, node, kResourceHandleTensor);
  auto* resource_handle_data =
      GetTensorData<std::int32_t>(resource_handle_tensor);
  resource_handle_data[0] = resource_id;

  Subgraph* subgraph = reinterpret_cast<Subgraph*>(context->impl_);
  auto& resources = subgraph->resources();
  resource::CreateHashtableResourceIfNotAvailable(
      &resources, resource_id, params->key_dtype, params->value_dtype);
  return kTfLiteOk;
}

}  // namespace hashtable

TfLiteRegistration* Register_HASHTABLE() {
  static TfLiteRegistration r = {
      hashtable::InitHashtable, hashtable::FreeHashtable,
      hashtable::PrepareHashtable, hashtable::EvalHashtable};
  return &r;
}

}  // namespace custom
}  // namespace ops
}  // namespace tflite


text:
jscs-trailing-whitespace-in-source
==================================

[JSCS](https://github.com/mdevils/node-jscs) plugin to disallow trailing whitespace in source (but not in comments).

Installation
------------

**Using npm:** `npm install --save-dev jscs-trailing-whitespace-in-source`

**Manually:** Download [`rules/jscs-trailing-whitespace-in-source.js`](https://raw.githubusercontent.com/joelrbrandt/jscs-trailing-whitespace-in-source/master/rules/jscs-trailing-whitespace-in-source.js)

Usage
-----

1. Add the path `"node_modules/jscs-trailing-whitespace-in-source/rules/*.js"` to the `additionalRules` property in your JSCS config.
2. Set `disallowTrailingWhitespaceInSource` to `true` in your JSCS config

For example:

```json
{
    "additionalRules": [ "node_modules/jscs-trailing-whitespace-in-source/rules/*.js" ],
    "disallowTrailingWhitespaceInSource": true
}
```

Additionally, if you `requre` this package in node, you'll get an object with a single property named `rulePath` that contains the full path to the rules file.

License
-------

The MIT License (MIT)

Copyright (c) 2014 Ian Wehrman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.