Skip to content

Commit

Permalink
Merge pull request #104 from uts-cic/develop
Browse files Browse the repository at this point in the history
merge develop
  • Loading branch information
andrewresearch authored Nov 6, 2017
2 parents 89760be + 80d5804 commit 5190c2c
Show file tree
Hide file tree
Showing 14 changed files with 330 additions and 194 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ src/main/scala/tap/nlp/old/NlpDocument.scala
src/main/scala/tap/nlp/old/OldNlpSentence.scala
src/main/scala/tap/nlp/old/SentenceConverter.scala
/src/main/scala/worksheet.sc
/src/main/scala/experiments.sc
12 changes: 7 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

name := "tap"

version := "3.0.7"
version := "3.0.8"

scalaVersion := "2.12.3"

Expand Down Expand Up @@ -51,16 +51,18 @@ val apiDependencies = Seq(
)

val analyticsDependencies = Seq(
"io.nlytx" %% "factorie-nlp-api" % nlytxFactorieVersion,
"cc.factorie.app.nlp" % "all-models" % factorieVersion,
"io.nlytx" %% "nlytx-nlp-api" % "1.0.2",
"io.nlytx" %% "factorie-nlp-models" % "1.0.3",
"com.typesafe.akka" % "akka-stream_2.12" % akkaStreamVersion,
"org.apache.opennlp" % "opennlp-tools" % openNlpVersion,
"org.languagetool" % "language-en" % langToolVersion
)
resolvers += Resolver.bintrayRepo("nlytx", "nlytx-nlp")

val generalDependencies = Seq(
"io.nlytx" %% "commons" % nlytxCommonsVersion
)
resolvers += Resolver.bintrayRepo("nlytx", "nlytx_commons")

val testDependencies = Seq(
"org.scalactic" %% "scalactic" % scalatestVersion,
Expand All @@ -74,8 +76,8 @@ libraryDependencies ++= apiDependencies ++ analyticsDependencies ++ generalDepen

scalacOptions in (Compile, doc) ++= Seq("-doc-root-content", baseDirectory.value+"/src/main/scala/root-doc.md")

resolvers += Resolver.bintrayRepo("nlytx", "nlytx_commons")
resolvers += Resolver.bintrayRepo("nlytx-io", "factorie-nlp-api")



//Documentation - run ;paradox;copyDocs
enablePlugins(ParadoxPlugin) //Generate documentation with Paradox
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
#

#sbt.version = 0.13.16
sbt.version = 1.0.2
sbt.version = 1.0.3
164 changes: 103 additions & 61 deletions src/main/public/js/app-graphiql.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,59 @@
"# Text Analytics Pipeline\n" +
"\n"

var exampleQueries = "query CleanText($input: String!) {\n" +
" clean(text:$input) {\n" +
var exampleQueries = "# TAP Example Queries\n" +
"# -------------------\n" +
"# These queries are just examples of what TAP can do, the\n" +
"# actual capability of the server at any point in time can\n" +
"# be found in the Schema - see the Documentation Explorer\n" +
"# on the right hand side. \n" +
"# See the TAP Documentation https://uts-cic.github.io/tap/\n" +
"\n" +
"# All queries require submission of text and return\n" +
"# analytics,timestamp, message, querytime\n" +
"\n" +
"# Some queries like \"moves\" require external resources and may\n" +
"# fail if those resources are not available.\n" +
"\n" +
"query RhetoricalMoves($input: String!) {\n" +
" moves(text:$input,grammar:\"analytic\") {\n" +
" analytics\n" +
" message\n" +
" timestamp\n" +
" querytime\n" +
" }\n" +
" cleanPreserve(text:$input) {\n" +
" analytics\n" +
" }\n" +
" cleanMinimal(text:$input) {\n" +
" analytics\n" +
" }\n" +
" cleanAscii(text:$input) {\n" +
"}\n" +
"# However, you only need to ask for what you want e.g.\n" +
"query MinimalMoves($input:String!) {\n" +
" moves(text:$input) {\n" +
" analytics\n" +
" }\n" +
"}\n" +
"\n" +
"query MakeVisible($input: String!) {\n" +
" visible(text:$input) {\n" +
" analytics\n" +
" timestamp\n" +
"# Tokenise with pipetype (default is 'fast'):\n" +
"# fast - lemmas and postags\n" +
"# standard - lemmas, postags, parse data\n" +
"# ner - lemmas, postags, parse data, nertags\n" +
"\n" +
"query Tokenise($input: String!) {\n" +
" annotations(text:$input) {\n" +
" analytics {\n" +
" idx\n" +
" start\n" +
" end\n" +
" length\n" +
" tokens {\n" +
" idx\n" +
" term\n" +
" lemma\n" +
" postag\n" +
" }\n" +
" }\n" +
" }\n" +
"}\n" +
"\n" +
"query Annotations($input: String!) {\n" +
" annotations(text:$input) {\n" +
"query TokeniseWithNer($input: String!) {\n" +
" annotations(text:$input,pipetype:\"ner\") {\n" +
" analytics {\n" +
" idx\n" +
" start\n" +
Expand All @@ -70,14 +98,34 @@
" lemma\n" +
" postag\n" +
" parent\n" +
" child\n" +
" children\n" +
" deptype\n" +
" nertag\n" +
" }\n" +
" }\n" +
" timestamp\n" +
" }\n" +
"}\n" +
"\n" +
"# Other examples\n" +
"query Expressions($input2:String!) {\n" +
" expressions(text:$input2) {\n" +
" analytics {\n" +
" sentIdx\n" +
" affect{\n" +
" text\n" +
" }\n" +
" epistemic {\n" +
" text\n" +
" startIdx\n" +
" endIdx\n" +
" }\n" +
" modal {\n" +
" text\n" +
" }\n" +
" }\n" +
" }\n" +
"}\n" +
"query Vocab($input: String!) {\n" +
" vocabulary(text:$input){\n" +
" analytics {\n" +
Expand All @@ -90,9 +138,8 @@
" timestamp\n" +
" }\n" +
"}\n" +
"\n" +
"query Metrics($input2: String!) {\n" +
" metrics(text:$input2) {\n" +
"query Metrics($input: String!) {\n" +
" metrics(text:$input) {\n" +
" analytics {\n" +
" sentences\n" +
" tokens\n" +
Expand All @@ -109,47 +156,16 @@
" timestamp\n" +
" }\n" +
"}\n" +
"\n" +
"query Athanor($input: String!) {\n" +
" moves(text:$input) {\n" +
" analytics\n" +
" }\n" +
"}\n" +
"\n" +
"query Expressions($input:String!) {\n" +
" expressions(text:$input) {\n" +
"query PosStats($input:String!){\n" +
" posStats(text:$input) {\n" +
" analytics {\n" +
" sentIdx\n" +
" affect{\n" +
" text\n" +
" }\n" +
" epistemic {\n" +
" text\n" +
" startIdx\n" +
" endIdx\n" +
" }\n" +
" modal {\n" +
" text\n" +
" }\n" +
" }\n" +
" }\n" +
"}\n" +
"\n" +
"query Expressions2($input2:String!) {\n" +
" expressions(text:$input2) {\n" +
" analytics {\n" +
" sentIdx\n" +
" affect{\n" +
" text\n" +
" }\n" +
" epistemic {\n" +
" text\n" +
" startIdx\n" +
" endIdx\n" +
" }\n" +
" modal {\n" +
" text\n" +
" }\n" +
" verbNounRatio\n" +
" futurePastRatio\n" +
" adjectiveWordRatio\n" +
" namedEntityWordRatio\n" +
" nounDistribution\n" +
" verbDistribution\n" +
" adjectiveDistribution\n" +
" }\n" +
" }\n" +
"}\n" +
Expand Down Expand Up @@ -178,11 +194,37 @@
" }\n" +
" }\n" +
" }\n" +
"}\n" +
"\n" +
"\n" +
"##############################\n" +
"# UTILITY QUERIES\n" +
"\n" +
"query MakeVisible($input: String!) {\n" +
" visible(text:$input) {\n" +
" analytics\n" +
" timestamp\n" +
" }\n" +
"}\n" +
"query AllCleaning($input: String!) {\n" +
" clean(text:$input) {\n" +
" analytics\n" +
" timestamp\n" +
" }\n" +
" cleanPreserve(text:$input) {\n" +
" analytics\n" +
" }\n" +
" cleanMinimal(text:$input) {\n" +
" analytics\n" +
" }\n" +
" cleanAscii(text:$input) {\n" +
" analytics\n" +
" }\n" +
"}" +
"\n"

var exampleVariables = "{\"input\": \"I didn't take any time to review the subject outline nor did I log onto UTS Online to review any supporting information to provide context, I walked into class like a blank canvas. I had no idea what this course was about but I was certain it had something to do with responsibility and leaders. I reflected on this and felt decision making was like second nature, yes I over-thought my decisions whether it was personal or professional but I never thought of the act of having to justify my decisions.\"," +
"\"input2\": \"Although I wasn't certain, I did believe that I was doing the right thing. Next time I will be sure.\"}"
var exampleVariables = "{\"input\": \"It didn't take any time for Dr. Smith to review the subject outline by logging onto UTS Online. However, I walked into class like a blank canvas. I had no idea what this course was about but I was certain it had something to do with responsibility and leaders. I reflected on this and felt decision making was like second nature, yes I over-thought my decisions whether it was personal or professional but I never thought of the act of having to justify my decisions.\"," +
"\"input2\": \"Althogh I wasn't certain, I did believe that I was doing the right thing. Next time I will be sure.\"}"



Expand Down
61 changes: 32 additions & 29 deletions src/main/scala/handlers/ExternalAnalysisHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

package handlers

import java.io.File
import javax.inject.Inject

import tap.pipelines.materialize.PipelineContext.{executor, materializer}
import com.typesafe.config.ConfigFactory
import models.Results.{StringListResult, StringResult}
import play.api.{Configuration, Environment, Logger, Mode}
import play.api.libs.ws.ahc.{AhcWSClient, AhcWSClientConfig, AhcWSClientConfigFactory}
import models.Results.StringListResult
import play.api.Logger
import play.api.libs.ws.{WSClient, WSRequest, WSResponse}
import tap.pipelines.materialize.PipelineContext.executor


import scala.concurrent.Future
import scala.concurrent.duration.DurationInt
Expand All @@ -37,42 +35,47 @@ class ExternalAnalysisHandler @Inject() (wsClient: WSClient) {

def analyseWithAthanor(text:String,grammar:Option[String]):Future[StringListResult] = {
//logger.info(s"Analysing with athanor: $text")
val parameter = "?grammar="+grammar.getOrElse("analytic")
val url = "http://athanor.utscic.edu.au/v2/analyse/text/rhetorical"+parameter
val parameter = "?grammar=" + grammar.getOrElse("analytic")
val url = "http://athanor.utscic.edu.au/v2/analyse/text/rhetorical" + parameter
logger.info(s"Creating request to: $url")
val request: WSRequest = wsClient.url(url)

val athanorRequest: WSRequest = request
.withHttpHeaders("Accept" -> "application/json")
.withRequestTimeout(10000.millis)
.withHttpHeaders("Accept" -> "application/json")
.withRequestTimeout(30000.millis)

val futureResponse: Future[WSResponse] = athanorRequest.post(text)
//try {
case class AthanorMsg(message: String, results: Vector[Vector[String]])

case class AthanorMsg(message:String, results:List[List[String]])

import play.api.libs.functional.syntax._ //scalastyle:ignore
import play.api.libs.json._ //scalastyle:ignore
import play.api.libs.functional.syntax._
import play.api.libs.json._ //scalastyle:ignore

implicit val AMWrites: Writes[AthanorMsg] = (
(JsPath \ "message").write[String] and
(JsPath \ "results").write[List[List[String]]]
)(unlift(AthanorMsg.unapply))
(JsPath \ "results").write[Vector[Vector[String]]]
) (unlift(AthanorMsg.unapply))

implicit val AMReads:Reads[AthanorMsg] = (
implicit val AMReads: Reads[AthanorMsg] = (
(JsPath \ "message").read[String] and
(JsPath \ "results").read[List[List[String]]]
)(AthanorMsg.apply _)

val result:Future[List[List[String]]] = futureResponse.map { response =>
response.json.as[AthanorMsg].results
(JsPath \ "results").read[Vector[Vector[String]]]
) (AthanorMsg.apply _)
logger.warn("About to try and get result...")
val result: Future[StringListResult] = {
futureResponse.map { response =>
val res = response.json.as[AthanorMsg].results
StringListResult(res,"ok")
}
val errMsg = "There was a problem connecting to the Athanor server."
futureResponse.recover {
case e: Any => {
val msg = s"$errMsg: $e"
logger.error(msg)
StringListResult(Vector(),msg)
}
}.asInstanceOf[Future[StringListResult]]
}

result.map(s => StringListResult(s))
result
}

// def analyseWithXip(text:String):Future[StringResult] = Future {
//
// StringResult("")
// }

}
Loading

0 comments on commit 5190c2c

Please sign in to comment.