<commit_before>/*
* This file is part of the sohva project.
*
* 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.
*/
package gnieh.sohva
package async

import dispatch._
import Defaults._

import com.ning.http.client._

import net.liftweb.json._

/** A CouchDB instance.
 *  Allows users to access the different databases and instance information.
 *  This is the key class to start with when one wants to work with couchdb.
 *  Through this one you will get access to the sessions and anonymous access
 *  to databases.
 *
 *  @author <NAME>
 *
 */
class CouchClient(val host: String = "localhost",
                  val port: Int = 5984,
                  val ssl: Boolean = false,
                  val version: String = "1.4",
                  val custom: List[SohvaSerializer[_]] = Nil) extends CouchDB with gnieh.sohva.CouchClient {

  val serializer = new JsonSerializer(this.version, custom)

  // check that the version matches the one of the server
  for {
    Right(i) <- info
    if i.version != version
  } {
    println("Warning Expected version is "  + version + " but actual server version is " + i.version)
  }

  def startSession =
    new CouchSession(this)

  def shutdown =
    _http.shutdown

  // ========== internals ==========

  protected[sohva] lazy val _http = Http.configure { builder =>
    builder.setFollowRedirects(true)
  }

  // the base request to this couch instance
  protected[sohva] def request =
    if (ssl)
      :/(host, port).secure
    else
      :/(host, port)

}<commit_msg>better client/server version comparison<commit_after>/*
* This file is part of the sohva project.
*
* 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.
*/
package gnieh.sohva
package async

import dispatch._
import Defaults._

import com.ning.http.client._

import net.liftweb.json._

import org.slf4j.LoggerFactory

/** A CouchDB instance.
 *  Allows users to access the different databases and instance information.
 *  This is the key class to start with when one wants to work with couchdb.
 *  Through this one you will get access to the sessions and anonymous access
 *  to databases.
 *
 *  @author <NAME>
 *
 */
class CouchClient(val host: String = "localhost",
                  val port: Int = 5984,
                  val ssl: Boolean = false,
                  val version: String = "1.4",
                  val custom: List[SohvaSerializer[_]] = Nil) extends CouchDB with gnieh.sohva.CouchClient {

  val serializer = new JsonSerializer(this.version, custom)

  // check that the version matches the one of the server
  for {
    Right(i) <- info
    if CouchVersion(i.version) != CouchVersion(version)
  } {
    LoggerFactory.getLogger(classOf[gnieh.sohva.CouchClient]).warn("Warning Expected version is "  + version + " but actual server version is " + i.version)
  }

  def startSession =
    new CouchSession(this)

  def shutdown =
    _http.shutdown

  // ========== internals ==========

  protected[sohva] lazy val _http = Http.configure { builder =>
    builder.setFollowRedirects(true)
  }

  // the base request to this couch instance
  protected[sohva] def request =
    if (ssl)
      :/(host, port).secure
    else
      :/(host, port)

}

private case class CouchVersion(raw: String) {

  val Array(major, minor, rest) = raw.split("\\.", 3)

  override def equals(other: Any): Boolean = other match {
    case that: CouchVersion =>
      this.major == that.major && this.minor == that.minor
    case _ =>
      false
  }

}

{'fraction_non_alphanumeric': 0.09662921348314607, 'fraction_numerical': 0.004943820224719101, 'mean_word_length': 3.053734061930783, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2142228', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1251, 'n_words': 498}