-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestBuiltinSplitter.py
More file actions
48 lines (35 loc) · 1.42 KB
/
Copy pathTestBuiltinSplitter.py
File metadata and controls
48 lines (35 loc) · 1.42 KB
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
from BoundaryReader import parseSentenceBoundaries
from eHostessAddins.SentenceReconstructor import SentenceReconstructor
from eHostessAddins.SentenceRepeatManager import SentenceRepeatManager
from pyConTextNLP.helpers import sentenceSplitter
testDoc = '327000.txt'
inFile = open("./ClinicalNotes/Training1/" + testDoc, 'rU')
body = inFile.read()
inFile.close()
testBoundaries, testText = parseSentenceBoundaries(body)
reconstructor = SentenceReconstructor(testText)
repeatManager = SentenceRepeatManager()
sentences = sentenceSplitter().splitSentences(testText)
predictedBoundaries = []
for sentence in sentences:
reconstructedSentence = reconstructor.reconstructSentence(sentence)
docSpan = repeatManager.processSentence(reconstructedSentence, testText)
predictedBoundaries.append(docSpan[1])
numTrueBoundaries = len(testBoundaries)
numPredictedBoundaries = len(predictedBoundaries)
numPredictedCorrect = 0
for boundary in predictedBoundaries:
if boundary in testBoundaries:
numPredictedCorrect += 1
recall = None
if numTrueBoundaries == 0:
recall = 0.
else:
recall = float(numPredictedCorrect) / float(numTrueBoundaries)
precision = None
if numPredictedBoundaries == 0:
precision = 0
else:
precision = float(numPredictedCorrect) / float(numPredictedBoundaries)
fScore = 2. * recall * precision / (recall + precision)
print "Recall: %f\nPrecision: %f\nF-Score:%f" % (recall, precision, fScore)