-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPutPatternAnnotations.scala
104 lines (91 loc) · 3.1 KB
/
PutPatternAnnotations.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package example
import example.FetchPatternAnnotations2._
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.InputStreamReader
import java.io.FileInputStream
import com.readr.client.document.layerDefaults
import com.readr.client.document.frameMatchFeatures
import com.readr.model.FrameMatchFeatureLayerRef
object PutPatternAnnotations extends Settings {
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 frameID = frames.idByName("frame3")
if (frameID == -1)
println("Frame not found")
val dir = tmpDir + "/test"
val f = new File(dir + "/annotations")
val reader = new BufferedReader(new InputStreamReader(new FileInputStream(f), "utf-8"))
val docPattern = Pattern.compile("doc (.*), sentNum (.*), sentenceTokenOffset (.*), truth (.*)")
val argPattern = Pattern.compile("arg (.*): (.*)")
var documentID = -1
var sentNum = -1
var sentenceTokenOffset = -1
var truth = false
var args = ArrayBuffer[FrameMatchFeatureArg]()
var l:String = null
while ({ l = reader.readLine(); l != null} ) {
if (l.startsWith("//")) {
// ignore sentence
if (documentID != -1) {
val fmf = FrameMatchFeature(
instanceID = -1,
frameID,
truth = truth,
priority = 0,
args = args
)
frameMatchFeatures.add(fmf)
args.clear
}
} else if (l.startsWith("doc ")) {
val m = docPattern.matcher(l)
m.find
//println(l)
documentID = m.group(1).toInt
sentNum = m.group(2).toInt
sentenceTokenOffset = m.group(3).toInt
truth = m.group(4).toBoolean
} else if (l.startsWith("arg ")) {
val m = argPattern.matcher(l)
m.find
val argNum = m.group(1).toByte
val pos = m.group(2).toInt
args += FrameMatchFeatureArg(argNum, documentID, sentenceTokenOffset + pos)
}
}
val fmf = FrameMatchFeature(
instanceID = -1,
frameID,
truth = truth,
priority = 0,
args = args
)
frameMatchFeatures.add(fmf)
reader.close
Client.close
}
}