-
Notifications
You must be signed in to change notification settings - Fork 1
/
FetchAllMeaning.scala
88 lines (76 loc) · 2.67 KB
/
FetchAllMeaning.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package example
//import scala.collection.mutable._
import scala.io.Source
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.io._
import com.readr.model.annotation._
import com.readr.model.Offsets
import com.readr.model.annotation.Annotations
import com.readr.client.util.AnnotationSequenceFileReader
import com.readr.client.Client
import com.readr.model.Project
import com.readr.client.meaning.frames
import com.readr.model.frame.Frame
import com.typesafe.config.ConfigFactory
import com.readr.client.meaning.frames
import com.readr.client.meaning.frameValences
import com.readr.model.annotation.AnnotationConfirmationType
import com.readr.model.annotation.AnnotatedSentence
import com.readr.model.annotation.FrameMatchFeature
import java.util.regex.Pattern
import java.util.regex.Matcher
import java.io.File
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.OutputStreamWriter
import java.io.FileOutputStream
import java.io.InputStreamReader
import java.io.FileInputStream
import com.readr.client.document.layerDefaults
import com.readr.client.document.frameMatchFeatures
import com.readr.model.FrameMatchFeatureLayerRef
import org.json4s.ShortTypeHints
import org.json4s.jackson.Serialization
import org.json4s.jackson.Serialization.write
import org.json4s.jackson.Serialization.read
import org.json4s.ShortTypeHints
import org.json4s.NoTypeHints
import org.json4s._
import org.json4s.JsonDSL._
import org.json4s.jackson.JsonMethods._
object FetchAllMeaning extends Settings {
implicit val formats = Serialization.formats(NoTypeHints)
def main(args:Array[String]) = {
implicit val p = Project(ns, proj)
Client.open(host, user, password)
val layerID = layerDefaults("FrameMatchFeature", "Manual")
implicit val lay = FrameMatchFeatureLayerRef(layerID)
val outDir = "/tmp/test"
// get frames
val l:Seq[(Int,Frame)] = frames.listDetails
// create document for each frame; get annotations
for (t <- l) { t match {
case (frameID,x) =>
val w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outDir + "/" + x.name + ".json")))
val json = write[Frame](x)
w.write(frameID + "\n")
w.write(json.toString + "\n")
var offset = 0
var hasMore = true
while (hasMore) {
val ls = frameMatchFeatures.findByFrameID(frameID, offset, 1000)
for (r <- ls) {
val jsonm = write[FrameMatchFeature](r)
w.write(jsonm + "\n")
}
if (ls.size < 1000)
hasMore = false
else
offset += 1000
}
w.close()
}
}
Client.close
}
}