-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsentence2standOff.rb
47 lines (39 loc) · 1.04 KB
/
sentence2standOff.rb
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
#!/usr/local/bin/ruby
$inputFile = File.expand_path($*.first) # non sentence-split txt
$inputFile2 = File.expand_path($*[1].to_s) # sentence-split txt
$outputFile = File.expand_path($*[2].to_s) # stand-off
def main
marker = "\n"[0]
tag = "sentence"
position = 0
sentenceCount = 1
target = ''
targetNew = ''
start = 0
finish = 0
inTxtStrict = open($inputFile)
inTxtNew = open($inputFile2)
outStandOff = open($outputFile, "w")
p marker
while(!inTxtNew.eof) do
targetNew = inTxtNew.getc
target = inTxtStrict.getc
position += 1
if targetNew == marker
sentenceCount += 1
finish = position - 1
outStandOff << start << "\t" << finish << "\t" << tag << "\n"
if targetNew == target
start = position
else
targetNew = inTxtNew.getc
while targetNew != target do
target = inTxtStrict.getc
position += 1
end
start = position - 1
end
end
end
end
main