Skip to content

Commit

Permalink
Merge pull request #21 from uts-cic/develop
Browse files Browse the repository at this point in the history
Update master from Develop
  • Loading branch information
andrewresearch authored Jul 28, 2017
2 parents 1901bb4 + f09c046 commit 4780907
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object Athanor {
def parsedSentenceToJsonString(parsedSent:ParsedSentence):String = {
implicit val formats = Serialization.formats(NoTypeHints)
val l = write(parsedSent._1)
val c = write(parsedSent._2)
val c = write(parsedSent._2).replaceAll("""(\"(?=[0-9]))|((?<=[0-9])\")""","") //remove quotes around Ints for json
val d = write(parsedSent._3)
s"[$l,$c,$d]"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ object ConstituentTreeParser {
def process(tree:Tree):Any = {
import scala.collection.JavaConverters._
if(tree.numChildren()==0) {
tree.yieldWords().asScala.map(_.value()).mkString(",")
//val words = tree.yieldWords().asScala.map(_.value()).mkString(",")
val num = tree.labels.asScala.flatMap(_.toString.split("-")).last
//println(s"WORD: $words NUM: $num")
num
}
else {
tree.label().toString +:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ object SentenceParser {
dependencies match {
case None => List()
case Some(deps) => {
Dependency("root",0,deps.getFirstRoot.index()) +:
deps.edgeListSorted().asScala.toList.map { d =>
Dependency(
d.getRelation.toString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object TextParser {

val pipeline:StanfordCoreNLP = {
val props = new Properties
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse") //parse ner dcoref
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse") //parse ner dcoref
new StanfordCoreNLP(props)
}

Expand Down
16 changes: 9 additions & 7 deletions src/test/scala/au/edu/utscic/athanorserver/TestData.scala

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ class AthanorSpec extends UnitSpec {
// }

it should "parseJsonSentence" in {
val ps = Athanor.parseJsonSentence(TestData.jsonString)
assert(ps==TestData.parsedSentence)
val ps = Athanor.parseJsonSentence(TestData.athJsonString)
assert(ps==TestData.athParsedSentence)
}

it should "parsedSentenceToJsonString" in {
import org.json4s._
import org.json4s.jackson.JsonMethods._
//Get strings
val expected = TestData.jsonString
val actual = Athanor.parsedSentenceToJsonString(TestData.parsedSentence)
val expected = TestData.athJsonString
val actual = Athanor.parsedSentenceToJsonString(TestData.athParsedSentence)
//Check that the strings can actually be parsed into json
val expJson = parse(expected)
val actJson = parse(actual)
Expand All @@ -51,16 +51,17 @@ class AthanorSpec extends UnitSpec {
}

it should "analyseParsedSentence" in {
val result = Athanor.analyseParsedSentence(TestData.parsedSentence)
val result = Athanor.analyseParsedSentence(TestData.athParsedSentence)
assert(result.toSet==rhetoricalMoves.toSet) //Order doesn't matter
}

it should "analyseJsonSentence" in {
val result = Athanor.analyseJson(TestData.jsonString)
val result = Athanor.analyseJson(TestData.athJsonString)
assert(result.toSet==rhetoricalMoves.toSet) //Order doesn't matter
}





}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package au.edu.utscic.athanorserver.corenlp

import au.edu.utscic.athanorserver.UnitSpec
import au.edu.utscic.athanorserver.athanor.Athanor
import edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations._
import edu.stanford.nlp.trees.TreeCoreAnnotations.TreeAnnotation

Expand Down Expand Up @@ -44,22 +45,28 @@ class CoreNlpSpec extends UnitSpec {
val ps1s = ps1._2(1).asInstanceOf[List[Any]]
assert(ps1s.head=="S") //Tree has starting sentence
assert(ps1s.length==4) //S + 3 top level phrases
assert(ps1._3.size==10) //Correct number of dependencies
assert(ps1._3.size==11) //Correct number of dependencies
assert(ps1._3.head.name=="root") //Dependencies has root
//Sentence 2
assert(ps2._1.size==9) //Correct number of nodes
assert(ps2._1.map(_._1).toSeq==Seq(0,1,2,3,4,5,6,7,8)) //Is sorted
assert(ps2._2.head=="ROOT") //Tree has root
val ps2s = ps2._2(1).asInstanceOf[List[Any]]
assert(ps2s.head=="S") //Tree has starting sentence
assert(ps2s.length==4) //S + 3 top level phrases
assert(ps2._3.size==7) //Correct number of dependencies
assert(ps2._3.size==8) //Correct number of dependencies
assert(ps1._3.head.name=="root") //Dependencies has root
}

it should "parse" in {
val ps = TextParser.parse(textA)
assert(ps.length==2)
assert(ps(0)==textAparsed1)
assert(ps(1)==textAparsed2)
//Athanor sentence test
val demoPS = TextParser.parse(athSentence)
val json = Athanor.parsedSentenceToJsonString(demoPS.head)
assert(json==athJsonString)
}

behavior of "SentenceParser"
Expand Down

0 comments on commit 4780907

Please sign in to comment.