Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jiemakel committed Jan 24, 2014
0 parents commit 54c1140
Show file tree
Hide file tree
Showing 19 changed files with 1,106 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
logs
project/project
project/target
target
/.target
/.ensime
/.cache
tmp
.history
dist
/.idea
/*.iml
/out
/.idea_modules
/.classpath
/.project
/RUNNING_PID
/.settings
/project/*-shim.sbt
activator.bat
activator
activator-launch-*.jar
activator-*-shim.sbt
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
seco-lexicalanalysis-play
=========================

SeCo lexical analysis services published as a web service using the Scala Play framework.

10 changes: 10 additions & 0 deletions app/Application.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import controllers.LexicalAnalysisController

import com.softwaremill.macwire.MacwireMacros._
import services.lexicalanalysis.LexicalAnalysisModule

object Application extends LexicalAnalysisModule {

val lexicalAnalysisController = wire[LexicalAnalysisController]

}
11 changes: 11 additions & 0 deletions app/Global.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import com.softwaremill.macwire.{InstanceLookup, Macwire}
import java.util.Locale
import play.api.GlobalSettings
import play.api.mvc.QueryStringBindable.Parsing

object Global extends GlobalSettings with Macwire {
val instanceLookup = InstanceLookup(valsByClass(Application))

override def getControllerInstance[A](controllerClass: Class[A]) = instanceLookup.lookupSingleOrThrow(controllerClass)

}
92 changes: 92 additions & 0 deletions app/assets/javascripts/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'use strict'

angular.module('index',['play.routing'])
.controller('IdentifyCtrl', ($scope, playRoutes) ->
$scope.text = "The quick brown fox jumps over the lazy dog"
$scope.$watch('text', _.throttle((text) ->
playRoutes.controllers.LexicalAnalysisController.identifyGET(text).get().success((data) ->
$scope.errorStatus = ''
$scope.guessedLang=data
).error((data,status) ->
if (status==0)
$scope.errorStatus = 503
$scope.error = "Service unavailable"
else
$scope.errorStatus = status
$scope.error = data
)
,1000))
)
.controller('LemmatizeCtrl', ($scope, playRoutes) ->
$scope.text = "Albert osti fagotin ja töräytti puhkuvan melodian."
$scope.$watchCollection('[text,locale]', _.throttle(() ->
locale = $scope.locale
if locale=='' then locale=null
playRoutes.controllers.LexicalAnalysisController.baseformGET($scope.text,locale).get().success((data) ->
$scope.errorStatus = ''
$scope.baseform=data
).error((data,status) ->
if (status==0)
$scope.errorStatus = 503
$scope.error = "Service unavailable"
else
$scope.errorStatus = status
$scope.error = data
)
,1000))
)
.controller('AnalyzeCtrl', ($scope, playRoutes) ->
$scope.text = "Albert osti"
$scope.locale = "fi"
$scope.$watchCollection('[text,locale]', _.throttle(() ->
locale = $scope.locale
if locale=='' then locale=null
playRoutes.controllers.LexicalAnalysisController.analyzeGET($scope.text,locale).get().success((data) ->
$scope.analysis=data
).error((data,status) ->
if (status==0)
$scope.errorStatus = 503
$scope.error = "Service unavailable"
else
$scope.errorStatus = status
$scope.error = data
)
,1000))
)
.controller('InflectionCtrl', ($scope, playRoutes) ->
$scope.text = "Albert osti fagotin ja töräytti puhkuvan melodian."
$scope.locale = "fi"
$scope.baseform=true;
$scope.forms = "V N Nom Sg, N Nom Pl, A Pos Nom Pl"
$scope.$watchCollection('[text,locale,baseform,forms]', _.throttle(() ->
locale = $scope.locale
if locale=='' then locale=null
playRoutes.controllers.LexicalAnalysisController.inflectGET($scope.text, $scope.forms.split(/, */),$scope.baseform,locale).get().success((data) ->
$scope.inflection=data
).error((data,status) ->
if (status==0)
$scope.errorStatus = 503
$scope.error = "Service unavailable"
else
$scope.errorStatus = status
$scope.error = data
)
,1000))
)
.controller('HyphenationCtrl', ($scope, playRoutes) ->
$scope.text = "Albert osti fagotin ja töräytti puhkuvan melodian."
$scope.$watchCollection('[text,locale]', _.throttle(() ->
locale = $scope.locale
if locale=='' then locale=null
playRoutes.controllers.LexicalAnalysisController.hyphenateGET($scope.text,locale).get().success((data) ->
$scope.hyphenation=data
).error((data,status) ->
if (status==0)
$scope.errorStatus = 503
$scope.error = "Service unavailable"
else
$scope.errorStatus = status
$scope.error = data
)
,1000))
)
58 changes: 58 additions & 0 deletions app/assets/javascripts/playroutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use strict";

// The service - will be used by controllers or other services, filters, etc.
angular.module("play.routing", []).factory("playRoutes", function($http) {

/*
* Wrap a Play JS function with a new function that adds the appropriate $http method.
* Note that the url has been already applied to the $http method so you only have to pass in
* the data (if any).
* Note: This is not only easier on the eyes, but must be called in a separate function with its own
* set of arguments, because otherwise JavaScript's function scope will bite us.
* @param playFunction The function from Play's jsRouter to be wrapped
*/
var wrapHttp = function(playFunction) {
return function(/*arguments*/) {
var routeObject = playFunction.apply(this, arguments);
var httpMethod = routeObject.method.toLowerCase();
var url = routeObject.url;
var res = {
method : httpMethod, url : url, absoluteUrl : routeObject.absoluteURL, webSocketUrl : routeObject.webSocketURL
};
res[httpMethod] = function(obj) {
return $http[httpMethod](url, obj);
};
return res;
};
};

// Add package object, in most cases "controllers"
var addPackageObject = function(packageName, service) {
if (!(packageName in playRoutes)) {
playRoutes[packageName] = {};
}
};

// Add controller object, e.g. Application
var addControllerObject = function(packageName, controllerKey, service) {
if (!(controllerKey in playRoutes[packageName])) {
playRoutes[packageName][controllerKey] = {};
}
};

var playRoutes = {};
// Loop over all items in the jsRoutes generated by Play, wrap and add them to
// playRoutes
for ( var packageKey in jsRoutes) {
var packageObject = jsRoutes[packageKey];
addPackageObject(packageKey, playRoutes);
for ( var controllerKey in packageObject) {
var controller = packageObject[controllerKey];
addControllerObject(packageKey, controllerKey, playRoutes);
for ( var controllerMethodKey in controller) {
playRoutes[packageKey][controllerKey][controllerMethodKey] = wrapHttp(controller[controllerMethodKey]);
}
}
}
return playRoutes;
});
14 changes: 14 additions & 0 deletions app/assets/stylesheets/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body {
padding-top: 70px;
padding-bottom: 70px;
}

.anchor {
position:relative;
top: -40px;
visibility: hidden;
}

.affix,.navbar-fixed-top {
-webkit-transform: scale3d(1,1,1);
}
15 changes: 15 additions & 0 deletions app/binders/Binders.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package binders

import play.api.mvc.QueryStringBindable.Parsing
import play.api.i18n.Lang
import play.api.mvc.QueryStringBindable
import java.util.Locale

/**
* Created by jiemakel on 24.10.2013.
*/
object Binders {
implicit object bindableLocale extends Parsing[Locale](
new Locale(_), _.toString, (key: String, e: Exception) => "Cannot parse parameter %s as Locale: %s".format(key, e.getMessage)
)
}
Loading

0 comments on commit 54c1140

Please sign in to comment.