diff --git a/.gitignore b/.gitignore index 848218b..904f28d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,18 @@ .cache .classpath +.history .project .scala_dependencies .settings target .target -project/strap/sbt-launch-*.jar +*.~ + +sbt-launch-*.jar + +*.log +*.pyc + +code/scala/Lift/src/main/static/coffee-js/*.js +code/scala/Lift/src/main/static/less-css/*.css diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..dc1f27b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "shared"] + path = shared + url = git://github.com/element-doo/shared-static.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8a662a8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,26 @@ +Copyright (c) 2012, Instantor AB +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +3. Neither the name of the Instantor AB nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/README b/README index 150a412..5d97753 100644 --- a/README +++ b/README @@ -1,10 +1,9 @@ - FUZZY STRING MATCHING - + NAME COMPARISON PROJECT * FuzzyMatch.apply is a method for comparing 2 names, that uses Levenshtein algorithm. * The Levenshtein algorithm (also called Edit-Distance) calculates the - * least number of edit operations that are necessary to modify one string to obtain another string. + * least number of edit operations that are necessary to modify one string to become an another string. * * Method FuzzyMatch.apply returns 0 to 1 correlation between 2 names. * @@ -13,6 +12,9 @@ * 1. Transliterated * 2. Alphabetically sorted * 3. Converted to lowercase and trimmed for extra whitespaces - - - + * + * Additionally, specialised handlers have been created for special cases of names + * containing hyphens or names which have been shortened to initials. + * + * A live demo of this code is available on the Instantor sandbox server at: + * https://platform.instantor.com/sandbox/name-compare/ diff --git a/build.sbt b/build.sbt deleted file mode 100644 index 9f63c50..0000000 --- a/build.sbt +++ /dev/null @@ -1,35 +0,0 @@ -organization := "hr.element.etb" - -name := "etb-name_compare" - -version := "0.0.3" - - -// ### Build settings ### - -resolvers := Seq( - "Element Nexus" at "http://maven.element.hr/nexus/content/groups/public/" -, "Element Releases" at "http://maven.element.hr/nexus/content/repositories/releases/" -) - -resolvers := Seq("3rd party" at "http://maven.element.hr/nexus/content/repositories/thirdparty/") - -libraryDependencies += "com.ibm.icu" % "icu4j" % "49.1" - -libraryDependencies += "uk.ac.shef.wit" % "simmetrics" % "1.6.2" - -libraryDependencies += "org.scalatest" %% "scalatest" % "1.7.1" % "test" - - -scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "UTF-8", "-optimise") - -unmanagedSourceDirectories in Compile <<= (scalaSource in Compile)( _ :: Nil) - -unmanagedSourceDirectories in Test <<= (scalaSource in Test )( _ :: Nil) - -publishTo <<= resolvers { _.lastOption } - -credentials += Credentials(Path.userHome / ".publish" / "element.credentials") -// ### Misc ### - -//initialCommands := "import hr.element.doit.csv._" diff --git a/code/scala/Core/build.sbt b/code/scala/Core/build.sbt new file mode 100644 index 0000000..94f4797 --- /dev/null +++ b/code/scala/Core/build.sbt @@ -0,0 +1,40 @@ +name := "Name-Compare" + +version := "0.1.1-3" + +organization := "hr.element.etb" + +crossScalaVersions := Seq("2.10.4", "2.9.2", "2.9.1-1", "2.9.1", "2.9.0-1", "2.9.0") + +scalaVersion := crossScalaVersions.value.head + +scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "UTF-8", "-optimise") + +unmanagedSourceDirectories in Compile := Seq((scalaSource in Compile).value) + +unmanagedSourceDirectories in Test := Seq((scalaSource in Test).value) + +resolvers := Seq("Element Nexus" at "http://repo.element.hr/nexus/content/groups/public/") + +externalResolvers <<= resolvers map ( rs => + Resolver.withDefaultResolvers(rs, mavenCentral = false) +) + +libraryDependencies := Seq( + "com.ibm.icu" % "icu4j" % "49.1" +, "uk.ac.shef.wit" % "simmetrics" % "1.6.2" +, "org.scalatest" %% "scalatest" % "2.0" % "test" +) + +publishTo <<= (version) ( v => Some( + if (v endsWith "SNAPSHOT") { + "Element Snapshots" at "http://repo.element.hr/nexus/content/repositories/snapshots/" + } + else { + "Element Releases" at "http://repo.element.hr/nexus/content/repositories/releases/" + } +)) + +credentials += Credentials(Path.userHome / ".publish" / "element.credentials") + +publishArtifact in (Compile, packageDoc) := false diff --git a/code/scala/Core/continuous-compilation.bat b/code/scala/Core/continuous-compilation.bat new file mode 100644 index 0000000..d59e1e2 --- /dev/null +++ b/code/scala/Core/continuous-compilation.bat @@ -0,0 +1,4 @@ +@echo off + +echo Entering continuous compilation loop ... +call "%~dp0\sbt.bat" --loop --no-jrebel %* ~compile diff --git a/code/scala/Core/continuous-compilation.sh b/code/scala/Core/continuous-compilation.sh new file mode 100755 index 0000000..9144fde --- /dev/null +++ b/code/scala/Core/continuous-compilation.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo Entering continuous compilation loop ... +`dirname $0`/sbt.sh --loop --no-jrebel "$@" ~compile diff --git a/code/scala/Core/cross-publish.bat b/code/scala/Core/cross-publish.bat new file mode 100644 index 0000000..f37d924 --- /dev/null +++ b/code/scala/Core/cross-publish.bat @@ -0,0 +1,4 @@ +@echo off + +echo Will cross-publish project to the maven server +call "%~dp0sbt.bat" %* clean +publish diff --git a/code/scala/Core/cross-publish.sh b/code/scala/Core/cross-publish.sh new file mode 100755 index 0000000..dda7da7 --- /dev/null +++ b/code/scala/Core/cross-publish.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo Will cross-publish project to the maven server +`dirname $0`/sbt.sh --no-jrebel "$@" clean +publish diff --git a/code/scala/Core/open-console.bat b/code/scala/Core/open-console.bat new file mode 100644 index 0000000..33592ef --- /dev/null +++ b/code/scala/Core/open-console.bat @@ -0,0 +1,4 @@ +@echo off + +echo Firing up the Scala REPL ... +call "%~dp0\sbt.bat" %* console diff --git a/code/scala/Core/open-console.sh b/code/scala/Core/open-console.sh new file mode 100755 index 0000000..7f5b319 --- /dev/null +++ b/code/scala/Core/open-console.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo Firing up the Scala REPL ... +`dirname $0`/sbt.sh "$@" console diff --git a/code/scala/Core/prepare-workspace.bat b/code/scala/Core/prepare-workspace.bat new file mode 100644 index 0000000..ba8961d --- /dev/null +++ b/code/scala/Core/prepare-workspace.bat @@ -0,0 +1,5 @@ +@echo off + +echo Performing dependency update for all projects ... +echo Will also create Eclipse .project and .classpath files ... +call "%~dp0\sbt.bat" --no-jrebel %* update eclipse diff --git a/code/scala/Core/prepare-workspace.sh b/code/scala/Core/prepare-workspace.sh new file mode 100755 index 0000000..9c0fc26 --- /dev/null +++ b/code/scala/Core/prepare-workspace.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo Performing dependency update for all projects ... +echo Will also create Eclipse .project and .classpath files ... +`dirname $0`/sbt.sh --no-jrebel "$@" update eclipse diff --git a/code/scala/Core/project/build.properties b/code/scala/Core/project/build.properties new file mode 100644 index 0000000..be6c454 --- /dev/null +++ b/code/scala/Core/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.13.5 diff --git a/project/plugins.sbt b/code/scala/Core/project/plugins.sbt similarity index 57% rename from project/plugins.sbt rename to code/scala/Core/project/plugins.sbt index eb68023..49f8734 100644 --- a/project/plugins.sbt +++ b/code/scala/Core/project/plugins.sbt @@ -1,3 +1,12 @@ +resolvers := Seq( + "Element Nexus" at "http://repo.element.hr/nexus/content/groups/public/" +, Resolver.url("Element Nexus (Ivy)", url("http://repo.element.hr/nexus/content/groups/public/"))(Resolver.ivyStylePatterns) +) + +externalResolvers := Resolver.withDefaultResolvers(resolvers.value, mavenCentral = false) + +// ======================================================================================= + // +-------------------------------------------------------------------------------------+ // | SBT Eclipse (https://github.com/typesafehub/sbteclipse) | // | Creates .project and .classpath files for easy Eclipse project imports | @@ -6,17 +15,11 @@ // | See also: Scala IDE downloads (http://download.scala-ide.org/) | // +-------------------------------------------------------------------------------------+ -resolvers += Classpaths.typesafeResolver - -addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0") +addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0") // +-------------------------------------------------------------------------------------+ -// | SBT Scalariform (https://github.com/typesafehub/sbtscalariform) | -// | Performs source code formatting | -// | | -// | See also: Scalariform reference (http://mdr.github.com/scalariform/) | +// | Dependency graph SBT plugin (https://github.com/jrudolph/sbt-dependency-graph) | +// | Lists all library dependencies in a nicely formatted way for easy inspection. | // +-------------------------------------------------------------------------------------+ -resolvers += Classpaths.typesafeResolver - -addSbtPlugin("com.typesafe.sbtscalariform" % "sbtscalariform" % "0.3.0") +addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.4") diff --git a/code/scala/Core/project/strap/gruj_vs_sbt-launch-0.13.x.jar b/code/scala/Core/project/strap/gruj_vs_sbt-launch-0.13.x.jar new file mode 100644 index 0000000..41b992a Binary files /dev/null and b/code/scala/Core/project/strap/gruj_vs_sbt-launch-0.13.x.jar differ diff --git a/code/scala/Core/project/strap/sbt.boot.properties b/code/scala/Core/project/strap/sbt.boot.properties new file mode 100644 index 0000000..5741e2a --- /dev/null +++ b/code/scala/Core/project/strap/sbt.boot.properties @@ -0,0 +1,28 @@ +[scala] + version: ${sbt.scala.version-auto} + +[app] + org: ${sbt.organization-org.scala-sbt} + name: sbt + version: ${sbt.version-read(sbt.version)[0.13.5]} + class: ${sbt.main.class-sbt.xMain} + components: xsbti,extra + cross-versioned: ${sbt.cross.versioned-false} + resources: ${sbt.extraClasspath-} + +[repositories] + local + element-nexus: http://maven.element.hr/nexus/content/groups/public/ + element-nexus-ivy: http://maven.element.hr/nexus/content/groups/public/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext] + +[boot] + directory: ${sbt.boot.directory-${sbt.global.base-${user.home}/.sbt}/boot/} + +[ivy] + ivy-home: ${sbt.ivy.home-${user.home}/.ivy2/name-compare} + checksums: ${sbt.checksums-sha1,md5} + override-build-repos: ${sbt.override.build.repos-false} + repository-config: ${sbt.repository.config-${sbt.global.base-${user.home}/.sbt}/repositories} + +[log] + level: info diff --git a/code/scala/Core/sbt.bat b/code/scala/Core/sbt.bat new file mode 100644 index 0000000..5be811e --- /dev/null +++ b/code/scala/Core/sbt.bat @@ -0,0 +1,75 @@ +@echo off +setlocal +pushd +cd "%~dp0" + +set JVM_PARAMS=-Xss2m -Xmx712m -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled + +set LIFT_RUN_MODE=-Drun.mode=development +set TRY_JREBEL=true +set LOG_LEVEL= +set NO_PAUSE=false +set DO_LOOP=false + +:PARSER_LOOP +if "%~1"=="" goto :PARSER_END + +if "%~1"=="--prod" ( + set LIFT_RUN_MODE=-Drun.mode=production + goto :PARSER_CONTINUE +) + +if "%~1"=="--debug" ( + set LOG_LEVEL="set logLevel:=Level.Debug" + goto :PARSER_CONTINUE +) + +if "%~1"=="~lift" ( + set SBT_PARAMS=%SBT_PARAMS% container:start ~compile container:stop + set JREBEL_PLUGINS=%JREBEL_PLUGINS% -Drebel.lift_plugin=true + goto :PARSER_CONTINUE +) + +if "%~1"=="--no-jrebel" ( + set TRY_JREBEL=false + goto :PARSER_CONTINUE +) + +if "%~1"=="--loop" ( + set DO_LOOP=true + goto :PARSER_CONTINUE +) + +if "%~1"=="--no-pause" ( + set NO_PAUSE=true + goto :PARSER_CONTINUE +) + +set SBT_PARAMS=%SBT_PARAMS% %1 + +:PARSER_CONTINUE +shift +goto :PARSER_LOOP +:PARSER_END + +set JVM_PARAMS=%JVM_PARAMS% %LIFT_RUN_MODE% +if %TRY_JREBEL%.==true. ( + if exist "%JREBEL_HOME%\jrebel.jar" set JVM_PARAMS=%JVM_PARAMS% -noverify -javaagent:"%JREBEL_HOME%\jrebel.jar" %JREBEL_PLUGINS% +) + +set GRUJ_PATH=project\strap\gruj_vs_sbt-launch-0.13.x.jar +set RUN_CMD=java %JVM_PARAMS% -jar %GRUJ_PATH% %LOG_LEVEL% %SBT_PARAMS% + +:RUN_LOOP +%RUN_CMD% + +if %DO_LOOP%.==true. ( + if %NO_PAUSE%.==false. ( + echo Press Enter to continue or Press CTRL+C to exit! + pause + ) + goto :RUN_LOOP +) + +popd +endlocal diff --git a/sbt.sh b/code/scala/Core/sbt.sh similarity index 91% rename from sbt.sh rename to code/scala/Core/sbt.sh index 4b6f2c5..75479ef 100755 --- a/sbt.sh +++ b/code/scala/Core/sbt.sh @@ -2,7 +2,7 @@ cd `dirname $0` ## START JVM PARAMS -JVM_PARAMS="-Xss2m -Xmx1g -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled" +JVM_PARAMS="-Xss2m -Xmx712m -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled" LIFT_RUN_MODE="-Drun.mode=development" TRY_JREBEL=true @@ -51,7 +51,7 @@ if $TRY_JREBEL && [ -n "$JREBEL_HOME" ] && [ -f $JREBEL_HOME/jrebel.jar ]; then JVM_PARAMS="$JVM_PARAMS -noverify -javaagent:$JREBEL_HOME/jrebel.jar $JREBEL_PLUGINS" fi -GRUJ_PATH="project/strap/gruj_vs_sbt-launch-0.11.2.jar" +GRUJ_PATH="project/strap/gruj_vs_sbt-launch-0.13.x.jar" RUN_CMD="java $JVM_PARAMS -jar $GRUJ_PATH $LOG_LEVEL $SBT_PARAMS" LOOPING=true diff --git a/code/scala/Core/src/main/scala/hr/element/etb/name_compare/ComparisonDecision.scala b/code/scala/Core/src/main/scala/hr/element/etb/name_compare/ComparisonDecision.scala new file mode 100644 index 0000000..5b5858c --- /dev/null +++ b/code/scala/Core/src/main/scala/hr/element/etb/name_compare/ComparisonDecision.scala @@ -0,0 +1,32 @@ +package hr.element.etb.name_compare + +sealed abstract class ComparisonDecision( + val decision: String + , val isOk: Boolean + , val description: String + , val percentage: Float) { + + override val toString = "%s (%s: %.0f%%)" format( + decision + , description + , percentage * 100 + ) +} + +case object IdenticalMatch + extends ComparisonDecision("Yes", true, "Identical match", 1f) + +case class DirectMatch(override val percentage: Float) + extends ComparisonDecision("Yes", true, "There was a direct match", percentage) + +case class InitialsMatch(override val percentage: Float) + extends ComparisonDecision("Maybe", true, "There was a match via initials", percentage) + +case class HyphenMatch(override val percentage: Float) + extends ComparisonDecision("Maybe", true, "There was a match via hyphens", percentage) + +case class NoMatch(override val percentage: Float) + extends ComparisonDecision("No", false, "There was no match", percentage) + +case object MatchError + extends ComparisonDecision("No", false, "There was an error", 0f) diff --git a/code/scala/Core/src/main/scala/hr/element/etb/name_compare/Fuzzy.scala b/code/scala/Core/src/main/scala/hr/element/etb/name_compare/Fuzzy.scala new file mode 100644 index 0000000..490d0f3 --- /dev/null +++ b/code/scala/Core/src/main/scala/hr/element/etb/name_compare/Fuzzy.scala @@ -0,0 +1,51 @@ +package hr.element.etb.name_compare + +import com.ibm.icu.text.Transliterator + +object Fuzzy extends Fuzzy(true, true) { + private val ASCII = Transliterator.getInstance("Latin-ASCII") + + private val SplitPattern = """\s+"""r + private val Spacer = " " + + private val trimWhiteSpace = SplitPattern replaceAllIn (_: String, Spacer) + private val lowerCase = (_: String) toLowerCase + private val transliterate = ASCII transliterate (_: String) + + private def sortAsc(e1: String, e2: String) = (e1 compare e2) > 0 // ASC + private def sortWords(words: String) = words split Spacer sortWith sortAsc mkString Spacer + + private val passThru = (s: String) => s +} + +case class Fuzzy private( + transliteration: Boolean + , lowercasing: Boolean) { + + import Fuzzy._ + + def setTransliteration(transliteration: Boolean) = + copy(transliteration = transliteration) + + def setLowercasing(lowercasing: Boolean) = + copy(lowercasing = lowercasing) + + def lowerCaseAction = + if (lowercasing) lowerCase else passThru + + def transliterateAction = + if (transliteration) transliterate else passThru + + def apply(text: String) = + FuzzyString( + text + , (trimWhiteSpace andThen + lowerCaseAction andThen + transliterateAction andThen + sortWords)(text) + ) +} + +case class FuzzyString(original: String, processed: String) { + override val toString = processed +} diff --git a/code/scala/Core/src/main/scala/hr/element/etb/name_compare/NameCompare.scala b/code/scala/Core/src/main/scala/hr/element/etb/name_compare/NameCompare.scala new file mode 100644 index 0000000..eba2adf --- /dev/null +++ b/code/scala/Core/src/main/scala/hr/element/etb/name_compare/NameCompare.scala @@ -0,0 +1,124 @@ +package hr.element.etb.name_compare + +import uk.ac.shef.wit.simmetrics.similaritymetrics.Levenshtein + +object NameCompare extends NameCompare(true, true, 0.95f, 1f, 1f) + +case class NameCompare private( + transliteration: Boolean + , lowercasing: Boolean + , directThreshold: Float + , initialsThreshold: Float + , hyphenThreshold: Float) { + + def setTransliteration(transliteration: Boolean) = + copy(transliteration = transliteration) + + def setLowercasing(lowercasing: Boolean) = + copy(lowercasing = lowercasing) + + def setDirectThreshold(directThreshold: Float) = + copy(directThreshold = directThreshold) + + def setInitialsThreshold(initialsThreshold: Float) = + copy(initialsThreshold = initialsThreshold) + + def setHyphenThreshold(hyphenThreshold: Float) = + copy(hyphenThreshold = hyphenThreshold) + + lazy val fuzzy = Fuzzy + .setTransliteration(transliteration) + .setLowercasing(lowercasing) + + def apply(src: String, dst: String) = { + val c = Comparison(fuzzy(src), fuzzy(dst)) + c.result -> (c.src, c.dst) + } + +// ---------------------------------------------------------------------------- + + private case class Comparison( + src: FuzzyString + , dst: FuzzyString) { + + lazy val identical = + src.original == dst.original + + lazy val directPercentage = + new Levenshtein getSimilarity(src.processed, dst.processed) + + lazy val initialsPercentage = { + val _src = src.processed + val _dst = dst.processed + + val names = _src split " " toList + + names.map{ name => + val perms = (name.head + "." :: names.diff(List(name))).permutations toList + + perms.map{ p => + val permName = p mkString " " + new Levenshtein getSimilarity(permName, _dst) + }.max + }.max + } + + lazy val hyphenPercentage = { + val _src = src.processed + val _dst = dst.processed + + if(!_dst.contains('-')) + { + 0.0f + } + else + { + val names = _dst replace ('-', ' ') + val namesList = names split ' ' toList + + val combinations = + for{n <- 1 to namesList.length} yield (namesList.combinations(n)) toList + + val comb = (for{v <- combinations + n <-v} yield n) toList + + val res = comb.map{ combination => + val perms = combination.permutations toList + + perms.map{ p => + val permName = p mkString " " + new Levenshtein getSimilarity(_src, permName) + }.max + }.max + + val nWordsDst = namesList.length toFloat + val nWordsSrc = (_src split " ").length toFloat + + if(nWordsDst > nWordsSrc) + { + res*(nWordsSrc/nWordsDst) + } else + { + res*(nWordsDst/nWordsSrc) + } + } + } + + lazy val result = + if (identical) { + IdenticalMatch + } + else if (directPercentage >= directThreshold) { + DirectMatch(directPercentage) + } + else if (initialsPercentage >= initialsThreshold) { + InitialsMatch(initialsPercentage) + } + else if (hyphenPercentage >= hyphenThreshold) { + HyphenMatch(hyphenPercentage) + } + else { + NoMatch(directPercentage) + } + } +} diff --git a/src/test/scala/hr/element/etb/name_compare/FuzzyStringTest.scala b/code/scala/Core/src/test/scala/hr/element/etb/name_compare/api/FuzzyStringTest.scala similarity index 93% rename from src/test/scala/hr/element/etb/name_compare/FuzzyStringTest.scala rename to code/scala/Core/src/test/scala/hr/element/etb/name_compare/api/FuzzyStringTest.scala index afea42f..03ab6ef 100644 --- a/src/test/scala/hr/element/etb/name_compare/FuzzyStringTest.scala +++ b/code/scala/Core/src/test/scala/hr/element/etb/name_compare/api/FuzzyStringTest.scala @@ -1,10 +1,9 @@ -package hr.element.etb -package name_compare +package hr.element.etb.name_compare.test +import hr.element.etb.name_compare.NameCompare -import org.scalatest.matchers.MustMatchers -import org.scalatest.FeatureSpec -import org.scalatest.GivenWhenThen +/* +import org.scalatest._ class FuzzyStringTest extends FeatureSpec with GivenWhenThen with MustMatchers{ @@ -67,4 +66,5 @@ class FuzzyStringTest extends FeatureSpec with GivenWhenThen with MustMatchers{ res1 must equal (res2) } } -} \ No newline at end of file +} +*/ diff --git a/code/scala/Lift/build.sbt b/code/scala/Lift/build.sbt new file mode 100644 index 0000000..269b3dc --- /dev/null +++ b/code/scala/Lift/build.sbt @@ -0,0 +1,52 @@ +name := "Name-Compare-Web" + +organization := "com.instantor.ip.sandbox" + +scalaVersion := "2.9.1" + +scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "UTF-8", "-optimise") + +unmanagedSourceDirectories in Compile <<= (scalaSource in Compile)(_ :: Nil) + +unmanagedSourceDirectories in Test := Nil + +resolvers := Seq("Instantor Nexus" at "http://www.instantor.com/nexus/content/groups/public/") + +externalResolvers <<= resolvers map ( rs => + Resolver.withDefaultResolvers(rs, mavenCentral = false, scalaTools = false) +) + +libraryDependencies := Seq( + "hr.element.etb" %% "name-compare" % "0.1.1-3" +, "org.joda" % "joda-convert" % "1.2" +, "joda-time" % "joda-time" % "2.1" +, "org.scala-tools.time" %% "time" % "0.5" +, "org.eclipse.jetty" % "jetty-webapp" % "7.6.5.v20120716" % "container" +, "org.eclipse.jetty.orbit" % "javax.servlet" % "2.5.0.v201103041518" % "container" artifacts Artifact("javax.servlet", "jar", "jar") +, "net.liftweb" %% "lift-webkit" % "2.4" +, "hr.element.etb" %% "etb-util" % "0.2.16" +, "hr.element.etb" %% "etb-lift" % "0.0.21" +, "ch.qos.logback" % "logback-classic" % "1.0.6" +, "com.github.scala-incubator.io" %% "scala-io-file" % "0.4.0" +, "org.scalatest" %% "scalatest" % "2.0.M2" % "test" +) + +seq(webSettings: _*) + +scanDirectories in Compile := Nil + +port in container.Configuration := 9633 + +artifactName in packageWar := ((_: String, _: ModuleID, _: Artifact) => "ip-sandbox-name-compare.war") + +seq(coffeeSettings: _*) + +resourceManaged in (Compile, CoffeeKeys.coffee) <<= (com.github.siasia.PluginKeys.webappResources in Compile)(_.get.head / ".." / "static" / "coffee-js") + +seq(lessSettings: _*) + +LessKeys.mini in (Compile, LessKeys.less) := true + +resourceManaged in (Compile, LessKeys.less) <<= (webappResources in Compile)(_.get.head / ".." / "static" / "less-css") + +seq(dependencyReportSettings: _*) diff --git a/code/scala/Lift/continuous-compilation.bat b/code/scala/Lift/continuous-compilation.bat new file mode 100644 index 0000000..d59e1e2 --- /dev/null +++ b/code/scala/Lift/continuous-compilation.bat @@ -0,0 +1,4 @@ +@echo off + +echo Entering continuous compilation loop ... +call "%~dp0\sbt.bat" --loop --no-jrebel %* ~compile diff --git a/code/scala/Lift/continuous-compilation.sh b/code/scala/Lift/continuous-compilation.sh new file mode 100755 index 0000000..9144fde --- /dev/null +++ b/code/scala/Lift/continuous-compilation.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo Entering continuous compilation loop ... +`dirname $0`/sbt.sh --loop --no-jrebel "$@" ~compile diff --git a/code/scala/Lift/fabfile.py b/code/scala/Lift/fabfile.py new file mode 100644 index 0000000..72d0d53 --- /dev/null +++ b/code/scala/Lift/fabfile.py @@ -0,0 +1,77 @@ +from fabric.api import * +from fabric.operations import sudo +from fabric.contrib.files import exists +from fabric.contrib.console import confirm + +import os +from os.path import abspath + +import sys +import socket + +from fabrils.shared import * +from fabrils.lift import lift_base +from fabrils.production import * +from fabrils.projects import PROJECTS, delete_old, add_jetty_xml, remove_jetty_xml, prepare_logback, revert_logback, package_project, upload + + +from fabric.colors import red + +env.hosts = ['root@deedee@instantor.com'] + +def set_ws(host): + env.hosts = [host] + +ws = { +'kanta' : lambda: set_ws('root@localhost') +,'prod' : lambda: set_ws('root@deedee.instantor.com') +} + +## check for hostname +if (socket.gethostname() == 'kanta'): + if confirm(red("DEPLOY ON PRODUCTION?")): + ws.get('prod')() + else: + ws.get('kanta')() + print(red('Deploying on LOCALHOST instead....')) + +def clean(): + local('./sbt.sh --no-jrebel "clean"') + +def prepare_deploy(project): + delete_old() + add_jetty_xml(project) + prepare_logback(project) + package_project(project) + remove_jetty_xml(project) + revert_logback(project) + + + +def deploy(project = "", restart=False): + ## if no project is specified deploy all of them + if project == "": + for p in PROJECTS: + print(p) + prepare_deploy(p) + if confirm(red("Do you wish to proceed?")): + upload(p) + + deploy_shared_static() + # Restart jetty + if confirm(red("Do you wish to restart jetty?")): + sudo('service jetty restart') + + else: + ## deploy only the specified project + print(project) + prepare_deploy(project) + if confirm(("Do you wish to proceed?")): + upload(project) + deploy_shared_static() + + + # Restart jetty + if confirm(red("Do you wish to restart jetty?")): + sudo('service jetty restart') + diff --git a/code/scala/Lift/fabrils/__init__.py b/code/scala/Lift/fabrils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code/scala/Lift/fabrils/lift.py b/code/scala/Lift/fabrils/lift.py new file mode 100644 index 0000000..282edf0 --- /dev/null +++ b/code/scala/Lift/fabrils/lift.py @@ -0,0 +1,33 @@ +import os +from os.path import abspath + +from fabric.api import * +from fabric.contrib.files import exists + +from production import * + +## IKC Lift conf +lift_base = abspath('.') + '/' +lift_target = lift_base + 'Lift/target/scala-2.9.1/' +lift_war = lift_target + 'ip-sandbox-name-compare.war' + +lift_static = lift_base + 'Lift/src/main/static/' +lift_static_dir = static_dir+'namecompare-static' +lift_static_archive_name = 'ncstatic.zip' +lift_static_archive = lift_base + lift_static_archive_name + +lift_webinf_dir = lift_base + "Lift/src/main/webapp/WEB-INF/" +lift_jettyxml = lift_base + "Lift/src/main/resources/jetty/jetty-web.xml" + +lift_logback_dir = lift_base + "Lift/src/main/resources/" +lift_logback = lift_base + "Lift/src/main/resources/jetty/logback.xml" + +def deploy_nc_static(): + #zip/put/unzip/clean ikc static files + local('cd %s && zip -r %s . && cd %s' % (lift_static, lift_static_archive, lift_base)) + put(lift_static_archive, static_dir) + local('rm ' + lift_static_archive) + if exists(lift_static_dir): + run('rm -r ' + lift_static_dir) + run('unzip %s%s -d %s' % (static_dir, lift_static_archive_name, lift_static_dir)) + run('rm %s%s' % (static_dir,lift_static_archive_name)) diff --git a/code/scala/Lift/fabrils/production.py b/code/scala/Lift/fabrils/production.py new file mode 100644 index 0000000..a551f69 --- /dev/null +++ b/code/scala/Lift/fabrils/production.py @@ -0,0 +1,4 @@ +## PRODUCTION conf +webapps_dir = '/opt/jetty/webapps/' +static_dir = '/var/www/ip/nc/' +shared_static_dir = static_dir + 'shared' diff --git a/code/scala/Lift/fabrils/projects.py b/code/scala/Lift/fabrils/projects.py new file mode 100644 index 0000000..a61b311 --- /dev/null +++ b/code/scala/Lift/fabrils/projects.py @@ -0,0 +1,77 @@ +from fabric.api import * +import os + +from lift import * +from production import * + +PROJECTS = ['lift',] + + +oldwar = { +'lift' : lambda : os.path.exists(lift_war) and local('rm %s' % lift_war) +} + +def delete_old(): + for p in PROJECTS: + oldwar.get(p)() + + + +## jetty-web.xml - for setting run mode to production +jettyxmladd = { +'lift' : lambda: local('cp %s %s' % (lift_jettyxml, lift_webinf_dir)) +} + +jettyxmlremove = { +'lift' : lambda: local('rm %sjetty-web.xml' % lift_webinf_dir) +} + +def add_jetty_xml(project): + jettyxmladd.get(project)() + +def remove_jetty_xml(project): + jettyxmlremove.get(project)() + +## END jetty-web.xml + +## set logback +logbackset = { +'lift' : lambda : local('cp %s %s' % (lift_logback, lift_logback_dir)) +} + +logbackrevert = { +'lift' : lambda : local('git checkout -- %slogback.xml' % lift_logback_dir) +} + +def prepare_logback(project): + logbackset.get(project)() + +def revert_logback(project): + logbackrevert.get(project)() +## END logback + + +## package war +package = { +'lift' : lambda : local('Lift/package-war.sh') +} + +def package_project(project): + package.get(project)() +## END package war + +## Upload +uploadwar = { +'lift' : lambda : put(lift_war, webapps_dir) +} + +uploadstatic = { +'lift' : lambda : deploy_nc_static() +} + +def upload(project): + uploadwar.get(project)() + uploadstatic.get(project)() + + +## END upload diff --git a/code/scala/Lift/fabrils/shared.py b/code/scala/Lift/fabrils/shared.py new file mode 100644 index 0000000..3d21a0b --- /dev/null +++ b/code/scala/Lift/fabrils/shared.py @@ -0,0 +1,24 @@ +import os +from os.path import abspath + +from fabric.api import * +from fabric.contrib.files import exists + +from production import * + +# SHARED STATIC resources +shared_base = abspath('.') + '/' +shared_static = shared_base + '../../shared/' +shared_static_archive_name = 'shared-static.zip' +shared_static_archive = shared_base + shared_static_archive_name + +def deploy_shared_static(): + #zip/put/unzip/clean shared-static + local('cd %s && zip -r %s . -x *.git* && cd %s' % (shared_static, shared_static_archive, shared_base)) + put(shared_static_archive, static_dir) + local('rm ' + shared_static_archive) + if exists(shared_static_dir): + run('rm -r ' + shared_static_dir) + run('unzip %s%s -d %s' % (static_dir, shared_static_archive_name, shared_static_dir)) + run('rm %s%s' % (static_dir,shared_static_archive_name)) + diff --git a/code/scala/Lift/jetty-run.bat b/code/scala/Lift/jetty-run.bat new file mode 100644 index 0000000..25ee1f6 --- /dev/null +++ b/code/scala/Lift/jetty-run.bat @@ -0,0 +1,4 @@ +@echo off + +echo Starting Lift, firing up Jetty ... +call "%~dp0\sbt.bat" --loop %* ~lift diff --git a/code/scala/Lift/jetty-run.sh b/code/scala/Lift/jetty-run.sh new file mode 100755 index 0000000..7e05718 --- /dev/null +++ b/code/scala/Lift/jetty-run.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo Starting Lift, firing up Jetty ... +`dirname $0`/sbt.sh --loop "$@" ~lift diff --git a/code/scala/Lift/open-console.bat b/code/scala/Lift/open-console.bat new file mode 100644 index 0000000..33592ef --- /dev/null +++ b/code/scala/Lift/open-console.bat @@ -0,0 +1,4 @@ +@echo off + +echo Firing up the Scala REPL ... +call "%~dp0\sbt.bat" %* console diff --git a/code/scala/Lift/open-console.sh b/code/scala/Lift/open-console.sh new file mode 100755 index 0000000..7f5b319 --- /dev/null +++ b/code/scala/Lift/open-console.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo Firing up the Scala REPL ... +`dirname $0`/sbt.sh "$@" console diff --git a/code/scala/Lift/package-war.bat b/code/scala/Lift/package-war.bat new file mode 100644 index 0000000..e10a145 --- /dev/null +++ b/code/scala/Lift/package-war.bat @@ -0,0 +1,4 @@ +@echo off + +echo Packaging the WAR file ... +call "%~dp0\sbt.bat" --no-jrebel %* package-war diff --git a/code/scala/Lift/package-war.sh b/code/scala/Lift/package-war.sh new file mode 100755 index 0000000..77d30e9 --- /dev/null +++ b/code/scala/Lift/package-war.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo Packaging the WAR file ... +`dirname $0`/sbt.sh --no-jrebel "$@" package-war diff --git a/code/scala/Lift/prepare-workspace.bat b/code/scala/Lift/prepare-workspace.bat new file mode 100644 index 0000000..ba8961d --- /dev/null +++ b/code/scala/Lift/prepare-workspace.bat @@ -0,0 +1,5 @@ +@echo off + +echo Performing dependency update for all projects ... +echo Will also create Eclipse .project and .classpath files ... +call "%~dp0\sbt.bat" --no-jrebel %* update eclipse diff --git a/code/scala/Lift/prepare-workspace.sh b/code/scala/Lift/prepare-workspace.sh new file mode 100755 index 0000000..9c0fc26 --- /dev/null +++ b/code/scala/Lift/prepare-workspace.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo Performing dependency update for all projects ... +echo Will also create Eclipse .project and .classpath files ... +`dirname $0`/sbt.sh --no-jrebel "$@" update eclipse diff --git a/code/scala/Lift/project/plugins.sbt b/code/scala/Lift/project/plugins.sbt new file mode 100644 index 0000000..56ae64a --- /dev/null +++ b/code/scala/Lift/project/plugins.sbt @@ -0,0 +1,53 @@ +resolvers := Seq( + "Instantor Nexus" at "http://www.instantor.com/nexus/content/groups/public/" +, Resolver.url("Instantor Nexus (Ivy)", + new URL("http://www.instantor.com/nexus/content/groups/public/"))(Resolver.ivyStylePatterns) +) + +externalResolvers <<= resolvers map { rs => + Resolver.withDefaultResolvers(rs, mavenCentral = false, scalaTools = false) +} + +// ======================================================================================= + +// +-------------------------------------------------------------------------------------+ +// | SBT Eclipse (https://github.com/typesafehub/sbteclipse) | +// | Creates .project and .classpath files for easy Eclipse project imports | +// | | +// | See also: Eclipse downloads (http://www.eclipse.org/downloads/) | +// | See also: Scala IDE downloads (http://download.scala-ide.org/) | +// +-------------------------------------------------------------------------------------+ + +addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0") + + // +-------------------------------------------------------------------------------------+ +// | XSBT Web plugin (https://github.com/siasia/xsbt-web-plugin) | +// | Implements SBT 0.7.x Web project actions: "jetty-run" -> "container:start", etc ... | +// +-------------------------------------------------------------------------------------+ + +libraryDependencies <+= sbtVersion(v => "com.github.siasia" %% "xsbt-web-plugin" % (v+"-0.2.11.1")) + +// +-------------------------------------------------------------------------------------+ +// | CoffeeScripted SBT (https://github.com/softprops/coffeescripted-sbt) | +// | Automates "compilation" of coffeescript files (/src/main/*.coffee) into javascript | +// | | +// | See also: Coffeescript reference (http://jashkenas.github.com/coffee-script/) | +// +-------------------------------------------------------------------------------------+ + +addSbtPlugin("me.lessis" % "coffeescripted-sbt" % "0.2.3") + +// +-------------------------------------------------------------------------------------+ +// | Less SBT (https://github.com/softprops/less-sbt) | +// | Automates "compilation" of less files (/src/main/*.less) into css | +// | | +// | See also: LESS reference (http://lesscss.org/) | +// +-------------------------------------------------------------------------------------+ + +addSbtPlugin("me.lessis" % "less-sbt" % "0.1.10") + +// +-------------------------------------------------------------------------------------+ +// | Dependency report plugin (hhttps://github.com/mslinn/dependencyReport) | +// | Lists all jars in a nicely formatted way for easy inspection. | +// +-------------------------------------------------------------------------------------+ + +addSbtPlugin("com.micronautics" % "dependencyreport" % "0.1.0") diff --git a/project/strap/gruj_vs_sbt-launch-0.11.2.jar b/code/scala/Lift/project/strap/gruj_vs_sbt-launch-0.11.3.jar similarity index 89% rename from project/strap/gruj_vs_sbt-launch-0.11.2.jar rename to code/scala/Lift/project/strap/gruj_vs_sbt-launch-0.11.3.jar index d15705c..24595fa 100644 Binary files a/project/strap/gruj_vs_sbt-launch-0.11.2.jar and b/code/scala/Lift/project/strap/gruj_vs_sbt-launch-0.11.3.jar differ diff --git a/code/scala/Lift/project/strap/sbt.boot.properties b/code/scala/Lift/project/strap/sbt.boot.properties new file mode 100644 index 0000000..c285489 --- /dev/null +++ b/code/scala/Lift/project/strap/sbt.boot.properties @@ -0,0 +1,25 @@ +[scala] + version: 2.9.1 + +[app] + org: ${sbt.organization-org.scala-sbt} + name: sbt + version: ${sbt.version-read(sbt.version)[0.11.3]} + class: ${sbt.main.class-sbt.xMain} + components: xsbti,extra + cross-versioned: ${sbt.cross.versioned-true} + +[repositories] + local + instantor-nexus: http://www.instantor.com/nexus/content/groups/public/ + instantor-nexus-ivy: http://www.instantor.com/nexus/content/groups/public/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext] + +[boot] + directory: ../../../../.sbt/name-compare + +[ivy] + ivy-home: ../../../../.ivy2/name-compare + checksums: ${sbt.checksums-sha1,md5} + +[log] + level: info diff --git a/code/scala/Lift/sbt.bat b/code/scala/Lift/sbt.bat new file mode 100644 index 0000000..2677dea --- /dev/null +++ b/code/scala/Lift/sbt.bat @@ -0,0 +1,75 @@ +@echo off +setlocal +pushd +cd "%~dp0" + +set JVM_PARAMS=-Xss2m -Xmx712m -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled + +set LIFT_RUN_MODE=-Drun.mode=development +set TRY_JREBEL=true +set LOG_LEVEL= +set NO_PAUSE=false +set DO_LOOP=false + +:PARSER_LOOP +if "%~1"=="" goto :PARSER_END + +if "%~1"=="--prod" ( + set LIFT_RUN_MODE=-Drun.mode=production + goto :PARSER_CONTINUE +) + +if "%~1"=="--debug" ( + set LOG_LEVEL="set logLevel:=Level.Debug" + goto :PARSER_CONTINUE +) + +if "%~1"=="~lift" ( + set SBT_PARAMS=%SBT_PARAMS% container:start ~compile container:stop + set JREBEL_PLUGINS=%JREBEL_PLUGINS% -Drebel.lift_plugin=true + goto :PARSER_CONTINUE +) + +if "%~1"=="--no-jrebel" ( + set TRY_JREBEL=false + goto :PARSER_CONTINUE +) + +if "%~1"=="--loop" ( + set DO_LOOP=true + goto :PARSER_CONTINUE +) + +if "%~1"=="--no-pause" ( + set NO_PAUSE=true + goto :PARSER_CONTINUE +) + +set SBT_PARAMS=%SBT_PARAMS% %1 + +:PARSER_CONTINUE +shift +goto :PARSER_LOOP +:PARSER_END + +set JVM_PARAMS=%JVM_PARAMS% %LIFT_RUN_MODE% +if %TRY_JREBEL%.==true. ( + if exist "%JREBEL_HOME%\jrebel.jar" set JVM_PARAMS=%JVM_PARAMS% -noverify -javaagent:"%JREBEL_HOME%\jrebel.jar" %JREBEL_PLUGINS% +) + +set GRUJ_PATH=project\strap\gruj_vs_sbt-launch-0.11.3.jar +set RUN_CMD=java %JVM_PARAMS% -jar %GRUJ_PATH% %LOG_LEVEL% %SBT_PARAMS% + +:RUN_LOOP +%RUN_CMD% + +if %DO_LOOP%.==true. ( + if %NO_PAUSE%.==false. ( + echo Press Enter to continue or Press CTRL+C to exit! + pause + ) + goto :RUN_LOOP +) + +popd +endlocal diff --git a/code/scala/Lift/sbt.sh b/code/scala/Lift/sbt.sh new file mode 100755 index 0000000..807b6c8 --- /dev/null +++ b/code/scala/Lift/sbt.sh @@ -0,0 +1,70 @@ +#!/bin/bash +cd `dirname $0` + +## START JVM PARAMS +JVM_PARAMS="-Xss2m -Xmx712m -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled" + +LIFT_RUN_MODE="-Drun.mode=development" +TRY_JREBEL=true +LOG_LEVEL= +NO_PAUSE=false +DO_LOOP=false + +while [ -n "$*" ] +do + case "$1" in + "--debug") + echo "Setting debug mode" + LOG_LEVEL="\"set logLevel:=Level.Debug\"" + ;; + "--prod") + echo "Set Lift mode to Production" + LIFT_RUN_MODE="-Drun.mode=production" + ;; + "~lift") + echo "Firing up Jetty ..." + SBT_PARAMS="$SBT_PARAMS container:start ~compile container:stop" + JREBEL_PLUGINS="$JREBEL_PLUGINS -Drebel.lift_plugin=true" + ;; + "--no-jrebel") + echo "Disabling JRebel for faster compilation" + TRY_JREBEL=false + ;; + "--loop") + echo "Will run SBT in loop mode" + DO_LOOP=true + ;; + "--no-pause") + echo "Will not pause in loop mode" + NO_PAUSE=true + ;; + *) + SBT_PARAMS="$SBT_PARAMS \"$1\"" + ;; + esac + shift + +done + +JVM_PARAMS="$JVM_PARAMS $LIFT_RUN_MODE" +if $TRY_JREBEL && [ -n "$JREBEL_HOME" ] && [ -f $JREBEL_HOME/jrebel.jar ]; then + JVM_PARAMS="$JVM_PARAMS -noverify -javaagent:$JREBEL_HOME/jrebel.jar $JREBEL_PLUGINS" +fi + +GRUJ_PATH="project/strap/gruj_vs_sbt-launch-0.11.3.jar" +RUN_CMD="java $JVM_PARAMS -jar $GRUJ_PATH $LOG_LEVEL $SBT_PARAMS" + +LOOPING=true +while $LOOPING +do + eval "$RUN_CMD" + + if ! $DO_LOOP ; then + LOOPING=false + else + if ! $NO_PAUSE ; then + echo "Press Enter to continue or Press CTRL+C to exit!" + read + fi + fi +done diff --git a/code/scala/Lift/src/main/coffee/name-compare.coffee b/code/scala/Lift/src/main/coffee/name-compare.coffee new file mode 100644 index 0000000..c361dee --- /dev/null +++ b/code/scala/Lift/src/main/coffee/name-compare.coffee @@ -0,0 +1,95 @@ +$ -> + formRoot = $('#name-compare') + + formRoot.find('button.submit').click (e) -> + responseField = $('#response .results') + responseField.find('.status').html 'Working…' + + t = $('#transliteration').is(':checked') + l = $('#lowercasing').is(':checked') + dT = parseFloat($('#directThreshold').val()) + iT = parseFloat($('#initialsThreshold').val()) + hT = parseFloat($('#hyphenThreshold').val()) + n = $('#names').val() + + if isNaN(dT) || dT < 0 + dT = 0 + else if dT > 100 + dT = 100 + + if isNaN(iT) || iT < 0 + iT = 0 + else if iT > 100 + iT = 100 + + if isNaN(hT) || hT < 0 + hT = 0 + else if hT > 100 + hT = 100 + + $('#directThreshold').val(dT) + $('#initialsThreshold').val(iT) + $('#hyphenThreshold').val(hT) + + $.ajax + type: 'post' + url: '/sandbox/name-compare/api' + + contentType: 'application/json; charset=utf-8' + dataType: 'json' + + data: + JSON.stringify + transliteration: t + lowercasing: l + directThreshold: dT / 100 + initialsThreshold: iT / 100 + hyphenThreshold: hT / 100 + names: n + + success: (response) -> + responseField.find('.status').text '' + + table = responseField.find 'table tbody' + list = responseField.find 'textarea' + + table.html '' + list.html '' + + i = 1 + for row in response + c = row.comparisonDecision + status = if c.decision is 'Yes' then 'label-success' else if c.decision is 'No' then 'label-important' else 'label-warning' + decision = "#{c.decision}" + perc = (c.percentage * 100).toFixed 2 + desc = c.description + + sO = row.src.original + sP = row.src.processed + dO = row.dst.original + dP = row.dst.processed + + table.append "#{i}#{sO}#{dO}#{desc}#{perc}%#{decision}" + list.append "#{sO}\t#{sP}\t#{dO}\t#{dP}\t#{c.decision}\t#{desc}\t#{perc}%\r\n" + i++ + + responseField.find('table').show() + list.attr 'rows', response.length+1 + + $('#response .js-data-toggler').show() + return + + error: (response) -> + responseField.find('.status').removeClass('muted').html 'Error '+response.status+': '+response.statusText+'' + return + false + + $('#response .js-data-toggler a').click -> + $(@).parents('ul').children('li').removeClass 'active' + $(@).parent().addClass 'active' + target = $(@).attr 'href' + $('#response .js-resultlist').hide() + $(target).show() + false + + return diff --git a/code/scala/Lift/src/main/less/name-compare.less b/code/scala/Lift/src/main/less/name-compare.less new file mode 100644 index 0000000..209b4ea --- /dev/null +++ b/code/scala/Lift/src/main/less/name-compare.less @@ -0,0 +1,38 @@ +/* Twotter Bootstrap 2.0.4 */ +// Main Bootstrap loader + +@import '../../../../../../shared/bootstrap/2.0.4/bootstrap.less'; + +// Platform-general styling +@import '../../../../../../shared/bootstrap/platform/platform.less'; + +@baseColor: @orange; // Set a base color +@import '../../../../../../shared/bootstrap/color.less'; + + +/* ========================================================================== */ +/* ===== Name compare LESS ============================================== */ +/* ========================================================================== */ + +/* ----- tha workz ---------------------------------------------------------- */ + +body { + background-color: @white; + background-repeat: repeat; + background-position: left center; + .background-source('textures/groovepaper.png'); + //#gradient.vertical(@white, @grayLighter); +} + +.hidden { display: none; } + +.spinner { + background-image: url('@{resourcesPath}images/loader-t.gif'); + background-repeat: no-repeat; + background-position: right center; + padding-right: 22px; +} + + + + diff --git a/code/scala/Lift/src/main/resources/jetty/jetty-web.xml b/code/scala/Lift/src/main/resources/jetty/jetty-web.xml new file mode 100644 index 0000000..0e844a6 --- /dev/null +++ b/code/scala/Lift/src/main/resources/jetty/jetty-web.xml @@ -0,0 +1,8 @@ + + + + + run.mode + production + + diff --git a/code/scala/Lift/src/main/resources/jetty/logback.xml b/code/scala/Lift/src/main/resources/jetty/logback.xml new file mode 100644 index 0000000..ae5d6b9 --- /dev/null +++ b/code/scala/Lift/src/main/resources/jetty/logback.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + [%4p] [%d{HH:mm:ss}] [%t] %c{36}: %m%n + + + + /var/log/jetty/namecompare.log + + [%d{HH:mm:ss}] [%4p] [%t] %c{36}: %m%n + + + /var/log/jetty/namecompare-%d{yyyy-MM-dd-HH}.log + + + + + + + + + diff --git a/code/scala/Lift/src/main/resources/logback.xml b/code/scala/Lift/src/main/resources/logback.xml new file mode 100644 index 0000000..d78c313 --- /dev/null +++ b/code/scala/Lift/src/main/resources/logback.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + [%4p] [%d{HH:mm:ss}] [%t] %c{36}: %m%n + + + + /var/log/jetty/namedcompare.log + + [%d{HH:mm:ss}] [%4p] [%t] %c{36}: %m%n + + + /var/log/jetty/namedcompare-%d{yyyy-MM-dd-HH}.log + + + + + + + + + diff --git a/code/scala/Lift/src/main/resources/names.txt b/code/scala/Lift/src/main/resources/names.txt new file mode 100644 index 0000000..dab69d3 --- /dev/null +++ b/code/scala/Lift/src/main/resources/names.txt @@ -0,0 +1,60 @@ +Hans Müller, --- --- +Hans Müller, H. M. +Hans Müller, H. Meier +Hans Müller, H. Müller +Hans Müller, H. Müller-Meier +Hans Müller, Hans M. +Hans Müller, Hans Meier +Hans Müller, Hans Müller +Hans Müller, Hans Müller-Meier +Hans Müller, Hans-Jörg Meier +Hans Müller, Hans-Jörg Müller +Hans Müller, Hans-Jörg Müller-Meier +Hans Müller, K. M. +Hans Müller, K. Meier +Hans Müller, K. Müller +Hans Müller, K. Müller-Meier +Hans Müller, Klaus Meier +Hans Müller, Klaus Müller +Hans Müller, Klaus Müller-Meier +Hans Müller, Klaus-Hans Meier +Hans Müller, Klaus-Hans Müller +Hans Müller, Klaus-Hans Müller-Meier +Hans Müller, Paula Meier +Hans Müller, Paula Müller +Hans Müller, Paula Müller-Meier +Hans Müller Meier, H. M. Meier +Hans Müller Meier, H. Muller Meier +Hans Müller Meier, Muller Meier H. +Hans Müller Meier, Muller Meier Hans +Hans Müller Meier, Muller Meier K. +Hans Müller, --- --- +Hans Muller, H. M. +Hans Muller, H. Meier +Hans Muller, H. Müller +Hans Muller, H. Müller-Meier +Hans Muller, Hans M. +Hans Muller, Hans Meier +Hans Muller, Hans Müller +Hans Muller, Hans Müller-Meier +Hans Muller, Hans-Jörg Meier +Hans Muller, Hans-Jörg Müller +Hans Muller, Hans-Jörg Müller-Meier +Hans Muller, K. M. +Hans Muller, K. Meier +Hans Muller, K. Müller +Hans Muller, K. Müller-Meier +Hans Muller, Klaus Meier +Hans Muller, Klaus Müller +Hans Muller, Klaus Müller-Meier +Hans Muller, Klaus-Hans Meier +Hans Muller, Klaus-Hans Müller +Hans Muller, Klaus-Hans Müller-Meier +Hans Muller, Paula Meier +Hans Muller, Paula Müller +Hans Muller, Paula Müller-Meier +Hans Muller Meier, H. M. Meier +Hans Muller Meier, H. Muller Meier +Hans Muller Meier, Muller Meier H. +Hans Muller Meier, Muller Meier Hans +Hans Muller Meier, Muller Meier K. diff --git a/code/scala/Lift/src/main/resources/props/default.props b/code/scala/Lift/src/main/resources/props/default.props new file mode 100644 index 0000000..e69de29 diff --git a/code/scala/Lift/src/main/resources/props/production.default.props b/code/scala/Lift/src/main/resources/props/production.default.props new file mode 100644 index 0000000..e69de29 diff --git a/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/Boot.scala b/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/Boot.scala new file mode 100644 index 0000000..35b36cd --- /dev/null +++ b/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/Boot.scala @@ -0,0 +1,33 @@ +package com.instantor.ip.sandbox +package name_compare + +import net.liftweb._ +import http._ +import sitemap._ +import org.slf4j.LoggerFactory +import scala.sys.process._ + + +import hr.element.etb.lift.boot.Bouncer +object NameCompareBouncer extends Bouncer("sandbox/name-compare") + +class Boot extends Bootable { + def boot { + NameCompareBouncer.init() + + LiftRules.setSiteMap(SiteMap( + Menu.i("Name compare") / "index" + , Menu.i("Test") / "test" + )) + + LiftRules.addToPackages("com.instantor.ip.sandbox.name_compare") + LiftRules.dispatch.append(LiftListener) + + LiftRules.early.append(_.setCharacterEncoding("UTF-8")) + + // Use this block to send HTML5 + LiftRules.htmlProperties.default.set((r: Req) => + XHtmlInHtml5OutProperties(r.userAgent) + ) + } +} diff --git a/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/LiftListener.scala b/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/LiftListener.scala new file mode 100644 index 0000000..416a7b1 --- /dev/null +++ b/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/LiftListener.scala @@ -0,0 +1,101 @@ +package com.instantor.ip.sandbox +package name_compare + +import hr.element.etb.name_compare._ +import net.liftweb.http._ +import rest._ +import net.liftweb.common._ +import scala.xml._ +import net.liftweb.json._ +import net.liftweb.json.JsonDSL._ +import net.liftweb.json.Printer._ +import hr.element.etb.Pimps._ +import net.liftweb.http.SessionVar +import scalax.io._ + +object LastTest extends SessionVar[Params]( + Params( + true + , true + , 0.95f + , 1f + , 0.6f + , Resource.fromClasspath("names.txt").slurpString("UTF-8") + ) +) + +case class Params( + transliteration: Boolean + , lowercasing: Boolean + , directThreshold: Float + , initialsThreshold: Float + , hyphenThreshold: Float + , names: String) + +object LiftListener extends RestHelper { + + serve { + case "api" :: Nil JsonPost json => + implicit def formats = Serialization.formats(NoTypeHints) + + val response = + try { + val params = json._1.asInstanceOf[JObject].extract[Params] + LastTest.set(params) + + val response = process(params) + response + } + catch { + case x: Throwable => + x.printStackTrace() + + ("Success" -> false) ~ ("Reason" -> x.toString) + } + + JsonResponse(response) + } + + private val LinePattern = "[\r\n]+"r + private val NamePattern = "(.*)[,;\t]+(.*)"r + + def process(params: Params) = { + val comparer = NameCompare + .setTransliteration(params.transliteration) + .setLowercasing(params.lowercasing) + .setDirectThreshold(params.directThreshold) + .setInitialsThreshold(params.initialsThreshold) + .setHyphenThreshold(params.hyphenThreshold) + + val lines = LinePattern split params.names + + lines.map { l => + val (cD, (fS, fD)) = + try { + val NamePattern(src, dst) = l + comparer(src.ksp, dst.ksp) + } + catch { + case _: Throwable => + val eS = FuzzyString(l, "Could not separate names") + MatchError -> (eS, eS) + } + + implicit def formats = Serialization.formats(NoTypeHints) + + ("comparisonDecision" -> + ("decision" -> cD.decision) ~ + ("percentage" -> cD.percentage) ~ + ("description" -> cD.description) + ) ~ + ("src" -> + ("original" -> fS.original) ~ + ("processed" -> fS.processed) + ) ~ + ("dst" -> + ("original" -> fD.original) ~ + ("processed" -> fD.processed) + ) + }.toList: JArray + } +} diff --git a/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/snippet/Scripts.scala b/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/snippet/Scripts.scala new file mode 100644 index 0000000..672a903 --- /dev/null +++ b/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/snippet/Scripts.scala @@ -0,0 +1,11 @@ +package com.instantor.ip.sandbox +package name_compare +package snippet + +object GeneratedJS extends hr.element.etb.lift.snippet.GeneratedJS { + override val root = "sandbox/name-compare/static" +} + +object GeneratedCSS extends hr.element.etb.lift.snippet.GeneratedCSS { + override val root = "sandbox/name-compare/static" +} diff --git a/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/snippet/Shared.scala b/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/snippet/Shared.scala new file mode 100644 index 0000000..a6824b7 --- /dev/null +++ b/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/snippet/Shared.scala @@ -0,0 +1,42 @@ +package com.instantor.ip.sandbox +package name_compare +package snippet + +import hr.element.etb.lift.snippet._ + +object SharedJS extends StaticJS { + override val root = "sandbox/name-compare/shared" + + override val defaultVersions = Map( + "jquery" -> "1.7.2" + , "jquery.bxSlider" -> "3.0" + , "jquery.scrollTo" -> "1.4.2" + , "jquery.mousewheel" -> "3.0.6" + , "jquery.fancybox" -> "2.0.6" + , "jquery.fancybox-buttons" -> "2.0.5" + , "jquery.easing" -> "1.3" + , "jquery.validate" -> "1.9.0" + , "jquery.validate-additional-methods" -> "1.9.0" + , "jquery.fieldselection" -> "0.1.1" + + , "knockout" -> "2.1.0" + , "knockout.mapping" -> "2.2.4" + , "json2" -> "11.10.19" + + , "less" -> "1.3.0" + , "coffeescript" -> "1.2.1" + + , "bootstrap" -> "2.0.4" + + , "modernizr.custom" -> "2.5.3" + ) +} + +object SharedCSS extends StaticCSS { + override val root = "sandbox/name-compare/shared" + + override val defaultVersions = Map( + "jquery.fancybox" -> "2.0.6" + , "jquery.fancybox-buttons" -> "2.0.5" + ) +} diff --git a/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/snippet/ShowLastTest.scala b/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/snippet/ShowLastTest.scala new file mode 100644 index 0000000..1fc1da2 --- /dev/null +++ b/code/scala/Lift/src/main/scala/com/instantor/ip/sandbox/name_compare/snippet/ShowLastTest.scala @@ -0,0 +1,22 @@ +package com.instantor.ip.sandbox +package name_compare +package snippet + +import net.liftweb._ +import http._ +import util._ +import common._ +import Helpers._ +import BindPlus._ +import scala.xml._ + +object ShowLastTest { + def render(n: NodeSeq) = n.bind("v", + FuncAttrOptionBindParam("transliteration", (t: NodeSeq) => if (LastTest.transliteration) Some(t) else None, "checked") + , FuncAttrOptionBindParam("lowercasing", (t: NodeSeq) => if (LastTest.lowercasing) Some(t) else None, "checked") + , AttrBindParam("directThreshold", "%.0f" format(LastTest.directThreshold * 100), "value") + , AttrBindParam("initialsThreshold", "%.0f" format(LastTest.initialsThreshold * 100), "value") + , AttrBindParam("hyphenThreshold", "%.0f" format(LastTest.hyphenThreshold * 100), "value") + , "names" -> LastTest.names + ) +} diff --git a/code/scala/Lift/src/main/static/images/close-message.png b/code/scala/Lift/src/main/static/images/close-message.png new file mode 100644 index 0000000..d3026f5 Binary files /dev/null and b/code/scala/Lift/src/main/static/images/close-message.png differ diff --git a/code/scala/Lift/src/main/static/images/cross.png b/code/scala/Lift/src/main/static/images/cross.png new file mode 100644 index 0000000..2d41437 Binary files /dev/null and b/code/scala/Lift/src/main/static/images/cross.png differ diff --git a/code/scala/Lift/src/main/static/images/delete.png b/code/scala/Lift/src/main/static/images/delete.png new file mode 100644 index 0000000..5df538d Binary files /dev/null and b/code/scala/Lift/src/main/static/images/delete.png differ diff --git a/code/scala/Lift/src/main/static/images/error.png b/code/scala/Lift/src/main/static/images/error.png new file mode 100644 index 0000000..426b151 Binary files /dev/null and b/code/scala/Lift/src/main/static/images/error.png differ diff --git a/code/scala/Lift/src/main/static/images/exclamation.png b/code/scala/Lift/src/main/static/images/exclamation.png new file mode 100644 index 0000000..831e996 Binary files /dev/null and b/code/scala/Lift/src/main/static/images/exclamation.png differ diff --git a/code/scala/Lift/src/main/static/images/glyphicons-halflings-gray.png b/code/scala/Lift/src/main/static/images/glyphicons-halflings-gray.png new file mode 100644 index 0000000..5d1308c Binary files /dev/null and b/code/scala/Lift/src/main/static/images/glyphicons-halflings-gray.png differ diff --git a/code/scala/Lift/src/main/static/images/glyphicons-halflings-white.png b/code/scala/Lift/src/main/static/images/glyphicons-halflings-white.png new file mode 100644 index 0000000..a20760b Binary files /dev/null and b/code/scala/Lift/src/main/static/images/glyphicons-halflings-white.png differ diff --git a/code/scala/Lift/src/main/static/images/glyphicons-halflings.png b/code/scala/Lift/src/main/static/images/glyphicons-halflings.png new file mode 100644 index 0000000..92d4445 Binary files /dev/null and b/code/scala/Lift/src/main/static/images/glyphicons-halflings.png differ diff --git a/code/scala/Lift/src/main/static/images/icons/glyphicons-halflings-white.png b/code/scala/Lift/src/main/static/images/icons/glyphicons-halflings-white.png new file mode 100644 index 0000000..a20760b Binary files /dev/null and b/code/scala/Lift/src/main/static/images/icons/glyphicons-halflings-white.png differ diff --git a/code/scala/Lift/src/main/static/images/icons/glyphicons-halflings.png b/code/scala/Lift/src/main/static/images/icons/glyphicons-halflings.png new file mode 100644 index 0000000..92d4445 Binary files /dev/null and b/code/scala/Lift/src/main/static/images/icons/glyphicons-halflings.png differ diff --git a/code/scala/Lift/src/main/static/images/information.png b/code/scala/Lift/src/main/static/images/information.png new file mode 100644 index 0000000..b694c23 Binary files /dev/null and b/code/scala/Lift/src/main/static/images/information.png differ diff --git a/code/scala/Lift/src/main/static/images/logo-instantor.png b/code/scala/Lift/src/main/static/images/logo-instantor.png new file mode 100644 index 0000000..ba5b7d9 Binary files /dev/null and b/code/scala/Lift/src/main/static/images/logo-instantor.png differ diff --git a/code/scala/Lift/src/main/static/images/logo-instantor_silver.png b/code/scala/Lift/src/main/static/images/logo-instantor_silver.png new file mode 100644 index 0000000..7fee24d Binary files /dev/null and b/code/scala/Lift/src/main/static/images/logo-instantor_silver.png differ diff --git a/code/scala/Lift/src/main/static/images/logo-instantplatform_54.png b/code/scala/Lift/src/main/static/images/logo-instantplatform_54.png new file mode 100644 index 0000000..7dc336d Binary files /dev/null and b/code/scala/Lift/src/main/static/images/logo-instantplatform_54.png differ diff --git a/code/scala/Lift/src/main/static/images/textures/bgnoise_lg.png b/code/scala/Lift/src/main/static/images/textures/bgnoise_lg.png new file mode 100644 index 0000000..caacc6f Binary files /dev/null and b/code/scala/Lift/src/main/static/images/textures/bgnoise_lg.png differ diff --git a/code/scala/Lift/src/main/static/images/textures/diagonal-noise.png b/code/scala/Lift/src/main/static/images/textures/diagonal-noise.png new file mode 100644 index 0000000..f65b22a Binary files /dev/null and b/code/scala/Lift/src/main/static/images/textures/diagonal-noise.png differ diff --git a/code/scala/Lift/src/main/static/images/textures/groovepaper.png b/code/scala/Lift/src/main/static/images/textures/groovepaper.png new file mode 100644 index 0000000..61f81a7 Binary files /dev/null and b/code/scala/Lift/src/main/static/images/textures/groovepaper.png differ diff --git a/code/scala/Lift/src/main/static/images/textures/littleknobs.png b/code/scala/Lift/src/main/static/images/textures/littleknobs.png new file mode 100644 index 0000000..53e9373 Binary files /dev/null and b/code/scala/Lift/src/main/static/images/textures/littleknobs.png differ diff --git a/code/scala/Lift/src/main/static/images/textures/white_carbon.png b/code/scala/Lift/src/main/static/images/textures/white_carbon.png new file mode 100644 index 0000000..ebe037e Binary files /dev/null and b/code/scala/Lift/src/main/static/images/textures/white_carbon.png differ diff --git a/code/scala/Lift/src/main/static/images/tick.png b/code/scala/Lift/src/main/static/images/tick.png new file mode 100644 index 0000000..3a34002 Binary files /dev/null and b/code/scala/Lift/src/main/static/images/tick.png differ diff --git a/code/scala/Lift/src/main/webapp/WEB-INF/web.xml b/code/scala/Lift/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..b949f2f --- /dev/null +++ b/code/scala/Lift/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,18 @@ + + + + + LiftFilter + Lift Filter + The Filter that intercepts lift calls + net.liftweb.http.LiftFilter + + bootloader + com.instantor.ip.sandbox.name_compare.Boot + + + + LiftFilter + /* + + diff --git a/code/scala/Lift/src/main/webapp/index.html b/code/scala/Lift/src/main/webapp/index.html new file mode 100644 index 0000000..580d42a --- /dev/null +++ b/code/scala/Lift/src/main/webapp/index.html @@ -0,0 +1,98 @@ +
+ +

Comparison form

+ + +
+
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ % +
+
+ +
+ +
+ % +
+
+ +
+ +
+ % +
+
+ +
+ +
+ +
+
+
+ +
+
+
+
+
+
+ +
+

Response

+
+
+ No response. +
+ + + + + + + + + + + + + + + +
#Source nameDestination nameResponseMatch %Decision
+ + +
+
+
+
diff --git a/code/scala/Lift/src/main/webapp/templates-hidden/default.html b/code/scala/Lift/src/main/webapp/templates-hidden/default.html new file mode 100644 index 0000000..26b22b1 --- /dev/null +++ b/code/scala/Lift/src/main/webapp/templates-hidden/default.html @@ -0,0 +1,41 @@ + + + + + + + + <span class="lift:Menu.title"/> + + + + + +
+ + +
+

Name compare

+ +
+ + + + + +
+ + diff --git a/code/static/favicon.ico b/code/static/favicon.ico new file mode 100644 index 0000000..b61160c Binary files /dev/null and b/code/static/favicon.ico differ diff --git a/code/static/robots.txt b/code/static/robots.txt new file mode 100644 index 0000000..eb05362 --- /dev/null +++ b/code/static/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: diff --git a/config/nginx/platform.instantor-local.com.ActionBunny b/config/nginx/platform.instantor-local.com.ActionBunny new file mode 100644 index 0000000..56d59ea --- /dev/null +++ b/config/nginx/platform.instantor-local.com.ActionBunny @@ -0,0 +1,82 @@ +server { + listen 127.0.0.1:443; + server_name platform.instantor-local.com; + + ssl on; + ssl_certificate d:\\Code\\instant-platform\\certs\\server\\platform.instantor.com.crt.chained; + ssl_certificate_key d:\\Code\\instant-platform\\certs\\server\\platform.instantor.com.key; + + ssl_client_certificate d:\\Code\\instant-platform\\certs\\client\\ip-local-tech.crt; + ssl_verify_client optional; + + keepalive_timeout 70; + ssl_session_timeout 5m; + + ssl_protocols SSLv3 TLSv1; + ssl_ciphers ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM; + ssl_prefer_server_ciphers on; + + access_log d:\\Code\\instant-platform\\logs\\nginx\\access.log; + error_log d:\\Code\\instant-platform\\logs\\nginx\\error.log; + + # -------------------------------------------------------------------------------------------------- + + # PLATFORM - SANDBOX - NAME COMPARE - GENERATED STATIC + location ~ ^/sandbox/name-compare/static/(?:less-(css)|coffee-(js))/.+?(?:-[0-9]+)?\.(?:\1|\2)$ { + rewrite ^/sandbox/name-compare(/static/(?:less-css|coffee-js)/.+?)(?:-[0-9]+)?(\.(?:css|js))$ $1$2 break; + root d:\\Code\\name-compare\\code\\scala\\Lift\\src\\main; + expires 30d; + access_log d:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log d:\\Code\\name-compare\\logs\\nginx\\error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - DIRECT STATIC + location ~ ^/sandbox/name-compare/static/.*$ { + rewrite ^/sandbox/name-compare(/static/.*)$ $1 break; + root d:\\Code\\name-compare\\code\\scala\\Lift\\src\\main; + expires 30d; + access_log d:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log d:\\Code\\name-compare\\logs\\nginx\\error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - SHARED + location ~ ^/sandbox/name-compare/shared/.*$ { + rewrite ^/sandbox/name-compare(/shared/.*)$ $1 break; + root d:\\Code\\name-compare; + expires 30d; + access_log d:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log d:\\Code\\name-compare\\logs\\nginx\\error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - CYBORGS + location ~ ^/sandbox/name-compare/(?:favicon\.ico|robots\.txt)$ { + rewrite ^/sandbox/name-compare(/(?:favicon\.ico|robots\.txt))$ $1 break; + root d:\\Code\\name-compare\\code\\static; + expires 30d; + access_log d:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log d:\\Code\\name-compare\\logs\\nginx\\error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - LIFT INTERNALS + location ~ ^/sandbox-name-compare-.*$ { + proxy_pass http://localhost:9633; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Client-Verify $ssl_client_verify; + proxy_set_header X-Client-DN $ssl_client_s_dn; + access_log d:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log d:\\Code\\name-compare\\logs\\nginx\\error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - LIFT + location ~ ^/sandbox/name-compare/.*$ { + rewrite ^/sandbox/name-compare(/.*)$ $1 break; + proxy_pass http://localhost:9633; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Client-Verify $ssl_client_verify; + proxy_set_header X-Client-DN $ssl_client_s_dn; + access_log d:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log d:\\Code\\name-compare\\logs\\nginx\\error.log; + } +} diff --git a/config/nginx/platform.instantor-local.com.Eustahije b/config/nginx/platform.instantor-local.com.Eustahije new file mode 100644 index 0000000..503ec68 --- /dev/null +++ b/config/nginx/platform.instantor-local.com.Eustahije @@ -0,0 +1,82 @@ +server { + listen 192.168.2.200:443; + server_name platform.instantor-local.com; + + ssl on; + ssl_certificate r:\\Code\\instant-platform\\certs\\server\\platform.instantor.com.crt.chained; + ssl_certificate_key r:\\Code\\instant-platform\\certs\\server\\platform.instantor.com.key; + + ssl_client_certificate r:\\Code\\instant-platform\\certs\\client\\ip-local-tech.crt; + ssl_verify_client optional; + + keepalive_timeout 70; + ssl_session_timeout 5m; + + ssl_protocols SSLv3 TLSv1; + ssl_ciphers ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM; + ssl_prefer_server_ciphers on; + + access_log r:\\Code\\instant-platform\\logs\\nginx\\access.log; + error_log r:\\Code\\instant-platform\\logs\\nginx\\error.log; + + # -------------------------------------------------------------------------------------------------- + + # PLATFORM - SANDBOX - NAME COMPARE - GENERATED STATIC + location ~ ^/sandbox/name-compare/static/(?:less-(css)|coffee-(js))/.+?(?:-[0-9]+)?\.(?:\1|\2)$ { + rewrite ^/sandbox/name-compare(/static/(?:less-css|coffee-js)/.+?)(?:-[0-9]+)?(\.(?:css|js))$ $1$2 break; + root r:\\Code\\name-compare\\code\\scala\\Lift\\src\\main; + expires 30d; + access_log r:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log r:\\Code\\name-compare\\logs\\nginx\\error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - DIRECT STATIC + location ~ ^/sandbox/name-compare/static/.*$ { + rewrite ^/sandbox/name-compare(/static/.*)$ $1 break; + root r:\\Code\\name-compare\\code\\scala\\Lift\\src\\main; + expires 30d; + access_log r:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log r:\\Code\\name-compare\\logs\\nginx\\error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - SHARED + location ~ ^/sandbox/name-compare/shared/.*$ { + rewrite ^/sandbox/name-compare(/shared/.*)$ $1 break; + root r:\\Code\\name-compare; + expires 30d; + access_log r:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log r:\\Code\\name-compare\\logs\\nginx\\error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - CYBORGS + location ~ ^/sandbox/name-compare/(?:favicon\.ico|robots\.txt)$ { + rewrite ^/sandbox/name-compare(/(?:favicon\.ico|robots\.txt))$ $1 break; + root r:\\Code\\name-compare\\code\\static; + expires 30d; + access_log r:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log r:\\Code\\name-compare\\logs\\nginx\\error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - LIFT INTERNALS + location ~ ^/sandbox-name-compare-.*$ { + proxy_pass http://localhost:9633; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Client-Verify $ssl_client_verify; + proxy_set_header X-Client-DN $ssl_client_s_dn; + access_log r:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log r:\\Code\\name-compare\\logs\\nginx\\error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - LIFT + location ~ ^/sandbox/name-compare/.*$ { + rewrite ^/sandbox/name-compare(/.*)$ $1 break; + proxy_pass http://localhost:9633; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Client-Verify $ssl_client_verify; + proxy_set_header X-Client-DN $ssl_client_s_dn; + access_log r:\\Code\\name-compare\\logs\\nginx\\access.log; + error_log r:\\Code\\name-compare\\logs\\nginx\\error.log; + } +} diff --git a/config/nginx/platform.instantor-local.com.elk b/config/nginx/platform.instantor-local.com.elk new file mode 100644 index 0000000..f2587fb --- /dev/null +++ b/config/nginx/platform.instantor-local.com.elk @@ -0,0 +1,83 @@ +server { + #listen 192.168.2.200:443; + listen 443 + server_name platform.instantor-local.com; + + ssl on; + ssl_certificate /home/neven/code/instant-platform/certs/server/platform.instantor.com.crt.chained; + ssl_certificate_key /home/neven/code/instant-platform/certs/server/platform.instantor.com.key; + + ssl_client_certificate /home/neven/code/instant-platform/certs/client/ip-local-tech.crt; + ssl_verify_client optional; + + keepalive_timeout 70; + ssl_session_timeout 5m; + + ssl_protocols SSLv3 TLSv1; + ssl_ciphers ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM; + ssl_prefer_server_ciphers on; + + access_log /home/neven/code/instant-platform/logs/nginx/access.log; + error_log /home/neven/code/instant-platform/logs/nginx/error.log; + + # -------------------------------------------------------------------------------------------------- + + # PLATFORM - SANDBOX - NAME COMPARE - GENERATED STATIC + location ~ ^/sandbox/name-compare/static/(?:less-(css)|coffee-(js))/.+?(?:-[0-9]+)?\.(?:\1|\2)$ { + rewrite ^/sandbox/name-compare(/static/(?:less-css|coffee-js)/.+?)(?:-[0-9]+)?(\.(?:css|js))$ $1$2 break; + root /home/neven/code/name-compare/code/scala/Lift/src/main; + expires 30d; + access_log /home/neven/code/name-compare/logs/nginx/access.log; + error_log /home/neven/code/name-compare/logs/nginx/error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - DIRECT STATIC + location ~ ^/sandbox/name-compare/static/.*$ { + rewrite ^/sandbox/name-compare(/static/.*)$ $1 break; + root /home/neven/code/name-compare/code/scala/Lift/src/main; + expires 30d; + access_log /home/neven/code/name-compare/logs/nginx/access.log; + error_log /home/neven/code/name-compare/logs/nginx/error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - SHARED + location ~ ^/sandbox/name-compare/shared/.*$ { + rewrite ^/sandbox/name-compare(/shared/.*)$ $1 break; + root /home/neven/code/name-compare; + expires 30d; + access_log /home/neven/code/name-compare/logs/nginx/access.log; + error_log /home/neven/code/name-compare/logs/nginx/error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - CYBORGS + location ~ ^/sandbox/name-compare/(?:favicon\.ico|robots\.txt)$ { + rewrite ^/sandbox/name-compare(/(?:favicon\.ico|robots\.txt))$ $1 break; + root /home/neven/code/name-compare/code/static; + expires 30d; + access_log /home/neven/code/name-compare/logs/nginx/access.log; + error_log /home/neven/code/name-compare/logs/nginx/error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - LIFT INTERNALS + location ~ ^/sandbox-name-compare-.*$ { + proxy_pass http://localhost:9633; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Client-Verify $ssl_client_verify; + proxy_set_header X-Client-DN $ssl_client_s_dn; + access_log /home/neven/code/name-compare/logs/nginx/access.log; + error_log /home/neven/code/name-compare/logs/nginx/error.log; + } + + # PLATFORM - SANDBOX - NAME COMPARE - LIFT + location ~ ^/sandbox/name-compare/.*$ { + rewrite ^/sandbox/name-compare(/.*)$ $1 break; + proxy_pass http://localhost:9633; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Client-Verify $ssl_client_verify; + proxy_set_header X-Client-DN $ssl_client_s_dn; + access_log /home/neven/code/name-compare/logs/nginx/access.log; + error_log /home/neven/code/name-compare/logs/nginx/error.log; + } +} diff --git a/logs/lift/.keep b/logs/lift/.keep new file mode 100644 index 0000000..efeb28f --- /dev/null +++ b/logs/lift/.keep @@ -0,0 +1 @@ +.keep diff --git a/logs/nginx/.keep b/logs/nginx/.keep new file mode 100644 index 0000000..efeb28f --- /dev/null +++ b/logs/nginx/.keep @@ -0,0 +1 @@ +.keep diff --git a/shared b/shared new file mode 160000 index 0000000..505f6a3 --- /dev/null +++ b/shared @@ -0,0 +1 @@ +Subproject commit 505f6a334b2ca400ac6d83b0b00323387182a901 diff --git a/src/main/scala/hr/element/etb/name_compare/FuzzyMatch.scala b/src/main/scala/hr/element/etb/name_compare/FuzzyMatch.scala deleted file mode 100644 index b9c44d4..0000000 --- a/src/main/scala/hr/element/etb/name_compare/FuzzyMatch.scala +++ /dev/null @@ -1,27 +0,0 @@ -package hr.element.etb.name_compare - - -import uk.ac.shef.wit.simmetrics.similaritymetrics.Levenshtein - -/* - * The following method of comparing names uses Levenshtein algorithm. - * The Levenshtein algorithm (also called Edit-Distance) calculates the - * least number of edit operations that are necessary to modify one string to obtain another string. - * - * Method FuzzyMatch.apply returns 0 to 1 correlation between 2 names. - * - * Names, that are used for fuzzy matching previously are: - * - * 1. Transliterated - * 2. Alphabetically sorted - * 3. Converted to lowercase and trimmed for extra whitespaces - * - */ -object FuzzyMatch { - - def apply(name1: String, name2: String): Float = { - (new Levenshtein).getSimilarity( - FuzzyString(name1), - FuzzyString(name2)) - } -} \ No newline at end of file diff --git a/src/main/scala/hr/element/etb/name_compare/FuzzyString.scala b/src/main/scala/hr/element/etb/name_compare/FuzzyString.scala deleted file mode 100644 index 083f6c0..0000000 --- a/src/main/scala/hr/element/etb/name_compare/FuzzyString.scala +++ /dev/null @@ -1,31 +0,0 @@ -package hr.element.etb -package name_compare - - -import com.ibm.icu.text.Transliterator - -object FuzzyString { - private val ASCII = Transliterator.getInstance("Latin-ASCII") - - def apply(s: String) = { - val sanitizedName = (transliterate andThen lowerCase andThen trimWhiteSpace)(s) - println("sanitized: " + sanitizedName) - val sortedName = sanitizedName split " " sortWith sortAsc - sortedName mkString " " - } - - - private val splitPattern = """\s{2,}""" - - private def sortAsc(e1: String, e2: String) = (e1 compareToIgnoreCase e2) > 0 //ASC - - protected val trimWhiteSpace = (splitPattern r) replaceAllIn (_: String, " ") - - protected val lowerCase = (_: String).toLowerCase - - protected val transliterate = ASCII.transliterate(_: String) - - def transText(text: String, splitPattern: String) = - (lowerCase andThen transliterate andThen trimWhiteSpace) (text) - -}