@@ -11,7 +11,6 @@ import net.codingwell.scalaguice.ScalaModule
11
11
import org .apache .commons .lang3 .RandomUtils
12
12
import org .joda .time .DateTime
13
13
import play .api .Configuration
14
- import play .api .mvc .Result
15
14
import reactivemongo .api .collections .bson .BSONCollection
16
15
import reactivemongo .api .commands .UpdateWriteResult
17
16
import reactivemongo .api .{Cursor , DefaultDB , MongoConnection }
@@ -113,8 +112,8 @@ object BsonPicklers {
113
112
114
113
object AnnotationToolUser {
115
114
implicit val bsonRw : BSONDocumentHandler [AnnotationToolUser ] = Macros .handler[AnnotationToolUser ]
116
- import prickle ._
117
115
import BsonPicklers ._
116
+ import prickle ._
118
117
119
118
implicit val pickler : Pickler [AnnotationToolUser ] =
120
119
prickle.Pickler .materializePickler[AnnotationToolUser ]
@@ -304,6 +303,29 @@ object SentenceBSON {
304
303
305
304
class SentenceDbo @ Inject ()(db : AnnotationDb )(implicit ec : ExecutionContext ) extends StrictLogging {
306
305
306
+ private val coll = db.db.collection[BSONCollection ](" sentences" )
307
+
308
+ import SentenceBSON ._
309
+
310
+ def recalcStatuses () = {
311
+ coll.find(BSONDocument ()).cursor[Sentence ]().fold(NotUsed ) {
312
+ case (_, doc) =>
313
+ val newStatus = SentenceUtils .computeStatus(doc)
314
+ if (newStatus != doc.status) {
315
+ val search = BSONDocument (
316
+ " _id" -> doc.id
317
+ )
318
+ val upd = BSONDocument (
319
+ " $set" -> BSONDocument (
320
+ " status" -> newStatus.value
321
+ )
322
+ )
323
+ coll.update(search, upd)
324
+ }
325
+ NotUsed
326
+ }
327
+ }
328
+
307
329
def findAlreadyReported (surfaceComment : String ): Future [Option [String ]] = {
308
330
val q = BSONDocument (
309
331
" tags" -> " report" ,
@@ -312,16 +334,12 @@ class SentenceDbo @Inject()(db: AnnotationDb)(implicit ec: ExecutionContext) ext
312
334
313
335
val proj = BSONDocument (" _id" -> 1 )
314
336
315
- coll.find(q, proj).one.map {
337
+ coll.find(q, proj).one[ BSONDocument ] .map {
316
338
case Some (doc) => doc.getAs[String ](" _id" )
317
339
case _ => None
318
340
}
319
341
}
320
342
321
- private val coll = db.db.collection[BSONCollection ](" sentences" )
322
-
323
- import SentenceBSON ._
324
-
325
343
def checkExistance (ids : Seq [String ]): Future [Set [String ]] = {
326
344
if (ids.isEmpty) {
327
345
return Future .successful(Set .empty)
@@ -384,6 +402,10 @@ class SentenceDbo @Inject()(db: AnnotationDb)(implicit ec: ExecutionContext) ext
384
402
doc.merge(
385
403
" status" -> SentenceStatus .WorkRequired .value
386
404
)
405
+ case " rj" | " rej" =>
406
+ doc.merge(
407
+ " status" -> SentenceStatus .Rejected .value
408
+ )
387
409
case " bad" | " ng" =>
388
410
doc.merge(
389
411
" status" -> BSONDocument (
@@ -460,6 +482,13 @@ class SentenceDbo @Inject()(db: AnnotationDb)(implicit ec: ExecutionContext) ext
460
482
" $ne" -> user._id
461
483
)
462
484
)
485
+ if (req.query == " " ) {
486
+ q = q.merge(
487
+ " status" -> BSONDocument (
488
+ " $ne" -> SentenceStatus .Rejected .value
489
+ )
490
+ )
491
+ }
463
492
}
464
493
465
494
if (req.reviewedBefore.isDefined) {
@@ -659,6 +688,13 @@ class SentenceDbo @Inject()(db: AnnotationDb)(implicit ec: ExecutionContext) ext
659
688
}
660
689
661
690
object SentenceUtils {
691
+
692
+ val badAnnotations = Set (
693
+ " どうでもいい" ,
694
+ " 入力:意味不明" ,
695
+ " 入力:誤字脱字"
696
+ )
697
+
662
698
def cleanTags (blocks : Seq [SentenceBlock ], allowedFields : Set [String ]): Seq [SentenceBlock ] = {
663
699
blocks.map { b =>
664
700
b.copy(spans = b.spans.map { s =>
@@ -689,6 +725,7 @@ object SentenceUtils {
689
725
} else {
690
726
val values = anns.map(_.value).distinct
691
727
values match {
728
+ case vs if vs.exists(badAnnotations.contains) => SentenceStatus .Rejected
692
729
case Seq (XInt (_)) => SentenceStatus .TotalAgreement
693
730
case vs if vs.forall(v => XInt .unapply(v).isDefined) => SentenceStatus .PartialAgreement
694
731
case _ => SentenceStatus .WorkRequired
0 commit comments